Skip to content
Merged
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
7 changes: 5 additions & 2 deletions test/addons/async-resource/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -26,7 +26,7 @@ async_hooks.createHook({
assert.strictEqual(triggerAsyncId, expectedTriggerId);
bindingUids.push(id);
}
},
}, 7),

before(id) {
if (bindingUids.includes(id)) before++;
Expand All @@ -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';
},
Expand Down
4 changes: 2 additions & 2 deletions test/addons/cppgc-object/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -48,4 +48,4 @@ setTimeout(async function() {
'All old CppGCed are destroyed',
() => states[kDestructCount] === count * 2,
);
}, 1);
})().then(common.mustCall())), 1);
4 changes: 2 additions & 2 deletions test/addons/make-callback-recurse/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
42 changes: 8 additions & 34 deletions test/addons/no-addons/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
});
12 changes: 6 additions & 6 deletions test/addons/no-addons/test-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ 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
const worker = new Worker(`require(${JSON.stringify(binding)})`, {
eval: true,
});

worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}

{
Expand All @@ -35,7 +35,7 @@ const assertError = (error) => {
},
);

worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}

{
Expand All @@ -45,7 +45,7 @@ const assertError = (error) => {
execArgv: ['--no-addons'],
});

worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}

{
Expand All @@ -55,5 +55,5 @@ const assertError = (error) => {
execArgv: [],
});

worker.on('error', common.mustCall(assertError));
worker.on('error', assertError);
}
42 changes: 8 additions & 34 deletions test/addons/no-addons/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
});
4 changes: 2 additions & 2 deletions test/addons/null-buffer-neuter/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const binding = require(`./build/${common.buildType}/binding`);

binding.run();
global.gc();
setImmediate(() => {
setImmediate(common.mustCall(() => {
assert.strictEqual(binding.isAlive(), 0);
});
}));
6 changes: 3 additions & 3 deletions test/addons/symlinked-module/submodule.js
Original file line number Diff line number Diff line change
@@ -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);
16 changes: 15 additions & 1 deletion test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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',
Expand Down
Loading