[tests] Fix examples tests with shared util (#9415)

Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>
This commit is contained in:
Steven
2023-02-10 17:32:45 -05:00
committed by GitHub
parent fdcd86d37c
commit 2b483b0fd0
3 changed files with 34 additions and 48 deletions

View File

@@ -1,7 +1,27 @@
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) {
const { testDeployment } = require('../../test/lib/deployment/test-deployment.js');
const example = basename(filename).replace(/\.test\.ts$/, '');
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;
}