test: ensure assertions are reachable in test/addons

PR-URL: https://github.com/nodejs/node/pull/60142
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Antoine du Hamel committed 2025-11-13 22:44:12 +01:00
1 parent 1659078c11
commit 84576ef021
9 files changed
+51 -86

No files matched your search

+5 -2
View File
@@ -17,7 +17,7 @@ let after = 0;
let destroy = 0;
async_hooks.createHook({
init(id, type, triggerAsyncId, resource) {
init: common.mustCall((id, type, triggerAsyncId, resource) => {
assert.strictEqual(typeof id, 'number');
assert.strictEqual(typeof resource, 'object');
assert(id > 1);
@@ -26,7 +26,7 @@ async_hooks.createHook({
assert.strictEqual(triggerAsyncId, expectedTriggerId);
bindingUids.push(id);
}
},
}, 7),
before(id) {
if (bindingUids.includes(id)) before++;
@@ -48,8 +48,11 @@ for (const call of [binding.callViaFunction,
let uid;
const object = {
methöd(arg) {
// eslint-disable-next-line node-core/must-call-assert
assert.strictEqual(this, object);
// eslint-disable-next-line node-core/must-call-assert
assert.strictEqual(arg, 42);
// eslint-disable-next-line node-core/must-call-assert
assert.strictEqual(async_hooks.executionAsyncId(), uid);
return 'baz';
},
+2 -2
View File
@@ -23,7 +23,7 @@ for (let i = 0; i < count; ++i) {
globalThis.gc();
setTimeout(async function() {
setTimeout(common.mustCall(() => (async function() {
// GC should have invoked Trace() on at least some of the CppGCed objects,
// but they should all be alive at this point.
assert.strictEqual(states[kDestructCount], 0);
@@ -48,4 +48,4 @@ setTimeout(async function() {
'All old CppGCed are destroyed',
() => states[kDestructCount] === count * 2,
);
}, 1);
})().then(common.mustCall())), 1);
+2 -2
View File
@@ -71,11 +71,11 @@ assert.throws(() => {
if (arg === 1) {
// The tests are first run on bootstrap during LoadEnvironment() in
// src/node.cc. Now run the tests through node::MakeCallback().
setImmediate(() => {
setImmediate(common.mustCall(() => {
makeCallback({}, common.mustCall(() => {
verifyExecutionOrder(2);
}));
});
}));
} else if (arg === 2) {
// Make sure there are no conflicts using node::MakeCallback()
// within timers.
+8 -34
View File
@@ -7,37 +7,11 @@ const assert = require('assert');
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
const assertError = (error) => {
assert(error instanceof Error);
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
assert.strictEqual(
error.message,
'Cannot load native addon because loading addons is disabled.',
);
};
{
let threw = false;
try {
require(bindingPath);
} catch (error) {
assertError(error);
threw = true;
}
assert(threw);
}
{
let threw = false;
try {
process.dlopen({ exports: {} }, bindingPath);
} catch (error) {
assertError(error);
threw = true;
}
assert(threw);
}
assert.throws(() => require(bindingPath), {
code: 'ERR_DLOPEN_DISABLED',
message: 'Cannot load native addon because loading addons is disabled.',
});
assert.throws(() => process.dlopen({ exports: {} }, bindingPath), {
code: 'ERR_DLOPEN_DISABLED',
message: 'Cannot load native addon because loading addons is disabled.',
});
+6 -6
View File
@@ -9,13 +9,13 @@ const { Worker } = require('worker_threads');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
const assertError = (error) => {
const assertError = common.mustCall((error) => {
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
assert.strictEqual(
error.message,
'Cannot load native addon because loading addons is disabled.',
);
};
}, 4);
{
// Flags should be inherited
@@ -23,7 +23,7 @@ const assertError = (error) => {
eval: true,
});
worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}
{
@@ -35,7 +35,7 @@ const assertError = (error) => {
},
);
worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}
{
@@ -45,7 +45,7 @@ const assertError = (error) => {
execArgv: ['--no-addons'],
});
worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}
{
@@ -55,5 +55,5 @@ const assertError = (error) => {
execArgv: [],
});
worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}
+8 -34
View File
@@ -7,37 +7,11 @@ const assert = require('assert');
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
const assertError = (error) => {
assert(error instanceof Error);
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
assert.strictEqual(
error.message,
'Cannot load native addon because loading addons is disabled.',
);
};
{
let threw = false;
try {
require(bindingPath);
} catch (error) {
assertError(error);
threw = true;
}
assert(threw);
}
{
let threw = false;
try {
process.dlopen({ exports: {} }, bindingPath);
} catch (error) {
assertError(error);
threw = true;
}
assert(threw);
}
assert.throws(() => require(bindingPath), {
code: 'ERR_DLOPEN_DISABLED',
message: 'Cannot load native addon because loading addons is disabled.',
});
assert.throws(() => process.dlopen({ exports: {} }, bindingPath), {
code: 'ERR_DLOPEN_DISABLED',
message: 'Cannot load native addon because loading addons is disabled.',
});
+2 -2
View File
@@ -6,6 +6,6 @@ const binding = require(`./build/${common.buildType}/binding`);
binding.run();
global.gc();
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(binding.isAlive(), 0);
});
}));
+3 -3
View File
@@ -1,13 +1,13 @@
'use strict';
require('../../common');
const common = require('../../common');
const path = require('path');
const assert = require('assert');
// This is a subtest of symlinked-module/test.js. This is not
// intended to be run directly.
module.exports.test = function test(bindingDir) {
module.exports.test = common.mustCall(function test(bindingDir) {
const mod = require(path.join(bindingDir, 'binding.node'));
assert.notStrictEqual(mod, null);
assert.strictEqual(mod.hello(), 'world');
};
}, require.main === module ? 0 : 2);
+15 -1
View File
@@ -155,7 +155,21 @@ export default [
},
{
files: [
'test/{async-hooks,benchmark,cctest,client-proxy,message,module-hooks,node-api,pummel,pseudo-tty,v8-updates,wasi}/**/*.{js,mjs,cjs}',
`test/{${[
'abort',
'addons',
'async-hooks',
'benchmark',
'cctest',
'client-proxy',
'message',
'module-hooks',
'node-api',
'pummel',
'pseudo-tty',
'v8-updates',
'wasi',
].join(',')}}/**/*.{js,mjs,cjs}`,
],
rules: {
'node-core/must-call-assert': 'error',