mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
* Revert "[frameworks] Fix import in test (#3570)" This reverts commit9ee86df69d. * Revert "[frameworks] Rename frameworks to now-frameworks (#3569)" This reverts commitdaa5cbdd4b.
142 lines
3.4 KiB
TypeScript
Vendored
142 lines
3.4 KiB
TypeScript
Vendored
import path from 'path';
|
|
import { readFileSync } from 'fs-extra';
|
|
import { Framework } from '@now/frameworks';
|
|
import { detectFramework, DetectorFilesystem } from '../src';
|
|
|
|
const frameworkList = JSON.parse(
|
|
readFileSync(
|
|
path.join(__dirname, '..', '..', 'frameworks', 'frameworks.json')
|
|
).toString()
|
|
) as Framework[];
|
|
|
|
class VirtualFilesystem extends DetectorFilesystem {
|
|
private files: Map<string, Buffer>;
|
|
|
|
constructor(files: { [key: string]: string | Buffer }) {
|
|
super();
|
|
this.files = new Map();
|
|
Object.entries(files).map(([key, value]) => {
|
|
const buffer = typeof value === 'string' ? Buffer.from(value) : value;
|
|
this.files.set(key, buffer);
|
|
});
|
|
}
|
|
|
|
async _exists(name: string): Promise<boolean> {
|
|
return this.files.has(name);
|
|
}
|
|
|
|
async _readFile(name: string): Promise<Buffer> {
|
|
const file = this.files.get(name);
|
|
|
|
if (file === undefined) {
|
|
throw new Error('File does not exist');
|
|
}
|
|
|
|
if (typeof file === 'string') {
|
|
return Buffer.from(file);
|
|
}
|
|
|
|
return file;
|
|
}
|
|
}
|
|
|
|
describe('#detectFramework', () => {
|
|
it('Do not detect anything', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'README.md': '# hi',
|
|
'api/cheese.js': 'export default (req, res) => res.end("cheese");',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe(null);
|
|
});
|
|
|
|
it('Detect Next.js', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'package.json': JSON.stringify({
|
|
dependencies: {
|
|
next: '9.0.0',
|
|
},
|
|
}),
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('nextjs');
|
|
});
|
|
|
|
it('Detect Nuxt.js', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'package.json': JSON.stringify({
|
|
dependencies: {
|
|
nuxt: '1.0.0',
|
|
},
|
|
}),
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('nuxtjs');
|
|
});
|
|
|
|
it('Detect Gatsby', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'package.json': JSON.stringify({
|
|
dependencies: {
|
|
gatsby: '1.0.0',
|
|
},
|
|
}),
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('gatsby');
|
|
});
|
|
|
|
it('Detect Hugo #1', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'config.yaml': 'config',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
|
});
|
|
|
|
it('Detect Hugo #2', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'config.json': 'config',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
|
});
|
|
|
|
it('Detect Hugo #3', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'config.toml': 'config',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
|
});
|
|
|
|
it('Detect Jekyll', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'_config.yml': 'config',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('jekyll');
|
|
});
|
|
|
|
it('Detect Middleman', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'config.rb': 'config',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('middleman');
|
|
});
|
|
|
|
it('Detect Scully', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'package.json': JSON.stringify({
|
|
dependencies: {
|
|
'@angular/cli': 'latest',
|
|
'@scullyio/init': 'latest',
|
|
},
|
|
}),
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('scully');
|
|
});
|
|
});
|