Skip to content

Commit 8d900a2

Browse files
committed
test: run tests in separated process
To identify corruptions between tests
1 parent 86feeeb commit 8d900a2

File tree

3 files changed

+52
-121
lines changed

3 files changed

+52
-121
lines changed

.travis.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

appveyor.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/index.js

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ process.config.target_defaults.default_configuration =
55
.readdirSync(require('path').join(__dirname, 'build'))
66
.filter((item) => (item === 'Debug' || item === 'Release'))[0];
77

8+
const RUN_TEST_CMD = 'run-test';
9+
810
// FIXME: We might need a way to load test modules automatically without
911
// explicit declaration as follows.
1012
let testModules = [
@@ -75,7 +77,6 @@ if (process.env.NAPI_VERSION) {
7577
// specified
7678
napiVersion = process.env.NAPI_VERSION;
7779
}
78-
console.log('napiVersion:' + napiVersion);
7980

8081
const majorNodeVersion = process.versions.node.split('.')[0]
8182

@@ -110,40 +111,65 @@ if (majorNodeVersion < 12) {
110111
testModules.splice(testModules.indexOf('objectwrap_worker_thread'), 1);
111112
}
112113

113-
if (typeof global.gc === 'function') {
114-
(async function() {
115-
console.log(`Testing with N-API Version '${napiVersion}'.`);
116-
117-
console.log('Starting test suite\n');
118-
119-
// Requiring each module runs tests in the module.
120-
for (const name of testModules) {
121-
console.log(`Running test '${name}'`);
114+
main(process.argv.slice(2)).catch(err => {
115+
console.error(err);
116+
process.exit(1);
117+
});
118+
async function main(argv) {
119+
const cmd = argv[0];
120+
if (cmd === RUN_TEST_CMD) {
121+
const name = argv[1];
122+
if (name == null || name === '') {
123+
console.log('command run-test has to be run against a test case name.');
124+
return process.exit(1);
125+
}
126+
// Requiring each module runs tests in the module.
122127
await require('./' + name);
123-
};
128+
return;
129+
}
124130

125-
console.log('\nAll tests passed!');
126-
})().catch((error) => {
127-
console.log(error);
128-
process.exit(1);
129-
});
130-
} else {
131+
runTestSuiteInBatch(argv);
132+
}
133+
134+
function runTestSuiteInBatch(argv) {
135+
const failFast = argv.includes('--fail-fast');
136+
console.log(`Testing with N-API Version '${napiVersion}'.`);
137+
console.log('Starting test suite\n');
131138
// Construct the correct (version-dependent) command-line args.
132139
let args = ['--expose-gc', '--no-concurrent-array-buffer-freeing'];
133140
if (majorNodeVersion >= 14) {
134141
args.push('--no-concurrent-array-buffer-sweeping');
135142
}
136-
args.push(__filename);
143+
args.push(__filename, RUN_TEST_CMD);
137144

138-
const child = require('./napi_child').spawnSync(process.argv[0], args, {
139-
stdio: 'inherit',
140-
});
145+
let failedModules = [];
146+
for (const name of testModules) {
147+
console.log(`Running test '${name}'`);
148+
const child = require('./napi_child').spawnSync(process.execPath, [...args, name], {
149+
stdio: 'inherit',
150+
});
141151

142-
if (child.signal) {
143-
console.error(`Tests aborted with ${child.signal}`);
144-
process.exitCode = 1;
152+
let failed = false;
153+
if (child.signal) {
154+
console.error(`Test '${name}' aborted with ${child.signal}`);
155+
failed = true;
156+
} else if (child.status !== 0) {
157+
console.error(`Test '${name}' exited with code ${child.status}`);
158+
failed = true;
159+
}
160+
161+
if (failed) {
162+
failedModules.push(name);
163+
}
164+
if (failed && failFast) {
165+
process.exit(1);
166+
}
167+
}
168+
169+
if (failedModules.length === 0) {
170+
console.log('\nAll tests passed!');
145171
} else {
146-
process.exitCode = child.status;
172+
console.log('\nTests failed with: \n %s', failedModules.join('\n '));
173+
process.exit(1);
147174
}
148-
process.exit(process.exitCode);
149175
}

0 commit comments

Comments
 (0)