-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.runner.mjs
42 lines (38 loc) · 1005 Bytes
/
test.runner.mjs
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
import { readdir } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { run } from 'node:test';
import { spec, tap } from 'node:test/reporters';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'node:util';
const {
values: { parallel, only },
positionals,
} = parseArgs({
options: {
parallel: {
type: 'boolean',
short: 'p',
default: false,
},
only: {
type: 'boolean',
short: 'o',
default: false,
},
},
allowPositionals: true,
});
const __dirname = dirname(fileURLToPath(import.meta.url));
const dir = join(__dirname, 'test');
const files =
positionals.length > 0
? positionals
: (await readdir(dir, { recursive: true }))
.filter((el) => el.endsWith('.test.ts'))
.map((el) => join(dir, el));
run({ files, concurrency: parallel, only })
.on('test:fail', () => {
process.exitCode = 1;
})
.compose(process.stdout.isTTY ? new spec() : tap)
.pipe(process.stdout);