Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29a5855

Browse filesBrowse files
committed
test: ensure assertions are reachable in test/addons
PR-URL: #60142 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 3d183e3 commit 29a5855
Copy full SHA for 29a5855

File tree

Expand file treeCollapse file tree

9 files changed

+51
-86
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

9 files changed

+51
-86
lines changed
Open diff view settings
Collapse file

‎test/addons/async-resource/test.js‎

Copy file name to clipboardExpand all lines: test/addons/async-resource/test.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let after = 0;
1717
let destroy = 0;
1818

1919
async_hooks.createHook({
20-
init(id, type, triggerAsyncId, resource) {
20+
init: common.mustCall((id, type, triggerAsyncId, resource) => {
2121
assert.strictEqual(typeof id, 'number');
2222
assert.strictEqual(typeof resource, 'object');
2323
assert(id > 1);
@@ -26,7 +26,7 @@ async_hooks.createHook({
2626
assert.strictEqual(triggerAsyncId, expectedTriggerId);
2727
bindingUids.push(id);
2828
}
29-
},
29+
}, 7),
3030

3131
before(id) {
3232
if (bindingUids.includes(id)) before++;
@@ -48,8 +48,11 @@ for (const call of [binding.callViaFunction,
4848
let uid;
4949
const object = {
5050
methöd(arg) {
51+
// eslint-disable-next-line node-core/must-call-assert
5152
assert.strictEqual(this, object);
53+
// eslint-disable-next-line node-core/must-call-assert
5254
assert.strictEqual(arg, 42);
55+
// eslint-disable-next-line node-core/must-call-assert
5356
assert.strictEqual(async_hooks.executionAsyncId(), uid);
5457
return 'baz';
5558
},
Collapse file

‎test/addons/cppgc-object/test.js‎

Copy file name to clipboardExpand all lines: test/addons/cppgc-object/test.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ for (let i = 0; i < count; ++i) {
2323

2424
globalThis.gc();
2525

26-
setTimeout(async function() {
26+
setTimeout(common.mustCall(() => (async function() {
2727
// GC should have invoked Trace() on at least some of the CppGCed objects,
2828
// but they should all be alive at this point.
2929
assert.strictEqual(states[kDestructCount], 0);
@@ -48,4 +48,4 @@ setTimeout(async function() {
4848
'All old CppGCed are destroyed',
4949
() => states[kDestructCount] === count * 2,
5050
);
51-
}, 1);
51+
})().then(common.mustCall())), 1);
Collapse file

‎test/addons/make-callback-recurse/test.js‎

Copy file name to clipboardExpand all lines: test/addons/make-callback-recurse/test.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ assert.throws(() => {
7171
if (arg === 1) {
7272
// The tests are first run on bootstrap during LoadEnvironment() in
7373
// src/node.cc. Now run the tests through node::MakeCallback().
74-
setImmediate(() => {
74+
setImmediate(common.mustCall(() => {
7575
makeCallback({}, common.mustCall(() => {
7676
verifyExecutionOrder(2);
7777
}));
78-
});
78+
}));
7979
} else if (arg === 2) {
8080
// Make sure there are no conflicts using node::MakeCallback()
8181
// within timers.
Collapse file

‎test/addons/no-addons/permission.js‎

Copy file name to clipboardExpand all lines: test/addons/no-addons/permission.js
+8-34Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,11 @@ const assert = require('assert');
77

88
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
99

10-
const assertError = (error) => {
11-
assert(error instanceof Error);
12-
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
13-
assert.strictEqual(
14-
error.message,
15-
'Cannot load native addon because loading addons is disabled.',
16-
);
17-
};
18-
19-
{
20-
let threw = false;
21-
22-
try {
23-
require(bindingPath);
24-
} catch (error) {
25-
assertError(error);
26-
threw = true;
27-
}
28-
29-
assert(threw);
30-
}
31-
32-
{
33-
let threw = false;
34-
35-
try {
36-
process.dlopen({ exports: {} }, bindingPath);
37-
} catch (error) {
38-
assertError(error);
39-
threw = true;
40-
}
41-
42-
assert(threw);
43-
}
10+
assert.throws(() => require(bindingPath), {
11+
code: 'ERR_DLOPEN_DISABLED',
12+
message: 'Cannot load native addon because loading addons is disabled.',
13+
});
14+
assert.throws(() => process.dlopen({ exports: {} }, bindingPath), {
15+
code: 'ERR_DLOPEN_DISABLED',
16+
message: 'Cannot load native addon because loading addons is disabled.',
17+
});
Collapse file

‎test/addons/no-addons/test-worker.js‎

Copy file name to clipboardExpand all lines: test/addons/no-addons/test-worker.js
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ const { Worker } = require('worker_threads');
99

1010
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
1111

12-
const assertError = (error) => {
12+
const assertError = common.mustCall((error) => {
1313
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
1414
assert.strictEqual(
1515
error.message,
1616
'Cannot load native addon because loading addons is disabled.',
1717
);
18-
};
18+
}, 4);
1919

2020
{
2121
// Flags should be inherited
2222
const worker = new Worker(`require(${JSON.stringify(binding)})`, {
2323
eval: true,
2424
});
2525

26-
worker.on('error', common.mustCall(assertError));
26+
worker.on('error', assertError);
2727
}
2828

2929
{
@@ -35,7 +35,7 @@ const assertError = (error) => {
3535
},
3636
);
3737

38-
worker.on('error', common.mustCall(assertError));
38+
worker.on('error', assertError);
3939
}
4040

4141
{
@@ -45,7 +45,7 @@ const assertError = (error) => {
4545
execArgv: ['--no-addons'],
4646
});
4747

48-
worker.on('error', common.mustCall(assertError));
48+
worker.on('error', assertError);
4949
}
5050

5151
{
@@ -55,5 +55,5 @@ const assertError = (error) => {
5555
execArgv: [],
5656
});
5757

58-
worker.on('error', common.mustCall(assertError));
58+
worker.on('error', assertError);
5959
}
Collapse file

‎test/addons/no-addons/test.js‎

Copy file name to clipboardExpand all lines: test/addons/no-addons/test.js
+8-34Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,11 @@ const assert = require('assert');
77

88
const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
99

10-
const assertError = (error) => {
11-
assert(error instanceof Error);
12-
assert.strictEqual(error.code, 'ERR_DLOPEN_DISABLED');
13-
assert.strictEqual(
14-
error.message,
15-
'Cannot load native addon because loading addons is disabled.',
16-
);
17-
};
18-
19-
{
20-
let threw = false;
21-
22-
try {
23-
require(bindingPath);
24-
} catch (error) {
25-
assertError(error);
26-
threw = true;
27-
}
28-
29-
assert(threw);
30-
}
31-
32-
{
33-
let threw = false;
34-
35-
try {
36-
process.dlopen({ exports: {} }, bindingPath);
37-
} catch (error) {
38-
assertError(error);
39-
threw = true;
40-
}
41-
42-
assert(threw);
43-
}
10+
assert.throws(() => require(bindingPath), {
11+
code: 'ERR_DLOPEN_DISABLED',
12+
message: 'Cannot load native addon because loading addons is disabled.',
13+
});
14+
assert.throws(() => process.dlopen({ exports: {} }, bindingPath), {
15+
code: 'ERR_DLOPEN_DISABLED',
16+
message: 'Cannot load native addon because loading addons is disabled.',
17+
});
Collapse file

‎test/addons/null-buffer-neuter/test.js‎

Copy file name to clipboardExpand all lines: test/addons/null-buffer-neuter/test.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ const binding = require(`./build/${common.buildType}/binding`);
66

77
binding.run();
88
global.gc();
9-
setImmediate(() => {
9+
setImmediate(common.mustCall(() => {
1010
assert.strictEqual(binding.isAlive(), 0);
11-
});
11+
}));
Collapse file
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
2-
require('../../common');
2+
const common = require('../../common');
33
const path = require('path');
44
const assert = require('assert');
55

66
// This is a subtest of symlinked-module/test.js. This is not
77
// intended to be run directly.
88

9-
module.exports.test = function test(bindingDir) {
9+
module.exports.test = common.mustCall(function test(bindingDir) {
1010
const mod = require(path.join(bindingDir, 'binding.node'));
1111
assert.notStrictEqual(mod, null);
1212
assert.strictEqual(mod.hello(), 'world');
13-
};
13+
}, require.main === module ? 0 : 2);
Collapse file

‎test/eslint.config_partial.mjs‎

Copy file name to clipboardExpand all lines: test/eslint.config_partial.mjs
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,21 @@ export default [
156156
},
157157
{
158158
files: [
159-
'test/{async-hooks,benchmark,cctest,client-proxy,message,module-hooks,node-api,pummel,pseudo-tty,v8-updates,wasi}/**/*.{js,mjs,cjs}',
159+
`test/{${[
160+
'abort',
161+
'addons',
162+
'async-hooks',
163+
'benchmark',
164+
'cctest',
165+
'client-proxy',
166+
'message',
167+
'module-hooks',
168+
'node-api',
169+
'pummel',
170+
'pseudo-tty',
171+
'v8-updates',
172+
'wasi',
173+
].join(',')}}/**/*.{js,mjs,cjs}`,
160174
],
161175
rules: {
162176
'node-core/must-call-assert': 'error',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.