From 42b1c8fd44eb63e3bcabd6ffc49f2e3e1c33c51c Mon Sep 17 00:00:00 2001 From: John French Date: Fri, 23 Apr 2021 20:51:19 +0800 Subject: [PATCH] test: run test suites with helpers PR-URL: https://github.com/nodejs/node-addon-api/pull/976 Reviewed-By: Michael Dawson --- test/addon.js | 5 +- test/addon_data.js | 9 +--- test/arraybuffer.js | 5 +- test/asynccontext.js | 49 ++++++++++++------- test/asyncprogressqueueworker.js | 6 +-- test/asyncprogressworker.js | 5 +- test/asyncworker-nocallback.js | 5 +- test/asyncworker-persistent.js | 13 ++--- test/asyncworker.js | 23 ++++++--- test/basic_types/array.js | 4 +- test/basic_types/boolean.js | 5 +- test/basic_types/number.js | 4 +- test/basic_types/value.js | 4 +- test/bigint.js | 4 +- test/buffer.js | 5 +- test/callbackscope.js | 15 +++--- test/common/index.js | 27 ++++++++++ test/dataview/dataview.js | 5 +- test/dataview/dataview_read_write.js | 4 +- test/date.js | 4 +- test/error.js | 5 +- test/external.js | 6 +-- test/function.js | 10 ++-- .../global_object_delete_property.js | 5 +- .../global_object_get_property.js | 5 +- .../global_object_has_own_property.js | 5 +- .../global_object_set_property.js | 5 +- test/handlescope.js | 5 +- test/index.js | 16 +++--- test/memory_management.js | 7 ++- test/movable_callbacks.js | 10 +--- test/name.js | 5 +- test/object/delete_property.js | 4 +- test/object/finalizer.js | 4 +- test/object/get_property.js | 4 +- test/object/has_own_property.js | 4 +- test/object/has_property.js | 4 +- test/object/object.js | 5 +- test/object/object_deprecated.js | 5 +- test/object/object_freeze_seal.js | 5 +- test/object/set_property.js | 4 +- test/object/subscript_operator.js | 4 +- test/objectreference.js | 5 +- test/objectwrap-removewrap.js | 6 +-- test/objectwrap.js | 7 ++- test/objectwrap_constructor_exception.js | 5 +- test/objectwrap_multiple_inheritance.js | 4 +- test/objectwrap_worker_thread.js | 3 +- test/promise.js | 5 +- test/reference.js | 5 +- test/run_script.js | 5 +- .../threadsafe_function.js | 6 +-- .../threadsafe_function_ctx.js | 4 +- .../threadsafe_function_existing_tsfn.js | 7 +-- .../threadsafe_function_ptr.js | 5 +- .../threadsafe_function_sum.js | 4 +- .../threadsafe_function_unref.js | 4 +- test/thunking_manual.js | 5 +- .../typed_threadsafe_function.js | 6 +-- .../typed_threadsafe_function_ctx.js | 4 +- ...typed_threadsafe_function_existing_tsfn.js | 5 +- .../typed_threadsafe_function_ptr.js | 5 +- .../typed_threadsafe_function_sum.js | 4 +- .../typed_threadsafe_function_unref.js | 4 +- test/typedarray-bigint.js | 5 +- test/typedarray.js | 5 +- test/version_management.js | 5 +- 67 files changed, 191 insertions(+), 260 deletions(-) diff --git a/test/addon.js b/test/addon.js index 54a5f66..b9fca2f 100644 --- a/test/addon.js +++ b/test/addon.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { assert.strictEqual(binding.addon.increment(), 43); diff --git a/test/addon_data.js b/test/addon_data.js index 571b23e..1762d96 100644 --- a/test/addon_data.js +++ b/test/addon_data.js @@ -1,15 +1,10 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const { spawn } = require('child_process'); const readline = require('readline'); -const path = require('path'); -module.exports = - test(path.resolve(__dirname, `./build/${buildType}/binding.node`)) - .then(() => - test(path.resolve(__dirname, - `./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTestWithBindingPath(test); // Make sure the instance data finalizer is called at process exit. If the hint // is non-zero, it will be printed out by the child process. diff --git a/test/arraybuffer.js b/test/arraybuffer.js index 363de17..942686f 100644 --- a/test/arraybuffer.js +++ b/test/arraybuffer.js @@ -1,10 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const testUtil = require('./testUtil'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTest(test); function test(binding) { return testUtil.runGCTests([ diff --git a/test/asynccontext.js b/test/asynccontext.js index e9b4aab..d6a3fc5 100644 --- a/test/asynccontext.js +++ b/test/asynccontext.js @@ -1,5 +1,5 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const common = require('./common'); @@ -17,14 +17,27 @@ function checkAsyncHooks() { return false; } -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = common.runTest(test); function installAsyncHooksForTest() { return new Promise((resolve, reject) => { let id; const events = []; - const hook = async_hooks.createHook({ + /** + * TODO(legendecas): investigate why resolving & disabling hooks in + * destroy callback causing crash with case 'callbackscope.js'. + */ + let hook; + let destroyed = false; + const interval = setInterval(() => { + if (destroyed) { + hook.disable(); + clearInterval(interval); + resolve(events); + } + }, 10); + + hook = async_hooks.createHook({ init(asyncId, type, triggerAsyncId, resource) { if (id === undefined && type === 'async_context_test') { id = asyncId; @@ -44,8 +57,7 @@ function installAsyncHooksForTest() { destroy(asyncId) { if (asyncId === id) { events.push({ eventName: 'destroy' }); - hook.disable(); - resolve(events); + destroyed = true; } } }).enable(); @@ -53,21 +65,22 @@ function installAsyncHooksForTest() { } function test(binding) { - binding.asynccontext.makeCallback(common.mustCall(), { foo: 'foo' }); - if (!checkAsyncHooks()) + if (!checkAsyncHooks()) { return; + } const hooks = installAsyncHooksForTest(); const triggerAsyncId = async_hooks.executionAsyncId(); - hooks.then(actual => { - assert.deepStrictEqual(actual, [ - { eventName: 'init', - type: 'async_context_test', - triggerAsyncId: triggerAsyncId, - resource: { foo: 'foo' } }, - { eventName: 'before' }, - { eventName: 'after' }, - { eventName: 'destroy' } - ]); + binding.asynccontext.makeCallback(common.mustCall(), { foo: 'foo' }); + return hooks.then(actual => { + assert.deepStrictEqual(actual, [ + { eventName: 'init', + type: 'async_context_test', + triggerAsyncId: triggerAsyncId, + resource: { foo: 'foo' } }, + { eventName: 'before' }, + { eventName: 'after' }, + { eventName: 'destroy' } + ]); }).catch(common.mustNotCall()); } diff --git a/test/asyncprogressqueueworker.js b/test/asyncprogressqueueworker.js index 4bb525e..e715001 100644 --- a/test/asyncprogressqueueworker.js +++ b/test/asyncprogressqueueworker.js @@ -1,11 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const common = require('./common') const assert = require('assert'); -const os = require('os'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = common.runTest(test); async function test({ asyncprogressqueueworker }) { await success(asyncprogressqueueworker); diff --git a/test/asyncprogressworker.js b/test/asyncprogressworker.js index 285fd2a..2a81b20 100644 --- a/test/asyncprogressworker.js +++ b/test/asyncprogressworker.js @@ -1,10 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const common = require('./common') const assert = require('assert'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = common.runTest(test); async function test({ asyncprogressworker }) { await success(asyncprogressworker); diff --git a/test/asyncworker-nocallback.js b/test/asyncworker-nocallback.js index fa9c172..d4e28ce 100644 --- a/test/asyncworker-nocallback.js +++ b/test/asyncworker-nocallback.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const common = require('./common'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = common.runTest(test); async function test(binding) { await binding.asyncworker.doWorkNoCallback(true, {}) diff --git a/test/asyncworker-persistent.js b/test/asyncworker-persistent.js index d584086..f4febac 100644 --- a/test/asyncworker-persistent.js +++ b/test/asyncworker-persistent.js @@ -1,9 +1,6 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -const common = require('./common'); -const binding = require(`./build/${buildType}/binding.node`); -const noexceptBinding = require(`./build/${buildType}/binding_noexcept.node`); function test(binding, succeed) { return new Promise((resolve) => @@ -21,7 +18,7 @@ function test(binding, succeed) { })); } -module.exports = test(binding.persistentasyncworker, false) - .then(() => test(binding.persistentasyncworker, true)) - .then(() => test(noexceptBinding.persistentasyncworker, false)) - .then(() => test(noexceptBinding.persistentasyncworker, true)); +module.exports = require('./common').runTest(async binding => { + await test(binding.persistentasyncworker, false); + await test(binding.persistentasyncworker, true); +}); diff --git a/test/asyncworker.js b/test/asyncworker.js index 0f008bb..46ab143 100644 --- a/test/asyncworker.js +++ b/test/asyncworker.js @@ -1,5 +1,4 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); const common = require('./common'); @@ -17,14 +16,27 @@ function checkAsyncHooks() { return false; } -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = common.runTest(test); function installAsyncHooksForTest() { return new Promise((resolve, reject) => { let id; const events = []; - const hook = async_hooks.createHook({ + /** + * TODO(legendecas): investigate why resolving & disabling hooks in + * destroy callback causing crash with case 'callbackscope.js'. + */ + let hook; + let destroyed = false; + const interval = setInterval(() => { + if (destroyed) { + hook.disable(); + clearInterval(interval); + resolve(events); + } + }, 10); + + hook = async_hooks.createHook({ init(asyncId, type, triggerAsyncId, resource) { if (id === undefined && type === 'TestResource') { id = asyncId; @@ -44,8 +56,7 @@ function installAsyncHooksForTest() { destroy(asyncId) { if (asyncId === id) { events.push({ eventName: 'destroy' }); - hook.disable(); - resolve(events); + destroyed = true; } } }).enable(); diff --git a/test/basic_types/array.js b/test/basic_types/array.js index 38ccba4..a3e5694 100644 --- a/test/basic_types/array.js +++ b/test/basic_types/array.js @@ -1,9 +1,7 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { diff --git a/test/basic_types/boolean.js b/test/basic_types/boolean.js index 13817ee..04f38e5 100644 --- a/test/basic_types/boolean.js +++ b/test/basic_types/boolean.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { const bool1 = binding.basic_types_boolean.createBoolean(true); diff --git a/test/basic_types/number.js b/test/basic_types/number.js index a7c66bb..592b6ad 100644 --- a/test/basic_types/number.js +++ b/test/basic_types/number.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { const MIN_INT32 = -2147483648; diff --git a/test/basic_types/value.js b/test/basic_types/value.js index bef7e44..81a95cb 100644 --- a/test/basic_types/value.js +++ b/test/basic_types/value.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { const externalValue = binding.basic_types_value.createExternal(); diff --git a/test/bigint.js b/test/bigint.js index 0af867b..bc27d95 100644 --- a/test/bigint.js +++ b/test/bigint.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { const { diff --git a/test/buffer.js b/test/buffer.js index ff17d30..9ff5ec1 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -1,11 +1,10 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const testUtil = require('./testUtil'); const safeBuffer = require('safe-buffer'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTest(test); function test(binding) { return testUtil.runGCTests([ diff --git a/test/callbackscope.js b/test/callbackscope.js index 523bca4..7396482 100644 --- a/test/callbackscope.js +++ b/test/callbackscope.js @@ -1,7 +1,5 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -const common = require('./common'); // we only check async hooks on 8.x an higher were // they are closer to working properly @@ -17,8 +15,7 @@ function checkAsyncHooks() { return false; } -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { if (!checkAsyncHooks()) @@ -26,7 +23,7 @@ function test(binding) { let id; let insideHook = false; - async_hooks.createHook({ + const hook = async_hooks.createHook({ init(asyncId, type, triggerAsyncId, resource) { if (id === undefined && type === 'callback_scope_test') { id = asyncId; @@ -42,7 +39,11 @@ function test(binding) { } }).enable(); - binding.callbackscope.runInCallbackScope(function() { - assert(insideHook); + return new Promise(resolve => { + binding.callbackscope.runInCallbackScope(function() { + assert(insideHook); + hook.disable(); + resolve(); + }); }); } diff --git a/test/common/index.js b/test/common/index.js index 54139bb..65bdc10 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -74,3 +74,30 @@ exports.mustNotCall = function(msg) { assert.fail(msg || 'function should not have been called'); }; }; + +exports.runTest = async function(test, buildType) { + buildType = buildType || process.config.target_defaults.default_configuration; + + const bindings = [ + `../build/${buildType}/binding.node`, + `../build/${buildType}/binding_noexcept.node`, + ].map(it => require.resolve(it)); + + for (const item of bindings) { + await Promise.resolve(test(require(item))) + .finally(exports.mustCall()); + } +} + +exports.runTestWithBindingPath = async function(test, buildType) { + buildType = buildType || process.config.target_defaults.default_configuration; + + const bindings = [ + `../build/${buildType}/binding.node`, + `../build/${buildType}/binding_noexcept.node`, + ].map(it => require.resolve(it)); + + for (const item of bindings) { + await test(item); + } +} diff --git a/test/dataview/dataview.js b/test/dataview/dataview.js index 4e39364..1d476c4 100644 --- a/test/dataview/dataview.js +++ b/test/dataview/dataview.js @@ -1,10 +1,7 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); - -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function testDataViewCreation(factory, arrayBuffer, offset, length) { diff --git a/test/dataview/dataview_read_write.js b/test/dataview/dataview_read_write.js index 83d58cc..fb8502a 100644 --- a/test/dataview/dataview_read_write.js +++ b/test/dataview/dataview_read_write.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function expected(type, value) { diff --git a/test/date.js b/test/date.js index 16e618e..bd24291 100644 --- a/test/date.js +++ b/test/date.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { const { diff --git a/test/error.js b/test/error.js index 031db08..763115c 100644 --- a/test/error.js +++ b/test/error.js @@ -1,5 +1,5 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); if (process.argv[2] === 'fatal') { @@ -8,8 +8,7 @@ if (process.argv[2] === 'fatal') { return; } -test(`./build/${buildType}/binding.node`); -test(`./build/${buildType}/binding_noexcept.node`); +module.exports = require('./common').runTestWithBindingPath(test); function test(bindingPath) { const binding = require(bindingPath); diff --git a/test/external.js b/test/external.js index 0443e3f..8a8cebc 100644 --- a/test/external.js +++ b/test/external.js @@ -1,5 +1,5 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const { spawnSync } = require('child_process'); const testUtil = require('./testUtil'); @@ -40,9 +40,7 @@ if (process.argv.length === 3) { return; } -module.exports = test(require.resolve(`./build/${buildType}/binding.node`)) - .then(() => - test(require.resolve(`./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTestWithBindingPath(test); function test(bindingPath) { const binding = require(bindingPath); diff --git a/test/function.js b/test/function.js index d98b194..9c30e04 100644 --- a/test/function.js +++ b/test/function.js @@ -1,11 +1,11 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`).function.plain); -test(require(`./build/${buildType}/binding_noexcept.node`).function.plain); -test(require(`./build/${buildType}/binding.node`).function.templated); -test(require(`./build/${buildType}/binding_noexcept.node`).function.templated); +module.exports = require('./common').runTest(binding => { + test(binding.function.plain); + test(binding.function.templated); +}); function test(binding) { assert.strictEqual(binding.emptyConstructor(true), true); diff --git a/test/globalObject/global_object_delete_property.js b/test/globalObject/global_object_delete_property.js index 8852007..c3f3dad 100644 --- a/test/globalObject/global_object_delete_property.js +++ b/test/globalObject/global_object_delete_property.js @@ -1,11 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); - +module.exports = require('../common').runTest(test); function test(binding) { const KEY_TYPE = { diff --git a/test/globalObject/global_object_get_property.js b/test/globalObject/global_object_get_property.js index 3630f43..83b3373 100644 --- a/test/globalObject/global_object_get_property.js +++ b/test/globalObject/global_object_get_property.js @@ -1,11 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); - +module.exports = require('../common').runTest(test); function test(binding) { const KEY_TYPE = { diff --git a/test/globalObject/global_object_has_own_property.js b/test/globalObject/global_object_has_own_property.js index d3955cd..30deeec 100644 --- a/test/globalObject/global_object_has_own_property.js +++ b/test/globalObject/global_object_has_own_property.js @@ -1,11 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); - +module.exports = require('../common').runTest(test); function test(binding) { const KEY_TYPE = { diff --git a/test/globalObject/global_object_set_property.js b/test/globalObject/global_object_set_property.js index 06f01a6..d934efa 100644 --- a/test/globalObject/global_object_set_property.js +++ b/test/globalObject/global_object_set_property.js @@ -1,11 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); - +module.exports = require('../common').runTest(test); function test(binding) { const KEY_TYPE = { diff --git a/test/handlescope.js b/test/handlescope.js index 71cb897..f8887f0 100644 --- a/test/handlescope.js +++ b/test/handlescope.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { assert.strictEqual(binding.handlescope.createScope(), 'scope'); diff --git a/test/index.js b/test/index.js index 46bb749..1b03f76 100644 --- a/test/index.js +++ b/test/index.js @@ -117,17 +117,17 @@ if (napiVersion < 8) { } (async function() { -console.log(`Testing with Node-API Version '${napiVersion}'.`); + console.log(`Testing with Node-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!'); + console.log('\nAll tests passed!'); })().catch((error) => { console.log(error); process.exit(1); diff --git a/test/memory_management.js b/test/memory_management.js index f4911a2..707899e 100644 --- a/test/memory_management.js +++ b/test/memory_management.js @@ -1,10 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); -function test(binding) { +function test(binding) { assert.strictEqual(binding.memory_management.externalAllocatedMemory(), true) } diff --git a/test/movable_callbacks.js b/test/movable_callbacks.js index 49810d5..3588295 100644 --- a/test/movable_callbacks.js +++ b/test/movable_callbacks.js @@ -1,15 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const common = require('./common'); const testUtil = require('./testUtil'); -Promise.all([ - test(require(`./build/${buildType}/binding.node`).movable_callbacks), - test(require(`./build/${buildType}/binding_noexcept.node`).movable_callbacks), -]).catch(e => { - console.error(e); - process.exitCode = 1; -}); +module.exports = require('./common').runTest(binding => test(binding.movable_callbacks)); async function test(binding) { await testUtil.runGCTests([ diff --git a/test/name.js b/test/name.js index 4e96593..4577746 100644 --- a/test/name.js +++ b/test/name.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { const expected = '123456789'; diff --git a/test/object/delete_property.js b/test/object/delete_property.js index b65e063..459298d 100644 --- a/test/object/delete_property.js +++ b/test/object/delete_property.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function testDeleteProperty(nativeDeleteProperty) { diff --git a/test/object/finalizer.js b/test/object/finalizer.js index 312b2de..bf2fb18 100644 --- a/test/object/finalizer.js +++ b/test/object/finalizer.js @@ -1,11 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); const testUtil = require('../testUtil'); -module.exports = test(require(`../build/${buildType}/binding.node`)) - .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); +module.exports = require('../common').runTest(test); function createWeakRef(binding, bindingToTest) { return binding.object[bindingToTest]({}); diff --git a/test/object/get_property.js b/test/object/get_property.js index b2b68d9..d661bab 100644 --- a/test/object/get_property.js +++ b/test/object/get_property.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function testGetProperty(nativeGetProperty) { diff --git a/test/object/has_own_property.js b/test/object/has_own_property.js index 570b0ee..fda74c3 100644 --- a/test/object/has_own_property.js +++ b/test/object/has_own_property.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function testHasOwnProperty(nativeHasOwnProperty) { diff --git a/test/object/has_property.js b/test/object/has_property.js index f283fc7..722f006 100644 --- a/test/object/has_property.js +++ b/test/object/has_property.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function testHasProperty(nativeHasProperty) { diff --git a/test/object/object.js b/test/object/object.js index 4b6f72f..ef06ad2 100644 --- a/test/object/object.js +++ b/test/object/object.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function assertPropertyIs(obj, key, attribute) { diff --git a/test/object/object_deprecated.js b/test/object/object_deprecated.js index 153fb11..00ee7b4 100644 --- a/test/object/object_deprecated.js +++ b/test/object/object_deprecated.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { if (!('object_deprecated' in binding)) { diff --git a/test/object/object_freeze_seal.js b/test/object/object_freeze_seal.js index f85c36d..b6434b6 100644 --- a/test/object/object_freeze_seal.js +++ b/test/object/object_freeze_seal.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { { diff --git a/test/object/set_property.js b/test/object/set_property.js index 9b64cc5..772538b 100644 --- a/test/object/set_property.js +++ b/test/object/set_property.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function testSetProperty(nativeSetProperty) { diff --git a/test/object/subscript_operator.js b/test/object/subscript_operator.js index 21a6ee8..0caefe4 100644 --- a/test/object/subscript_operator.js +++ b/test/object/subscript_operator.js @@ -1,10 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { function testProperty(obj, key, value, nativeGetProperty, nativeSetProperty) { diff --git a/test/objectreference.js b/test/objectreference.js index 55b95db..daecb59 100644 --- a/test/objectreference.js +++ b/test/objectreference.js @@ -10,12 +10,11 @@ */ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const testUtil = require('./testUtil'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTest(test); function test(binding) { function testCastedEqual(testToCompare) { diff --git a/test/objectwrap-removewrap.js b/test/objectwrap-removewrap.js index 560f61d..c7c99aa 100644 --- a/test/objectwrap-removewrap.js +++ b/test/objectwrap-removewrap.js @@ -5,11 +5,12 @@ if (process.argv[2] === 'child') { return new (require(process.argv[3]).objectwrap.Test)(); } -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); const { spawnSync } = require('child_process'); const testUtil = require('./testUtil'); +module.exports = require('./common').runTestWithBindingPath(test); + function test(bindingName) { return testUtil.runGCTests([ 'objectwrap removewrap test', @@ -37,6 +38,3 @@ function test(bindingName) { assert.strictEqual(child.signal, null); assert.strictEqual(child.status, 0); } - -module.exports = test(`./build/${buildType}/binding.node`) - .then(() => test(`./build/${buildType}/binding_noexcept.node`)); diff --git a/test/objectwrap.js b/test/objectwrap.js index 3a41683..2dcd12f 100644 --- a/test/objectwrap.js +++ b/test/objectwrap.js @@ -1,8 +1,10 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const testUtil = require('./testUtil'); +module.exports = require('./common').runTest(test); + async function test(binding) { const Test = binding.objectwrap.Test; @@ -280,6 +282,3 @@ async function test(binding) { // Make sure the C++ object can be garbage collected without issues. await testUtil.runGCTests(['one last gc', () => {}, () => {}]); } - -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); diff --git a/test/objectwrap_constructor_exception.js b/test/objectwrap_constructor_exception.js index 02dff2c..6a5e469 100644 --- a/test/objectwrap_constructor_exception.js +++ b/test/objectwrap_constructor_exception.js @@ -1,5 +1,5 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const testUtil = require('./testUtil'); @@ -15,5 +15,4 @@ function test(binding) { ]); } -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTest(test); diff --git a/test/objectwrap_multiple_inheritance.js b/test/objectwrap_multiple_inheritance.js index 87c669e..d4d2282 100644 --- a/test/objectwrap_multiple_inheritance.js +++ b/test/objectwrap_multiple_inheritance.js @@ -1,6 +1,5 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); const test = bindingName => { @@ -11,5 +10,4 @@ const test = bindingName => { assert.strictEqual(testmi.test, 0); } -test(`./build/${buildType}/binding.node`); -test(`./build/${buildType}/binding_noexcept.node`); +module.exports = require('./common').runTestWithBindingPath(test); diff --git a/test/objectwrap_worker_thread.js b/test/objectwrap_worker_thread.js index 5e5e50b..eedc9ee 100644 --- a/test/objectwrap_worker_thread.js +++ b/test/objectwrap_worker_thread.js @@ -10,6 +10,5 @@ if (isMainThread) { }; const buildType = workerData; - test(require(`./build/${buildType}/binding.node`)); - test(require(`./build/${buildType}/binding_noexcept.node`)); + require('./common').runTest(test, buildType); } diff --git a/test/promise.js b/test/promise.js index 65544c6..f681a2e 100644 --- a/test/promise.js +++ b/test/promise.js @@ -1,10 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const common = require('./common'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = common.runTest(test); async function test(binding) { assert.strictEqual(binding.promise.isPromise({}), false); diff --git a/test/reference.js b/test/reference.js index 22ee8c8..8c56cea 100644 --- a/test/reference.js +++ b/test/reference.js @@ -1,12 +1,9 @@ 'use strict'; - -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); const testUtil = require('./testUtil'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTest(test); function test(binding) { return testUtil.runGCTests([ diff --git a/test/run_script.js b/test/run_script.js index ec36dcf..711ab10 100644 --- a/test/run_script.js +++ b/test/run_script.js @@ -1,10 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); const testUtil = require('./testUtil'); -module.exports = test(require(`./build/${buildType}/binding.node`)) - .then(() => test(require(`./build/${buildType}/binding_noexcept.node`))); +module.exports = require('./common').runTest(test); function test(binding) { return testUtil.runGCTests([ diff --git a/test/threadsafe_function/threadsafe_function.js b/test/threadsafe_function/threadsafe_function.js index 419c214..7da0e3d 100644 --- a/test/threadsafe_function/threadsafe_function.js +++ b/test/threadsafe_function/threadsafe_function.js @@ -1,13 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); const common = require('../common'); -module.exports = (async function() { - await test(require(`../build/${buildType}/binding.node`)); - await test(require(`../build/${buildType}/binding_noexcept.node`)); -})(); +module.exports = common.runTest(test); async function test(binding) { const expectedArray = (function(arrayLength) { diff --git a/test/threadsafe_function/threadsafe_function_ctx.js b/test/threadsafe_function/threadsafe_function_ctx.js index 2651586..94ea01f 100644 --- a/test/threadsafe_function/threadsafe_function_ctx.js +++ b/test/threadsafe_function/threadsafe_function_ctx.js @@ -1,10 +1,8 @@ 'use strict'; const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; -module.exports = test(require(`../build/${buildType}/binding.node`)) - .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); +module.exports = require('../common').runTest(test); async function test(binding) { const ctx = { }; diff --git a/test/threadsafe_function/threadsafe_function_existing_tsfn.js b/test/threadsafe_function/threadsafe_function_existing_tsfn.js index d5ab185..f459787 100644 --- a/test/threadsafe_function/threadsafe_function_existing_tsfn.js +++ b/test/threadsafe_function/threadsafe_function_existing_tsfn.js @@ -2,14 +2,11 @@ const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; - -module.exports = test(require(`../build/${buildType}/binding.node`)) - .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); +module.exports = require('../common').runTest(test); async function test(binding) { const testCall = binding.threadsafe_function_existing_tsfn.testCall; - + assert.strictEqual(typeof await testCall({ blocking: true, data: true }), "number"); assert.strictEqual(typeof await testCall({ blocking: true, data: false }), "undefined"); assert.strictEqual(typeof await testCall({ blocking: false, data: true }), "number"); diff --git a/test/threadsafe_function/threadsafe_function_ptr.js b/test/threadsafe_function/threadsafe_function_ptr.js index 535b5d6..1890816 100644 --- a/test/threadsafe_function/threadsafe_function_ptr.js +++ b/test/threadsafe_function/threadsafe_function_ptr.js @@ -1,9 +1,6 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; - -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { binding.threadsafe_function_ptr.test({}, () => {}); diff --git a/test/threadsafe_function/threadsafe_function_sum.js b/test/threadsafe_function/threadsafe_function_sum.js index 738e31d..64f2b45 100644 --- a/test/threadsafe_function/threadsafe_function_sum.js +++ b/test/threadsafe_function/threadsafe_function_sum.js @@ -1,6 +1,5 @@ 'use strict'; const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; /** * @@ -29,8 +28,7 @@ const buildType = process.config.target_defaults.default_configuration; const THREAD_COUNT = 5; const EXPECTED_SUM = (THREAD_COUNT - 1) * (THREAD_COUNT) / 2; -module.exports = test(require(`../build/${buildType}/binding.node`)) - .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); +module.exports = require('../common').runTest(test); /** @param {number[]} N */ const sum = (N) => N.reduce((sum, n) => sum + n, 0); diff --git a/test/threadsafe_function/threadsafe_function_unref.js b/test/threadsafe_function/threadsafe_function_unref.js index e8f0ee3..85aa85d 100644 --- a/test/threadsafe_function/threadsafe_function_unref.js +++ b/test/threadsafe_function/threadsafe_function_unref.js @@ -1,7 +1,6 @@ 'use strict'; const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; const isMainProcess = process.argv[1] != __filename; @@ -15,8 +14,7 @@ const isMainProcess = process.argv[1] != __filename; */ if (isMainProcess) { - module.exports = test(`../build/${buildType}/binding.node`) - .then(() => test(`../build/${buildType}/binding_noexcept.node`)); + module.exports = require('../common').runTestWithBindingPath(test); } else { test(process.argv[2]); } diff --git a/test/thunking_manual.js b/test/thunking_manual.js index 22fb887..f1a93e2 100644 --- a/test/thunking_manual.js +++ b/test/thunking_manual.js @@ -1,10 +1,9 @@ // Flags: --expose-gc 'use strict'; -const buildType = 'Debug'; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { console.log("Thunking: Performing initial GC"); diff --git a/test/typed_threadsafe_function/typed_threadsafe_function.js b/test/typed_threadsafe_function/typed_threadsafe_function.js index 7aa8cc2..5d4a52a 100644 --- a/test/typed_threadsafe_function/typed_threadsafe_function.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function.js @@ -1,13 +1,9 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; const assert = require('assert'); const common = require('../common'); -module.exports = (async function () { - await test(require(`../build/${buildType}/binding.node`)); - await test(require(`../build/${buildType}/binding_noexcept.node`)); -})(); +module.exports = common.runTest(test); async function test(binding) { const expectedArray = (function (arrayLength) { diff --git a/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js b/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js index 2651586..94ea01f 100644 --- a/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_ctx.js @@ -1,10 +1,8 @@ 'use strict'; const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; -module.exports = test(require(`../build/${buildType}/binding.node`)) - .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); +module.exports = require('../common').runTest(test); async function test(binding) { const ctx = { }; diff --git a/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js b/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js index b6df669..bd37824 100644 --- a/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_existing_tsfn.js @@ -2,10 +2,7 @@ const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; - -module.exports = test(require(`../build/${buildType}/binding.node`)) - .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); +module.exports = require('../common').runTest(test); async function test(binding) { const testCall = binding.typed_threadsafe_function_existing_tsfn.testCall; diff --git a/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js b/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js index 47b1877..36b146c 100644 --- a/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_ptr.js @@ -1,9 +1,6 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; - -test(require(`../build/${buildType}/binding.node`)); -test(require(`../build/${buildType}/binding_noexcept.node`)); +module.exports = require('../common').runTest(test); function test(binding) { binding.typed_threadsafe_function_ptr.test({}, () => {}); diff --git a/test/typed_threadsafe_function/typed_threadsafe_function_sum.js b/test/typed_threadsafe_function/typed_threadsafe_function_sum.js index 8f10476..59e6670 100644 --- a/test/typed_threadsafe_function/typed_threadsafe_function_sum.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_sum.js @@ -1,6 +1,5 @@ 'use strict'; const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; /** * @@ -29,8 +28,7 @@ const buildType = process.config.target_defaults.default_configuration; const THREAD_COUNT = 5; const EXPECTED_SUM = (THREAD_COUNT - 1) * (THREAD_COUNT) / 2; -module.exports = test(require(`../build/${buildType}/binding.node`)) - .then(() => test(require(`../build/${buildType}/binding_noexcept.node`))); +module.exports = require('../common').runTest(test); /** @param {number[]} N */ const sum = (N) => N.reduce((sum, n) => sum + n, 0); diff --git a/test/typed_threadsafe_function/typed_threadsafe_function_unref.js b/test/typed_threadsafe_function/typed_threadsafe_function_unref.js index 55b42a5..aafc5e0 100644 --- a/test/typed_threadsafe_function/typed_threadsafe_function_unref.js +++ b/test/typed_threadsafe_function/typed_threadsafe_function_unref.js @@ -1,7 +1,6 @@ 'use strict'; const assert = require('assert'); -const buildType = process.config.target_defaults.default_configuration; const isMainProcess = process.argv[1] != __filename; @@ -15,8 +14,7 @@ const isMainProcess = process.argv[1] != __filename; */ if (isMainProcess) { - module.exports = test(`../build/${buildType}/binding.node`) - .then(() => test(`../build/${buildType}/binding_noexcept.node`)); + module.exports = require('../common').runTestWithBindingPath(test); } else { test(process.argv[2]); } diff --git a/test/typedarray-bigint.js b/test/typedarray-bigint.js index ce66d38..e96a51f 100644 --- a/test/typedarray-bigint.js +++ b/test/typedarray-bigint.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { [ diff --git a/test/typedarray.js b/test/typedarray.js index 9aa880c..5d0fb4a 100644 --- a/test/typedarray.js +++ b/test/typedarray.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function test(binding) { const testData = [ diff --git a/test/version_management.js b/test/version_management.js index f52db2f..6bb1b18 100644 --- a/test/version_management.js +++ b/test/version_management.js @@ -1,9 +1,8 @@ 'use strict'; -const buildType = process.config.target_defaults.default_configuration; + const assert = require('assert'); -test(require(`./build/${buildType}/binding.node`)); -test(require(`./build/${buildType}/binding_noexcept.node`)); +module.exports = require('./common').runTest(test); function parseVersion() { const expected = {};