8000 test: ensure assertions are reached on more tests by aduh95 · Pull Request #60641 · nodejs/node · GitHub
[go: up one dir, main page]

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
4 changes: 2 additions & 2 deletions test/addons/callback-scope/test-async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ async_hooks.createHook({
}),
}).enable();

runInCallbackScope({}, 1000, 1000, () => {
runInCallbackScope({}, 1000, 1000, common.mustCallAtLeast(() => {
assert(insideHook);
});
}));
2 changes: 1 addition & 1 deletion test/addons/callback-scope/test-resolve-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const { testResolveAsync } = require(`./build/${common.buildType}/binding`);
let called = false;
testResolveAsync().then(() => { called = true; });

process.on('beforeExit', () => { assert(called); });
process.on('beforeExit', common.mustCall(() => { assert(called); }));
8 changes: 4 additions & 4 deletions test/async-hooks/test-async-local-storage-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const server = http.createServer((req, res) => {
res.end('ok');
});

server.listen(0, () => {
asyncLocalStorage.run(new Map(), () => {
server.listen(0, mustCall(() => {
asyncLocalStorage.run(new Map(), mustCall(() => {
const store = asyncLocalStorage.getStore();
store.set('hello', 'world');
http.get({ host: 'localhost', port: server.address().port }, mustCall(() => {
assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
server.close();
}));
});
});
}));
}));
2 changes: 1 addition & 1 deletion test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default [
].join(',')}}/**/*.{js,mjs,cjs}`,
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 3 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
Array.from({ length: 4 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
Expand Down
12 changes: 6 additions & 6 deletions test/module-hooks/test-module-hooks-custom-conditions-cjs.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
// allow a CJS to be resolved with that condition.
{
const hooks = registerHooks({
resolve(specifier, context, nextResolve) {
resolve: common.mustCall((specifier, context, nextResolve) => {
assert(Array.isArray(context.conditions));
context.conditions = ['foo', ...context.conditions];
return nextResolve(specifier, context);
},
}, 2),
});
assert.strictEqual(cjs('foo/second').result, 'foo');
assert.strictEqual((await esm('foo/second')).result, 'foo');
Expand All @@ -30,11 +30,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
// allow a ESM to be BE2E resolved with that condition.
{
const hooks = registerHooks({
resolve(specifier, context, nextResolve) {
resolve: common.mustCall((specifier, context, nextResolve) => {
assert(Array.isArray(context.conditions));
context.conditions = ['foo-esm', ...context.conditions];
return nextResolve(specifier, context);
},
}, 2),
});
assert.strictEqual(cjs('foo/third').result, 'foo-esm');
assert.strictEqual((await esm('foo/third')).result, 'foo-esm');
Expand All @@ -44,11 +44,11 @@ const { cjs, esm } = require('../fixtures/es-modules/custom-condition/load.cjs')
// Duplicating the 'foo' condition in the resolve hook should not change the result.
{
const hooks = registerHooks({
resolve(specifier, context, nextResolve) {
resolve: common.mustCall((specifier, context, nextResolve) => {
assert(Array.isArray(context.conditions));
context.conditions = ['foo', ...context.conditions, 'foo'];
return nextResolve(specifier, context);
},
}, 2),
});
assert.strictEqual(cjs('foo/fourth').result, 'foo');
assert.strictEqual((await esm('foo/fourth')).result, 'foo');
Expand Down
14 changes: 7 additions & 7 deletions test/module-hooks/test-module-hooks-custom-conditions.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This tests that custom conditions can be used in module resolution hooks.
import '../common/index.mjs';
import * as common from '../common/index.mjs';
import { registerHooks } from 'node:module';
import assert from 'node:assert';
import { cjs, esm } from '../fixtures/es-modules/custom-condition/load.cjs';
Expand All @@ -12,11 +12,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
// allow a CJS to be resolved with that condition.
{
const hooks = registerHooks({
resolve(specifier, context, nextResolve) {
resolve: common.mustCall((specifier, context, nextResolve) => {
assert(Array.isArray(context.conditions));
context.conditions = ['foo', ...context.conditions];
return nextResolve(specifier, context);
},
}, 2),
});
assert.strictEqual(cjs('foo/second').result, 'foo');
assert.strictEqual((await esm('foo/second')).result, 'foo');
Expand All @@ -27,11 +27,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
// allow a ESM to be resolved with that condition.
{
const hooks = registerHooks({
resolve(specifier, context, nextResolve) {
resolve: common.mustCall((specifier, context, nextResolve) => {
assert(Array.isArray(context.conditions));
context.conditions = ['foo-esm', ...context.conditions];
return nextResolve(specifier, context);
},
}, 2),
});
assert.strictEqual(cjs('foo/third').result, 'foo-esm');
assert.strictEqual((await esm('foo/third')).result, 'foo-esm');
Expand All @@ -41,11 +41,11 @@ assert.strictEqual((await esm('foo')).result, 'default');
// Duplicating the 'foo' condition in the resolve hook should not change the result.
{
const hooks = registerHooks({
resolve(specifier, context, nextResolve) {
resolve: common.mustCall((specifier, context, nextResolve) => {
assert(Array.isArray(context.conditions));
context.conditions = ['foo', ...context.conditions, 'foo'];
return nextResolve(specifier, context);
},
}, 2),
});
assert.strictEqual(cjs('foo/fourth').result, 'foo');
assert.strictEqual((await esm('foo/fourth')).result, 'foo');
Expand Down
4 changes: 2 additions & 2 deletions test/node-api/test_callback_scope/test-async-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ async_hooks.createHook({
}),
}).enable();

runInCallbackScope(expectedResource, expectedResourceType, () => {
runInCallbackScope(expectedResource, expectedResourceType, common.mustCall(() => {
assert(insideHook);
});
}));
4 changes: 2 additions & 2 deletions test/parallel/test-assert.js
4D92
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

const { invalidArgTypeHelper } = require('../common');
const { invalidArgTypeHelper, mustCall } = require('../common');
const assert = require('assert');
const { inspect } = require('util');
const { test } = require('node:test');
Expand Down Expand Up @@ -605,7 +605,7 @@ test('Test strict assert', () => {
}
);
strict.throws(
() => assert(),
mustCall(() => assert()),
{
message: 'No value argument passed to `assert.ok()`',
name: 'AssertionError'
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-fork-net.js
BE2E
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ if (process.argv[2] === 'child') {
function closeServer() {
server.close();

setTimeout(() => {
setTimeout(mustCall(() => {
assert(!closeEmitted);
child1.send('close');
child2.send('close');
child3.disconnect();
}, platformTimeout(200));
}), platformTimeout(200));
}

process.on('exit', function() {
Expand Down
22 changes: 11 additions & 11 deletions test/parallel/test-cluster-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,36 +160,36 @@ if (cluster.isWorker) {
}));

// Check all values
process.once('exit', () => {
process.on('exit', () => {
// Check cluster events
forEach(checks.cluster.events, (check, name) => {
for (const [ name, check ] of Object.entries(checks.cluster.events)) {
assert(check,
`The cluster event "${name}" on the cluster object did not fire`);
});
}

// Check cluster event arguments
forEach(checks.cluster.equal, (check, name) => {
for (const [ name, check ] of Object.entries(checks.cluster.equal)) {
assert(check,
`The cluster event "${name}" did not emit with correct argument`);
});
}

// Check worker states
forEach(checks.worker.states, (check, name) => {
for (const [ name, check ] of Object.entries(checks.worker.states)) {
assert(check,
`The worker state "${name}" was not set to true`);
});
}

// Check worker events
forEach(checks.worker.events, (check, name) => {
for (const [ name, check ] of Object.entries(checks.worker.events)) {
assert(check,
`The worker event "${name}" on the worker object did not fire`);
});
}

// Check worker event arguments
forEach(checks.worker.equal, (check, name) => {
for (const [ name, check ] of Object.entries(checks.worker.equal)) {
assert(check,
`The worker event "${name}" did not emit with correct argument`);
});
}
});

}
6 changes: 3 additions & 3 deletions test/parallel/test-cluster-send-deadlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ if (cluster.isPrimary) {
worker.send({ message: 'listen', port: server.address().port });
});
} else {
process.on('message', (msg, handle) => {
if (msg.message && msg.message === 'listen') {
process.on('message', common.mustCallAtLeast((msg, handle) => {
if (msg.message === 'listen') {
assert(msg.port);
const client1 = net.connect({
host: 'localhost',
Expand All @@ -69,5 +69,5 @@ if (cluster.isPrimary) {
} else {
process.send('reply', handle);
}
});
}));
}
8 changes: 4 additions & 4 deletions test/parallel/test-cluster-worker-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ const check = common.mustCallAtLeast((m) => {
process.emit('error', 'HI');
});

process.on('message', (m) => {
process.on('message', common.mustCall((m) => {
assert(!sawProcess);
sawProcess = true;
check(m);
});
}));

cluster.worker.on('message', (m) => {
cluster.worker.on('message', common.mustCall((m) => {
assert(!sawWorker);
sawWorker = true;
check(m);
});
}));
10 changes: 5 additions & 5 deletions < B8BA span class="Truncate"> test/parallel/test-cluster-worker-no-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
Expand All @@ -41,21 +41,21 @@ let server;
// 4 destroy connection
// 5 confirm it does exit
if (cluster.isPrimary) {
server = net.createServer(function(conn) {
server = net.createServer(common.mustCall((conn) => {
server.close();
worker.disconnect();
worker.once('disconnect', function() {
setTimeout(function() {
conn.destroy();
destroyed = true;
}, 1000);
}).once('exit', function() {
}).once('exit', common.mustCall(() => {
// Worker should not exit while it has a connection
assert(destroyed, 'worker exited before connection destroyed');
success = true;
});
}));

}).listen(0, function() {
})).listen(0, function() {
const port = this.address().port;

worker = cluster.fork()
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-cluster-worker-wait-server-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ if (cluster.isWorker) {
const keepOpen = setInterval(() => {}, 9999);

// Check worker events and properties
process.once('disconnect', function() {
process.once('disconnect', common.mustCall(() => {
// Disconnect should occur after socket close
assert(serverClosed);
clearInterval(keepOpen);
});
}));
} else if (cluster.isPrimary) {
// start worker
const worker = cluster.fork();
Expand Down
9 changes: 4 additions & 5 deletions test/parallel/test-crypto-hkdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,8 @@ algorithms.forEach(([ hash, secret, salt, info, length ]) => {

if (!hasOpenSSL3) {
const kKnownUnsupported = ['shake128', 'shake256'];
getHashes()
.filter((hash) => !kKnownUnsupported.includes(hash))
.forEach((hash) => {
assert(hkdfSync(hash, 'key', 'salt', 'info', 5));
});
for (const hash of getHashes()) {
if (kKnownUnsupported.includes(hash)) continue;
assert(hkdfSync(hash, 'key', 'salt', 'info', 5));
}
}
4 changes: 2 additions & 2 deletions test/parallel/test-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ function testEncoding(options, assertionHash) {
const hash = crypto.createHash('sha256', options);
let hashValue = '';

hash.on('data', (data) => {
hash.on('data', common.mustCall((data) => {
// The defaultEncoding has no effect on the hash value. It only affects data
// consumed by the Hash transform stream.
assert(Buffer.isBuffer(data));
hashValue += data.toString('hex');
});
}));

hash.on('end', common.mustCall(() => {
assert.strictEqual(hashValue, assertionHash);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-debugger-auto-resume.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { path as _path } from '../common/fixtures.js';
import startCLI from '../common/debugger.js';
import { addLibraryPath } from '../common/shared-lib-util.js';

import { deepStrictEqual, strictEqual } from 'assert';
import assert from 'assert';
import { relative } from 'path';

addLibraryPath(process.env);
Expand All @@ -24,10 +24,10 @@ addLibraryPath(process.env);
const cli = startCLI([script], [], { env });

await cli.waitForInitialBreak();
deepStrictEqual(cli.breakInfo, {
assert.deepStrictEqual(cli.breakInfo, {
filename: script,
line: 10,
});
const code = await cli.quit();
strictEqual(code, 0);
assert.strictEqual(code, 0);
}
6 changes: 2 additions & 4 deletions test/parallel/test-debugger-preserve-breaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const scriptFullPath = fixtures.path('debugger', 'three-lines.js');
const script = path.relative(process.cwd(), scriptFullPath);

// Run after quit.
const runTest = async () => {
(async () => {
const cli = startCLI([script]);
try {
await cli.waitForInitialBreak();
Expand Down Expand Up @@ -42,6 +42,4 @@ const runTest = async () => {
} finally {
await cli.quit();
}
};

runTest();
})().then(common.mustCall());
4 changes: 2 additions & 2 deletions test/parallel/test-debugger-websocket-secret-mismatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const server = http.createServer(common.mustCall((req, res) => {
childProcess.spawn(process.execPath, ['inspect', `localhost:${port}`]);

let stdout = '';
proc.stdout.on('data', (data) => {
proc.stdout.on('data', common.mustCallAtLeast((data) => {
stdout += data.toString();
assert.doesNotMatch(stdout, /\bok\b/);
});
}));

let stderr = '';
proc.stderr.on('data', (data) => {
Expand Down
Loading
Loading
0