Skip to content

Commit b0b65c7

Browse files
author
Luca Forstner
committed
test: Run node integration tests in isolation
1 parent 1c566b5 commit b0b65c7

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

packages/node-integration-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"fix:prettier": "prettier --write \"{suites,utils}/**/*.ts\"",
1818
"type-check": "tsc",
1919
"pretest": "run-s --silent prisma:init",
20-
"test": "jest --forceExit",
20+
"test": "ts-node ./utils/run-tests.ts",
2121
"test:watch": "yarn test --watch"
2222
},
2323
"dependencies": {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* eslint-disable no-console */
2+
import childProcess from 'child_process';
3+
import os from 'os';
4+
5+
const testPaths = childProcess.execSync('jest --listTests', { encoding: 'utf8' }).trim().split('\n');
6+
7+
let testsSucceeded = true;
8+
const testAmount = testPaths.length;
9+
const fails: string[] = [];
10+
11+
const threads = os.cpus().map(async (_, i) => {
12+
let testPath = testPaths.pop();
13+
while (testPath !== undefined) {
14+
console.log(`(Worker ${i}) Running test "${testPath}"`);
15+
await new Promise(resolve => {
16+
const p = childProcess.spawn('jest', ['--runTestsByPath', testPath as string, '--forceExit']);
17+
18+
let output = '';
19+
20+
p.stdout.on('data', (data: Buffer) => {
21+
output = output + data.toString();
22+
});
23+
24+
p.stderr.on('data', (data: Buffer) => {
25+
output = output + data.toString();
26+
});
27+
28+
p.on('error', error => {
29+
console.log(`(Worker ${i}) Error in test "${testPath}"`, error);
30+
console.log(output);
31+
resolve();
32+
});
33+
34+
p.on('exit', exitcode => {
35+
console.log(`(Worker ${i}) Finished test "${testPath}"`);
36+
console.log(output);
37+
if (exitcode !== 0) {
38+
fails.push(`FAILED: "${testPath}"`);
39+
testsSucceeded = false;
40+
}
41+
resolve();
42+
});
43+
});
44+
testPath = testPaths.pop();
45+
}
46+
});
47+
48+
void Promise.all(threads).then(() => {
49+
console.log('-------------------');
50+
console.log(`Successfully ran ${testAmount} tests.`);
51+
if (!testsSucceeded) {
52+
console.log('Not all tests succeeded:\n');
53+
fails.forEach(fail => {
54+
console.log(`● ${fail}`);
55+
});
56+
process.exit(1);
57+
} else {
58+
console.log('All testcases returned the expected results.');
59+
process.exit(0);
60+
}
61+
});

0 commit comments

Comments
 (0)