Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor remove repeated execution index.js #839

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
'use strict';

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

if (typeof global.gc !== 'function') {
// Construct the correct (version-dependent) command-line args.
let args = ['--expose-gc', '--no-concurrent-array-buffer-freeing'];
if (majorNodeVersion >= 14) {
args.push('--no-concurrent-array-buffer-sweeping');
}
args.push(__filename);

const child = require('./napi_child').spawnSync(process.argv[0], args, {
stdio: 'inherit',
});

if (child.signal) {
console.error(`Tests aborted with ${child.signal}`);
process.exitCode = 1;
} else {
process.exitCode = child.status;
}
process.exit(process.exitCode);
}

process.config.target_defaults.default_configuration =
require('fs')
.readdirSync(require('path').join(__dirname, 'build'))
Expand Down Expand Up @@ -68,7 +91,7 @@ let testModules = [
'version_management'
];

let napiVersion = Number(process.versions.napi)
let napiVersion = Number(process.versions.napi);
if (process.env.NAPI_VERSION) {
// we need this so that we don't try run tests that rely
// on methods that are not available in the NAPI_VERSION
Expand All @@ -77,8 +100,6 @@ if (process.env.NAPI_VERSION) {
}
console.log('napiVersion:' + napiVersion);

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

if (napiVersion < 3) {
testModules.splice(testModules.indexOf('callbackscope'), 1);
testModules.splice(testModules.indexOf('version_management'), 1);
Expand Down Expand Up @@ -110,40 +131,19 @@ if (majorNodeVersion < 12) {
testModules.splice(testModules.indexOf('objectwrap_worker_thread'), 1);
}

if (typeof global.gc === 'function') {
(async function() {
console.log(`Testing with N-API Version '${napiVersion}'.`);
(async function() {
console.log(`Testing with N-API Version '${napiVersion}'.`);

console.log('Starting test suite\n');
console.log('Starting test suite\n');

// Requiring each module runs tests in the module.
for (const name of testModules) {
console.log(`Running test '${name}'`);
await require('./' + name);
};
// Requiring each module runs tests in the module.
for (const name of testModules) {
console.log(`Running test '${name}'`);
await require('./' + name);
};

console.log('\nAll tests passed!');
})().catch((error) => {
console.log(error);
process.exit(1);
});
} else {
// Construct the correct (version-dependent) command-line args.
let args = ['--expose-gc', '--no-concurrent-array-buffer-freeing'];
if (majorNodeVersion >= 14) {
args.push('--no-concurrent-array-buffer-sweeping');
}
args.push(__filename);

const child = require('./napi_child').spawnSync(process.argv[0], args, {
stdio: 'inherit',
});

if (child.signal) {
console.error(`Tests aborted with ${child.signal}`);
process.exitCode = 1;
} else {
process.exitCode = child.status;
}
process.exit(process.exitCode);
}
console.log('\nAll tests passed!');
})().catch((error) => {
console.log(error);
process.exit(1);
});