/
run-perf-tests.ts
47 lines (41 loc) · 1.42 KB
/
run-perf-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
import * as fs from 'fs';
import * as path from 'path';
import * as execa from 'execa';
import { Observable } from 'rxjs';
import { tap, throttleTime } from 'rxjs/operators';
const testRootDir = path.resolve(__dirname, '..', 'test');
runPerfTests()
.then(() => console.log('Done'))
.catch(err => {
console.error(err);
process.exit(1);
});
async function runPerfTests() {
const testDirs = fs.readdirSync(testRootDir);
console.time('all tests');
for (const testDir of testDirs) {
await runTest(testDir);
}
console.timeEnd('all tests');
}
async function runTest(testDir: string) {
console.time(testDir);
await execNpm(['run', 'stryker'], testDir).pipe(
throttleTime(60000),
tap(logMessage => console.timeLog(testDir, 'last log message: ', logMessage))
).toPromise();
console.timeEnd(testDir);
}
function execNpm(args: string[], testDir: string): Observable<string> {
const currentTestDir = path.resolve(testRootDir, testDir);
console.log(`Exec ${testDir} npm ${args.join(' ')}`);
return new Observable(observer => {
const testProcess = execa('npm', args, { timeout: 0, cwd: currentTestDir, stdio: 'pipe' });
let stderr = '';
testProcess.stderr.on('data', chunk => stderr += chunk.toString());
testProcess.stdout.on('data', chunk => observer.next(chunk.toString().trim()));
testProcess
.then(() => observer.complete())
.catch(error => observer.error(error));
});
}