mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 04:22:13 +00:00
* remove prefix from codeowners * remove references from ignore files * Remove prefix from package json and tests * Add run js without prefixes * Rename package folders * Delete auto generated test files * Remove now-node in integration test * Put back deleted vercel json files * Remove eol * Add styfle suggestion to comment in utils/run.js Co-authored-by: Steven <steven@ceriously.com>
155 lines
3.8 KiB
TypeScript
Vendored
155 lines
3.8 KiB
TypeScript
Vendored
import frameworkList from '@vercel/frameworks';
|
|
import { detectFramework, DetectorFilesystem } from '../src';
|
|
|
|
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 _hasPath(path: string): Promise<boolean> {
|
|
for (const file of this.files.keys()) {
|
|
if (file.startsWith(path)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
async _isFile(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': 'baseURL: http://example.org/',
|
|
'content/post.md': '# hello world',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
|
});
|
|
|
|
it('Detect Hugo #2', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'config.json': '{ "baseURL": "http://example.org/" }',
|
|
'content/post.md': '# hello world',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('hugo');
|
|
});
|
|
|
|
it('Detect Hugo #3', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'config.toml': 'baseURL = "http://example.org/"',
|
|
'content/post.md': '# hello world',
|
|
});
|
|
|
|
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');
|
|
});
|
|
|
|
it('Detect Zola', async () => {
|
|
const fs = new VirtualFilesystem({
|
|
'config.toml': 'base_url = "/"',
|
|
});
|
|
|
|
expect(await detectFramework({ fs, frameworkList })).toBe('zola');
|
|
});
|
|
});
|