mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
[tests] Fix examples tests with shared util (#9415)
Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
This commit is contained in:
38
packages/fs-detectors/test/unit.examples.test.ts
vendored
38
packages/fs-detectors/test/unit.examples.test.ts
vendored
@@ -1,35 +1,19 @@
|
||||
import frameworkList from '@vercel/frameworks';
|
||||
import { detectFramework } from '../src';
|
||||
import { FixtureFilesystem } from './utils/fixture-filesystem';
|
||||
import { readdirSync, lstatSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
function getExamples() {
|
||||
const root = join(__dirname, '..', '..', '..');
|
||||
const examplesPath = join(root, 'examples');
|
||||
const examples = readdirSync(examplesPath);
|
||||
|
||||
const exampleDirs = examples.filter(example => {
|
||||
const examplePath = join(examplesPath, example);
|
||||
const stat = lstatSync(examplePath);
|
||||
return stat.isDirectory();
|
||||
});
|
||||
|
||||
return exampleDirs.map(exampleDirName => {
|
||||
return [exampleDirName, join(examplesPath, exampleDirName)];
|
||||
});
|
||||
}
|
||||
import { getExamples } from '../../../examples/__tests__/test-utils';
|
||||
|
||||
describe('examples should be detected', () => {
|
||||
const examples = getExamples();
|
||||
it.each(getExamples())(
|
||||
'should detect $exampleName',
|
||||
async ({ exampleName, examplePath }) => {
|
||||
const fs = new FixtureFilesystem(examplePath);
|
||||
const framework = await detectFramework({ fs, frameworkList });
|
||||
if (!framework) {
|
||||
throw new Error(`Framework not detected for example "${exampleName}".`);
|
||||
}
|
||||
|
||||
it.each(examples)('%s', async (example, examplePath) => {
|
||||
const fs = new FixtureFilesystem(examplePath);
|
||||
const framework = await detectFramework({ fs, frameworkList });
|
||||
if (!framework) {
|
||||
throw new Error(`Framework not detected for example "${example}".`);
|
||||
expect(framework).toBe(exampleName);
|
||||
}
|
||||
|
||||
expect(framework).toBe(example);
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user