-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-runner.ts
35 lines (29 loc) · 1.17 KB
/
test-runner.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
import { run } from 'node:test';
import { spec } from 'node:test/reporters';
import { readdir } from 'node:fs/promises';
import { createWriteStream } from 'node:fs';
import { join } from 'node:path';
async function getFiles(): Promise<string[]> {
const base = __dirname;
const dir = join(base, 'test');
const files = await readdir(dir, { recursive: true });
return files.filter((file) => /\.(test|spec)\.[cm]?[jt]s$/u.test(file)).map((file) => join(dir, file));
}
void (async (): Promise<void> => {
const stream = run({
files: await getFiles(),
});
stream.on('test:fail', () => {
process.exitCode = 1;
});
stream.compose(spec).pipe(process.stdout);
if (process.env.CI === 'true' && process.env.GITHUB_ACTIONS === 'true') {
const { default: ghaReporter } = await import('node-reporter-gha');
stream.compose(ghaReporter).pipe(process.stdout);
}
if (process.env.SONARSCANNER === 'true') {
const { default: sonarReporter } = await import('node-reporter-sonarqube');
const testReportStream = createWriteStream('test-report.xml');
stream.compose(sonarReporter).pipe(testReportStream);
}
})();