forked from googleapis/cloud-trace-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.ts
57 lines (54 loc) · 1.52 KB
/
run-tests.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
import * as path from 'path';
import { globP, forkP, BUILD_DIRECTORY } from './utils';
export interface Options {
includeGlobs: string[],
excludeGlobs?: string[],
rootDir: string,
coverage?: boolean,
timeout?: number
}
export async function runTests(options: Options) {
const { includeGlobs, excludeGlobs, rootDir, coverage, timeout } = options;
function nodule(nodule: string) {
return path.relative(rootDir, `node_modules/${nodule}`);
}
let testNum = 0;
const excludedFiles = ([] as string[])
.concat(...await Promise.all((excludeGlobs || []).map(glob => globP(glob))));
const includedFiles = ([] as string[])
.concat(...await Promise.all(includeGlobs.map(glob => globP(glob))));
// Take the difference
const files = includedFiles.filter(i => excludedFiles.indexOf(i) < 0);
for (const file of files) {
const moduleAndArgs = [
...coverage ? [
nodule('.bin/nyc'),
'--reporter',
'lcov',
'--report-dir',
`./.coverage/${testNum++}`,
'--exclude',
'build/test/fixtures/**',
'--exclude',
'build/test/plugins/fixtures/**',
'--exclude-after-remap',
'false',
] : [],
nodule('mocha/bin/_mocha'),
'--require',
'source-map-support/register',
path.relative(rootDir, file),
...timeout ? [
'--timeout',
`${timeout}`
] : [
'--no-timeouts'
]
];
await forkP(
moduleAndArgs[0],
moduleAndArgs.slice(1),
{ cwd: rootDir }
);
}
}