-
Notifications
You must be signed in to change notification settings - Fork 7
/
list.ts
61 lines (57 loc) · 1.69 KB
/
list.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { Scenario } from './index.js';
import glob from 'glob';
import { resolve } from 'path';
import { format } from 'util';
import { createRequire } from 'node:module';
const { sync: globSync } = glob;
export interface ListParams {
files: string[];
require: string[] | undefined;
matrix: string | undefined;
}
export async function list(params: ListParams): Promise<Scenario[]> {
if (params.require) {
for (let r of params.require) {
// @ts-ignore this doesn't actually fail since we're checking before using it
if(import.meta.url) {
// @ts-ignore
const require = createRequire(import.meta.url);
// @ts-ignore this will only happen if we have import.meta.url
await import(require.resolve(r, { paths: [process.cwd()]}));
} else {
require(require.resolve(r, { paths: [process.cwd()]}));
}
}
}
for (let pattern of params.files) {
for (let file of globSync(pattern)) {
// @ts-ignore
if(import.meta.url) {
// @ts-ignore
await import(resolve(file));
} else {
require(resolve(file));
}
}
}
return global.scenarioTesterSeenScenarios;
}
export async function printList(params: ListParams) {
let scenarios = await list(params);
if (params.matrix) {
process.stdout.write(
JSON.stringify({
include: scenarios.map(scenario => ({
name: scenario.name,
command: format(params.matrix, scenario.name),
})),
name: scenarios.map(scenario => scenario.name),
})
);
} else {
for (let scenario of scenarios) {
process.stdout.write(scenario.name + '\n');
}
}
}