mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 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:
@@ -1,7 +1,27 @@
|
|||||||
import { basename, join } from 'path';
|
import { basename, join } from 'path';
|
||||||
import { testDeployment } from '../../test/lib/deployment/test-deployment.js';
|
import { lstatSync, readdirSync } from 'fs';
|
||||||
|
|
||||||
export async function deployExample(filename: string) {
|
export async function deployExample(filename: string) {
|
||||||
|
const { testDeployment } = require('../../test/lib/deployment/test-deployment.js');
|
||||||
const example = basename(filename).replace(/\.test\.ts$/, '');
|
const example = basename(filename).replace(/\.test\.ts$/, '');
|
||||||
await testDeployment(join(filename, '..', '..', '..', example));
|
await testDeployment(join(filename, '..', '..', '..', example));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getExamples() {
|
||||||
|
const dirname = join(__dirname, '..');
|
||||||
|
const examples = readdirSync(dirname)
|
||||||
|
.map(example =>
|
||||||
|
({
|
||||||
|
exampleName: example,
|
||||||
|
examplePath: join(dirname, example),
|
||||||
|
testPath: join(dirname, '__tests__', 'integration', `${example}.test.ts`),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.filter(o =>
|
||||||
|
!o.exampleName.startsWith('.') &&
|
||||||
|
!o.exampleName.startsWith('_') &&
|
||||||
|
o.exampleName !== 'node_modules' &&
|
||||||
|
lstatSync(o.examplePath).isDirectory()
|
||||||
|
);
|
||||||
|
return examples;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
import { existsSync, lstatSync, readdirSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { join } from 'path';
|
import { getExamples } from '../test-utils';
|
||||||
|
|
||||||
function getExamples() {
|
|
||||||
const dirname = join(__dirname, '..', '..');
|
|
||||||
const examples = readdirSync(dirname)
|
|
||||||
.map(example =>
|
|
||||||
({
|
|
||||||
exampleName: example,
|
|
||||||
examplePath: join(dirname, example),
|
|
||||||
testPath: join(dirname, '__tests__', 'integration', `${example}.test.ts`),
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.filter(o =>
|
|
||||||
!o.exampleName.startsWith('.') &&
|
|
||||||
!o.exampleName.startsWith('_') &&
|
|
||||||
lstatSync(o.examplePath).isDirectory()
|
|
||||||
);
|
|
||||||
return examples;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('should have test for each example', () => {
|
describe('should have test for each example', () => {
|
||||||
it.each(getExamples())('should exist $exampleName', async ({testPath}) => {
|
it.each(getExamples())('should exist $exampleName', async ({testPath}) => {
|
||||||
|
|||||||
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 frameworkList from '@vercel/frameworks';
|
||||||
import { detectFramework } from '../src';
|
import { detectFramework } from '../src';
|
||||||
import { FixtureFilesystem } from './utils/fixture-filesystem';
|
import { FixtureFilesystem } from './utils/fixture-filesystem';
|
||||||
import { readdirSync, lstatSync } from 'fs';
|
import { getExamples } from '../../../examples/__tests__/test-utils';
|
||||||
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)];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('examples should be detected', () => {
|
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) => {
|
expect(framework).toBe(exampleName);
|
||||||
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(example);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user