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: removed the usage of default_configuration. #1226

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
"benchmark": "node benchmark",
"pretest": "node-gyp rebuild -C test",
"test": "node test",
"test:debug": "node-gyp rebuild -C test --debug && NODE_API_BUILD_CONFIG=Debug node ./test/index.js",
"predev": "node-gyp rebuild -C test --debug",
"dev": "node test",
"predev:incremental": "node-gyp configure build -C test --debug",
Expand Down
41 changes: 37 additions & 4 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';
const assert = require('assert');
const path = require('path');
const { access } = require('node:fs/promises');

const noop = () => {};

Expand Down Expand Up @@ -75,9 +76,41 @@ exports.mustNotCall = function (msg) {
};
};

exports.runTest = async function (test, buildType, buildPathRoot = process.env.BUILD_PATH || '') {
buildType = buildType || process.config.target_defaults.default_configuration || 'Release';
const buildTypes = {
Release: 'Release',
Debug: 'Debug'
};

async function checkBuildType (buildType) {
try {
await access(path.join(path.resolve('./test/build'), buildType));
return true;
} catch {
return false;
}
}

async function whichBuildType () {
legendecas marked this conversation as resolved.
Show resolved Hide resolved
let buildType = 'Release';
const envBuildType = process.env.NODE_API_BUILD_CONFIG;
if (envBuildType) {
if (Object.values(buildTypes).includes(envBuildType)) {
if (await checkBuildType(envBuildType)) {
buildType = envBuildType;
} else {
throw new Error(`The ${envBuildType} build doesn't exists.`);
}
} else {
throw new Error('Invalid value for NODE_API_BUILD_CONFIG environment variable. It should be set to Release or Debug.');
}
}
return buildType;
}

exports.whichBuildType = whichBuildType;

exports.runTest = async function (test, buildType, buildPathRoot = process.env.BUILD_PATH || '') {
buildType = buildType || await whichBuildType();
const bindings = [
path.join(buildPathRoot, `../build/${buildType}/binding.node`),
path.join(buildPathRoot, `../build/${buildType}/binding_noexcept.node`),
Expand All @@ -92,7 +125,7 @@ exports.runTest = async function (test, buildType, buildPathRoot = process.env.B
};

exports.runTestWithBindingPath = async function (test, buildType, buildPathRoot = process.env.BUILD_PATH || '') {
buildType = buildType || process.config.target_defaults.default_configuration || 'Release';
buildType = buildType || await whichBuildType();

const bindings = [
path.join(buildPathRoot, `../build/${buildType}/binding.node`),
Expand All @@ -107,7 +140,7 @@ exports.runTestWithBindingPath = async function (test, buildType, buildPathRoot
};

exports.runTestWithBuildType = async function (test, buildType) {
buildType = buildType || process.config.target_defaults.default_configuration || 'Release';
buildType = buildType || await whichBuildType();

await Promise.resolve(test(buildType))
.finally(exports.mustCall());
Expand Down
18 changes: 12 additions & 6 deletions test/error_terminating_environment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const buildType = process.config.target_defaults.default_configuration;

const assert = require('assert');
const { whichBuildType } = require('./common');

// These tests ensure that Error types can be used in a terminating
// environment without triggering any fatal errors.
Expand Down Expand Up @@ -63,11 +64,16 @@ if (process.argv[2] === 'runInChildProcess') {
assert.fail('This should not be reachable');
}

test(`./build/${buildType}/binding.node`, true);
test(`./build/${buildType}/binding_noexcept.node`, true);
test(`./build/${buildType}/binding_swallowexcept.node`, false);
test(`./build/${buildType}/binding_swallowexcept_noexcept.node`, false);
test(`./build/${buildType}/binding_custom_namespace.node`, true);
wrapTest();

async function wrapTest () {
const buildType = await whichBuildType();
test(`./build/${buildType}/binding.node`, true);
test(`./build/${buildType}/binding_noexcept.node`, true);
test(`./build/${buildType}/binding_swallowexcept.node`, false);
test(`./build/${buildType}/binding_swallowexcept_noexcept.node`, false);
test(`./build/${buildType}/binding_custom_namespace.node`, true);
}

function test (bindingPath, processShouldAbort) {
const numberOfTestCases = 5;
Expand Down
7 changes: 5 additions & 2 deletions test/maybe/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';

const buildType = process.config.target_defaults.default_configuration;
const assert = require('assert');
const { whichBuildType } = require('../common');

const napiChild = require('../napi_child');

module.exports = test(require(`../build/${buildType}/binding_noexcept_maybe.node`).maybe_check);
module.exports = async function wrapTest () {
const buildType = await whichBuildType();
test(require(`../build/${buildType}/binding_noexcept_maybe.node`).maybe_check);
};

function test (binding) {
if (process.argv.includes('child')) {
Expand Down
7 changes: 4 additions & 3 deletions test/objectwrap_worker_thread.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';
const path = require('path');
const { Worker, isMainThread } = require('worker_threads');
const { runTestWithBuildType, whichBuildType } = require('./common');

module.exports = require('./common').runTestWithBuildType(test);
module.exports = runTestWithBuildType(test);

async function test (buildType) {
async function test () {
if (isMainThread) {
const buildType = process.config.target_defaults.default_configuration;
const buildType = await whichBuildType();
const worker = new Worker(__filename, { workerData: buildType });
return new Promise((resolve, reject) => {
worker.on('exit', () => {
Expand Down