test: ensure assertions are reached on more tests

PR-URL: https://github.com/nodejs/node/pull/60763
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Antoine du Hamel committed 2026-01-20 14:26:58 +01:00
1 parent 141fb82ffb
commit 5ee02c789a
53 files changed
+283 -300

No files matched your search

+1 -1
View File
@@ -203,7 +203,7 @@ export default [
`test/parallel/test-{${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
},n*,${
},n*,r*,${
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
}}.{js,mjs,cjs}`,
@@ -2,7 +2,7 @@
const { mustCall, mustNotCall } = require('../common');
const { Readable } = require('stream');
const { strictEqual } = require('assert');
const assert = require('assert');
async function asyncSupport() {
const finallyMustCall = mustCall();
@@ -20,7 +20,7 @@ async function asyncSupport() {
for await (const chunk of stream) {
bodyMustCall();
strictEqual(chunk, 'a');
assert.strictEqual(chunk, 'a');
break;
}
}
@@ -41,7 +41,7 @@ async function syncSupport() {
for await (const chunk of stream) {
bodyMustCall();
strictEqual(chunk, 'a');
assert.strictEqual(chunk, 'a');
break;
}
}
@@ -66,7 +66,7 @@ async function syncPromiseSupport() {
for await (const chunk of stream) {
bodyMustCall();
strictEqual(chunk, 'a');
assert.strictEqual(chunk, 'a');
break;
}
}
@@ -130,7 +130,6 @@ async function noReturnAfterThrow() {
async function closeStreamWhileNextIsPending() {
const finallyMustCall = mustCall();
const dataMustCall = mustCall();
let resolveDestroy;
const destroyed =
@@ -153,10 +152,9 @@ async function closeStreamWhileNextIsPending() {
const stream = Readable.from(infiniteGenerate());
stream.on('data', (data) => {
dataMustCall();
strictEqual(data, 'a');
});
stream.on('data', mustCall((data) => {
assert.strictEqual(data, 'a');
}));
yielded.then(() => {
stream.destroy();
@@ -166,7 +164,6 @@ async function closeStreamWhileNextIsPending() {
async function closeAfterNullYielded() {
const finallyMustCall = mustCall();
const dataMustCall = mustCall(3);
function* generate() {
try {
@@ -180,10 +177,9 @@ async function closeAfterNullYielded() {
const stream = Readable.from(generate());
stream.on('data', (chunk) => {
dataMustCall();
strictEqual(chunk, 'a');
});
stream.on('data', mustCall((chunk) => {
assert.strictEqual(chunk, 'a');
}, 3));
}
Promise.all([
@@ -1,7 +1,7 @@
'use strict';
const { mustCall } = require('../common');
const { Readable, Duplex } = require('stream');
const { strictEqual } = require('assert');
const assert = require('assert');
function start(controller) {
controller.enqueue(new Uint8Array(1));
@@ -10,7 +10,7 @@ function start(controller) {
Readable.fromWeb(new ReadableStream({ start }))
.on('data', mustCall((d) => {
strictEqual(d.length, 1);
assert.strictEqual(d.length, 1);
}))
.on('end', mustCall())
.resume();
@@ -20,7 +20,7 @@ Duplex.fromWeb({
writable: new WritableStream({ write(chunk) {} })
})
.on('data', mustCall((d) => {
strictEqual(d.length, 1);
assert.strictEqual(d.length, 1);
}))
.on('end', mustCall())
.resume();
+23 -23
View File
@@ -3,11 +3,11 @@
const { mustCall } = require('../common');
const { once } = require('events');
const { Readable } = require('stream');
const { strictEqual, throws } = require('assert');
const assert = require('assert');
const common = require('../common');
{
throws(() => {
assert.throws(() => {
Readable.from(null);
}, /ERR_INVALID_ARG_TYPE/);
}
@@ -24,7 +24,7 @@ async function toReadableBasicSupport() {
const expected = ['a', 'b', 'c'];
for await (const chunk of stream) {
strictEqual(chunk, expected.shift());
assert.strictEqual(chunk, expected.shift());
}
}
@@ -40,7 +40,7 @@ async function toReadableSyncIterator() {
const expected = ['a', 'b', 'c'];
for await (const chunk of stream) {
strictEqual(chunk, expected.shift());
assert.strictEqual(chunk, expected.shift());
}
}
@@ -56,7 +56,7 @@ async function toReadablePromises() {
const expected = ['a', 'b', 'c'];
for await (const chunk of stream) {
strictEqual(chunk, expected.shift());
assert.strictEqual(chunk, expected.shift());
}
}
@@ -66,7 +66,7 @@ async function toReadableString() {
const expected = ['abc'];
for await (const chunk of stream) {
strictEqual(chunk, expected.shift());
assert.strictEqual(chunk, expected.shift());
}
}
@@ -76,7 +76,7 @@ async function toReadableBuffer() {
const expected = ['abc'];
for await (const chunk of stream) {
strictEqual(chunk.toString(), expected.shift());
assert.strictEqual(chunk.toString(), expected.shift());
}
}
@@ -92,14 +92,14 @@ async function toReadableOnData() {
let iterations = 0;
const expected = ['a', 'b', 'c'];
stream.on('data', (chunk) => {
stream.on('data', common.mustCallAtLeast((chunk) => {
iterations++;
strictEqual(chunk, expected.shift());
});
assert.strictEqual(chunk, expected.shift());
}));
await once(stream, 'end');
strictEqual(iterations, 3);
assert.strictEqual(iterations, 3);
}
async function toReadableOnDataNonObject() {
@@ -114,15 +114,15 @@ async function toReadableOnDataNonObject() {
let iterations = 0;
const expected = ['a', 'b', 'c'];
stream.on('data', (chunk) => {
stream.on('data', common.mustCallAtLeast((chunk) => {
iterations++;
strictEqual(chunk instanceof Buffer, true);
strictEqual(chunk.toString(), expected.shift());
});
assert.strictEqual(chunk instanceof Buffer, true);
assert.strictEqual(chunk.toString(), expected.shift());
}));
await once(stream, 'end');
strictEqual(iterations, 3);
assert.strictEqual(iterations, 3);
}
async function destroysTheStreamWhenThrowing() {
@@ -135,8 +135,8 @@ async function destroysTheStreamWhenThrowing() {
stream.read();
const [err] = await once(stream, 'error');
strictEqual(err.message, 'kaboom');
strictEqual(stream.destroyed, true);
assert.strictEqual(err.message, 'kaboom');
assert.strictEqual(stream.destroyed, true);
}
@@ -162,7 +162,7 @@ async function asTransformStream() {
const expected = ['A', 'B', 'C'];
for await (const chunk of stream) {
strictEqual(chunk, expected.shift());
assert.strictEqual(chunk, expected.shift());
}
}
@@ -179,18 +179,18 @@ async function endWithError() {
try {
for await (const chunk of stream) {
strictEqual(chunk, expected.shift());
assert.strictEqual(chunk, expected.shift());
}
throw new Error();
} catch (err) {
strictEqual(expected.length, 0);
strictEqual(err, 'Boum');
assert.strictEqual(expected.length, 0);
assert.strictEqual(err, 'Boum');
}
}
async function destroyingStreamWithErrorThrowsInGenerator() {
const validateError = common.mustCall((e) => {
strictEqual(e, 'Boum');
assert.strictEqual(e, 'Boum');
});
async function* generate() {
try {
+8 -8
View File
@@ -284,10 +284,10 @@ function assertCursorRowsAndCols(rli, rows, cols) {
const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
// ['foo', 'baz', 'bar', bat'];
let callCount = 0;
rli.on('line', (line) => {
rli.on('line', common.mustCallAtLeast((line) => {
assert.strictEqual(line, expectedLines[callCount]);
callCount++;
});
}));
fi.emit('data', `${expectedLines.join('\n')}\n`);
assert.strictEqual(callCount, expectedLines.length);
fi.emit('keypress', '.', { name: 'up' }); // 'bat'
@@ -360,10 +360,10 @@ function assertCursorRowsAndCols(rli, rows, cols) {
});
const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
let callCount = 0;
rli.on('line', (line) => {
rli.on('line', common.mustCallAtLeast((line) => {
assert.strictEqual(line, expectedLines[callCount]);
callCount++;
});
}));
fi.emit('data', `${expectedLines.join('\n')}\n`);
assert.strictEqual(callCount, expectedLines.length);
fi.emit('keypress', '.', { name: 'up' }); // 'bat'
@@ -968,10 +968,10 @@ for (let i = 0; i < 12; i++) {
{
const [rli, fi] = getInterface({ terminal });
let called = false;
rli.on('line', (line) => {
rli.on('line', common.mustCallAtLeast((line) => {
called = true;
assert.strictEqual(line, 'a');
});
}));
fi.emit('data', 'a');
assert.ok(!called);
fi.emit('data', '\n');
@@ -1020,10 +1020,10 @@ for (let i = 0; i < 12; i++) {
const buf = Buffer.from('☮', 'utf8');
const [rli, fi] = getInterface({ terminal });
let callCount = 0;
rli.on('line', (line) => {
rli.on('line', common.mustCallAtLeast((line) => {
callCount++;
assert.strictEqual(line, buf.toString('utf8'));
});
}));
for (const i of buf) {
fi.emit('data', Buffer.from([i]));
}
+9 -9
View File
@@ -49,9 +49,9 @@ function addTest(sequences, expectedKeys) {
// (addKeyIntervalTest(..)(noop)))()
// where noop is a terminal function(() => {}).
const addKeyIntervalTest = (sequences, expectedKeys, interval = 550,
assertDelay = 550) => {
const fn = common.mustCall((next) => () => {
function addKeyIntervalTest(sequences, expectedKeys, interval = 550,
assertDelay = 550) {
const fn = common.mustCall((next) => common.mustCall(() => {
if (!Array.isArray(sequences)) {
sequences = [ sequences ];
@@ -66,21 +66,21 @@ const addKeyIntervalTest = (sequences, expectedKeys, interval = 550,
const keys = [];
fi.on('keypress', (s, k) => keys.push(k));
const emitKeys = ([head, ...tail]) => {
const emitKeys = common.mustCallAtLeast(([head, ...tail]) => {
if (head) {
fi.write(head);
setTimeout(() => emitKeys(tail), interval);
} else {
setTimeout(() => {
setTimeout(common.mustCall(() => {
next();
assert.deepStrictEqual(keys, expectedKeys);
}, assertDelay);
}), assertDelay);
}
};
});
emitKeys(sequences);
});
}));
return fn;
};
}
// Regular alphanumerics
addTest('io.JS', [
@@ -261,10 +261,10 @@ function assertCursorRowsAndCols(rli, rows, cols) {
const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
// ['foo', 'baz', 'bar', bat'];
let callCount = 0;
rli.on('line', function(line) {
rli.on('line', common.mustCallAtLeast((line) => {
assert.strictEqual(line, expectedLines[callCount]);
callCount++;
});
}));
fi.emit('data', `${expectedLines.join('\n')}\n`);
assert.strictEqual(callCount, expectedLines.length);
fi.emit('keypress', '.', { name: 'up' }); // 'bat'
@@ -337,10 +337,10 @@ function assertCursorRowsAndCols(rli, rows, cols) {
});
const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
let callCount = 0;
rli.on('line', function(line) {
rli.on('line', common.mustCallAtLeast((line) => {
assert.strictEqual(line, expectedLines[callCount]);
callCount++;
});
}));
fi.emit('data', `${expectedLines.join('\n')}\n`);
assert.strictEqual(callCount, expectedLines.length);
fi.emit('keypress', '.', { name: 'up' }); // 'bat'
@@ -840,10 +840,10 @@ for (let i = 0; i < 12; i++) {
{
const [rli, fi] = getInterface({ terminal });
let called = false;
rli.on('line', (line) => {
rli.on('line', common.mustCallAtLeast((line) => {
called = true;
assert.strictEqual(line, 'a');
});
}));
fi.emit('data', 'a');
assert.ok(!called);
fi.emit('data', '\n');
@@ -892,10 +892,10 @@ for (let i = 0; i < 12; i++) {
const buf = Buffer.from('☮', 'utf8');
const [rli, fi] = getInterface({ terminal });
let callCount = 0;
rli.on('line', function(line) {
rli.on('line', common.mustCallAtLeast((line) => {
callCount++;
assert.strictEqual(line, buf.toString('utf8'));
});
}));
for (const i of buf) {
fi.emit('data', Buffer.from([i]));
}
@@ -75,10 +75,10 @@ if (process.env.TERM === 'dumb') {
rli.on('line', common.mustNotCall());
for (const character of `${char}\t\t`) {
fi.emit('data', character);
queueMicrotask(() => {
queueMicrotask(common.mustCall(() => {
assert.strictEqual(output, expectations.shift());
output = '';
});
}));
}
fi.end();
});
@@ -110,9 +110,9 @@ if (process.env.TERM === 'dumb') {
rli.on('line', common.mustNotCall());
fi.emit('data', '\t');
queueMicrotask(() => {
queueMicrotask(common.mustCall(() => {
assert.match(output, /^Tab completion error: Error: message/);
output = '';
});
}));
fi.end();
}
+3 -3
View File
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const readline = require('readline');
const Stream = require('stream');
@@ -31,10 +31,10 @@ let rawModeCalled = false;
let resumeCalled = false;
let pauseCalled = false;
stream.setRawMode = function(mode) {
stream.setRawMode = common.mustCallAtLeast(function(mode) {
rawModeCalled = true;
assert.strictEqual(mode, expectedRawMode);
};
});
stream.resume = function() {
resumeCalled = true;
};
+6 -6
View File
@@ -96,10 +96,10 @@ if (process.env.TERM === 'dumb') {
rli.on('line', common.mustNotCall());
fi.emit('data', '\t');
queueMicrotask(() => {
queueMicrotask(common.mustCall(() => {
assert.match(output, /^Tab completion error: Error: message/);
output = '';
});
}));
rli.close();
}
@@ -129,12 +129,12 @@ if (process.env.TERM === 'dumb') {
rli.on('line', common.mustNotCall());
fi.emit('data', 'input');
queueMicrotask(() => {
queueMicrotask(common.mustCall(() => {
fi.emit('data', '\t');
queueMicrotask(() => {
queueMicrotask(common.mustCall(() => {
assert.match(output, /> Input/);
output = '';
rli.close();
});
});
}));
}));
}
+2 -2
View File
@@ -7,12 +7,12 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');
const getDefine = (text, name) => {
const getDefine = common.mustCallAtLeast((text, name) => {
const regexp = new RegExp(`#define\\s+${RegExp.escape(name)}\\s+(.*)`);
const match = regexp.exec(text);
assert.notStrictEqual(match, null);
return match[1];
};
});
const srcRoot = path.join(__dirname, '..', '..');
const mainChangelogFile = path.join(srcRoot, 'CHANGELOG.md');
+6 -6
View File
@@ -152,7 +152,7 @@ function runTest() {
REPL.createInternalRepl(opts.env, {
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
write: common.mustCallAtLeast((chunk, _, next) => {
const output = chunk.toString();
if (!opts.showEscapeCodes &&
@@ -177,7 +177,7 @@ function runTest() {
}
next();
}
}),
}),
allowBlockingCompletions: true,
completer: opts.completer,
@@ -185,13 +185,13 @@ function runTest() {
useColors: false,
preview: opts.preview,
terminal: true
}, function(err, repl) {
}, common.mustCall((err, repl) => {
if (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}
repl.once('close', () => {
repl.once('close', common.mustCall(() => {
if (opts.clean)
cleanupTmpFile();
@@ -203,7 +203,7 @@ function runTest() {
}
setImmediate(runTestWrap, true);
});
}));
if (opts.columns) {
Object.defineProperty(repl, 'columns', {
@@ -212,7 +212,7 @@ function runTest() {
});
}
repl.input.run(opts.test);
});
}));
}
// run the tests
+4 -4
View File
@@ -33,7 +33,7 @@ test1();
function test1() {
let gotWrite = false;
putIn.write = function(data) {
putIn.write = common.mustCall(function(data) {
gotWrite = true;
if (data.length) {
@@ -44,7 +44,7 @@ function test1() {
assert.strictEqual(globalThis.fs, require('fs'));
test2();
}
};
});
assert(!gotWrite);
putIn.run(['fs']);
assert(gotWrite);
@@ -52,7 +52,7 @@ function test1() {
function test2() {
let gotWrite = false;
putIn.write = function(data) {
putIn.write = common.mustCallAtLeast(function(data) {
gotWrite = true;
if (data.length) {
// REPL response error message
@@ -60,7 +60,7 @@ function test2() {
// Original value wasn't overwritten
assert.strictEqual(val, globalThis.url);
}
};
});
const val = {};
globalThis.url = val;
common.allowGlobals(val);
+6 -6
View File
@@ -2,7 +2,7 @@
require('../common');
const { Duplex } = require('stream');
const { inspect } = require('util');
const { strictEqual } = require('assert');
const assert = require('assert');
const { REPLServer } = require('repl');
let output = '';
@@ -25,9 +25,9 @@ process.on('exit', function() {
// https://github.com/nodejs/node/pull/16485#issuecomment-350428638
// The color setting of the REPL should not have leaked over into
// the color setting of `util.inspect.defaultOptions`.
strictEqual(output.includes(`"'string'"`), true);
strictEqual(output.includes(`'\u001b[32m\\'string\\'\u001b[39m'`), false);
strictEqual(inspect.defaultOptions.colors, false);
strictEqual(repl.writer.options.colors, true);
strictEqual(repl2.writer.options.colors, true);
assert.strictEqual(output.includes(`"'string'"`), true);
assert.strictEqual(output.includes(`'\u001b[32m\\'string\\'\u001b[39m'`), false);
assert.strictEqual(inspect.defaultOptions.colors, false);
assert.strictEqual(repl.writer.options.colors, true);
assert.strictEqual(repl2.writer.options.colors, true);
});
+2 -2
View File
@@ -14,7 +14,7 @@ setTimeout(() => {
child.stdin.write('\nimport("fs");\n');
child.stdin.write('\nprocess.exit(0);\n');
}, common.platformTimeout(50));
child.on('exit', (code, signal) => {
child.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
}));
+3 -5
View File
@@ -2,7 +2,7 @@
// Flags: --expose-internals
require('../common');
const common = require('../common');
const stream = require('stream');
const { describe, test } = require('node:test');
const REPL = require('internal/repl');
@@ -66,9 +66,7 @@ function run(test) {
Object.assign(process.env, env);
return new Promise((resolve) => {
REPL.createInternalRepl(process.env, opts, function(err, repl) {
assert.ifError(err);
REPL.createInternalRepl(process.env, opts, common.mustSucceed((repl) => {
assert.strictEqual(repl.terminal, expected.terminal,
`Expected ${inspect(expected)} with ${inspect(env)}`);
assert.strictEqual(repl.useColors, expected.useColors,
@@ -80,7 +78,7 @@ function run(test) {
}
repl.close();
resolve();
});
}));
});
}
+3 -3
View File
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
@@ -42,9 +42,9 @@ let out = '';
child.stdout.on('data', (d) => {
out += d;
});
child.stdout.on('end', () => {
child.stdout.on('end', common.mustCall(() => {
assert.match(out, expectOut);
console.log('ok');
});
}));
child.stdin.end(input);
@@ -867,7 +867,7 @@ function runTest() {
REPL.createInternalRepl(opts.env, {
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
write: common.mustCallAtLeast((chunk, _, next) => {
const output = chunk.toString();
if (!opts.showEscapeCodes &&
@@ -892,20 +892,20 @@ function runTest() {
}
next();
}
}),
}),
completer: opts.completer,
prompt,
useColors: false,
preview: opts.preview,
terminal: true
}, function(err, repl) {
}, common.mustCall((err, repl) => {
if (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}
repl.once('close', () => {
repl.once('close', common.mustCall(() => {
if (opts.clean)
cleanupTmpFile();
@@ -917,7 +917,7 @@ function runTest() {
}
setImmediate(runTestWrap, true);
});
}));
if (opts.columns) {
Object.defineProperty(repl, 'columns', {
@@ -926,7 +926,7 @@ function runTest() {
});
}
repl.input.run(opts.test);
});
}));
}
// run the tests
+3 -3
View File
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const { startNewREPLServer } = require('../common/repl');
@@ -8,6 +8,6 @@ const { replServer, output } = startNewREPLServer();
replServer.emit('line', 'process.nextTick(() => { throw null; })');
replServer.emit('line', '.exit');
setTimeout(() => {
setTimeout(common.mustCall(() => {
assert(output.accumulator.includes('Uncaught null'));
}, 0);
}), 0);
+6 -6
View File
@@ -78,7 +78,7 @@ function runTest() {
REPL.createInternalRepl(opts.env, {
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
write: common.mustCallAtLeast((chunk, _, next) => {
const output = chunk.toString();
if (!opts.showEscapeCodes &&
@@ -103,7 +103,7 @@ function runTest() {
}
next();
}
}),
}),
allowBlockingCompletions: true,
completer: opts.completer,
@@ -111,13 +111,13 @@ function runTest() {
useColors: false,
preview: opts.preview,
terminal: true
}, function(err, repl) {
}, common.mustCall((err, repl) => {
if (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}
repl.once('close', () => {
repl.once('close', common.mustCall(() => {
if (opts.checkTotal) {
assert.deepStrictEqual(lastChunks, expected);
@@ -127,10 +127,10 @@ function runTest() {
}
setImmediate(runTestWrap, true);
});
}));
repl.input.run(opts.test);
});
}));
}
// run the tests
+9 -11
View File
@@ -137,14 +137,12 @@ const tests = [
expected: [prompt, replFailedRead, prompt, replDisabled, prompt]
},
{
before: function before() {
before: common.mustCall(function before() {
if (common.isWindows) {
const execSync = require('child_process').execSync;
execSync(`ATTRIB +H "${emptyHiddenHistoryPath}"`, (err) => {
assert.ifError(err);
});
execSync(`ATTRIB +H "${emptyHiddenHistoryPath}"`);
}
},
}),
env: { NODE_REPL_HISTORY: emptyHiddenHistoryPath },
test: [UP],
expected: [prompt]
@@ -216,7 +214,7 @@ function runTest(assertCleaned) {
REPL.createInternalRepl(env, {
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
write: common.mustCallAtLeast((chunk, _, next) => {
const output = chunk.toString();
// Ignore escapes and blank lines
@@ -230,12 +228,12 @@ function runTest(assertCleaned) {
throw err;
}
next();
}
}),
}),
prompt,
useColors: false,
terminal: true
}, function(err, repl) {
}, common.mustCall((err, repl) => {
if (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
@@ -250,7 +248,7 @@ function runTest(assertCleaned) {
onClose();
});
function onClose() {
const onClose = common.mustCall(() => {
const cleaned = clean === false ? false : cleanupTmpFile();
try {
@@ -261,8 +259,8 @@ function runTest(assertCleaned) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}
}
});
repl.inputStream.run(test);
});
}));
}
@@ -138,14 +138,12 @@ const tests = [
},
// Checking the history file permissions
{
before: function before() {
before: common.mustCall(function before() {
if (common.isWindows) {
const execSync = require('child_process').execSync;
execSync(`ATTRIB +H "${emptyHiddenHistoryPath}"`, (err) => {
assert.ifError(err);
});
execSync(`ATTRIB +H "${emptyHiddenHistoryPath}"`);
}
},
}),
env: { NODE_REPL_HISTORY: emptyHiddenHistoryPath },
test: [UP],
expected: [prompt]
@@ -220,7 +218,7 @@ function runTest(assertCleaned) {
const repl = REPL.start({
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
write: common.mustCallAtLeast((chunk, _, next) => {
const output = chunk.toString();
// Ignore escapes and blank lines
@@ -234,7 +232,7 @@ function runTest(assertCleaned) {
throw err;
}
next();
}
}),
}),
prompt: prompt,
useColors: false,
@@ -131,14 +131,12 @@ const tests = [
expected: [prompt, replFailedRead, prompt, replDisabled, prompt]
},
{
before: function before() {
before: common.mustCall(function before() {
if (common.isWindows) {
const execSync = require('child_process').execSync;
execSync(`ATTRIB +H "${emptyHiddenHistoryPath}"`, (err) => {
assert.ifError(err);
});
execSync(`ATTRIB +H "${emptyHiddenHistoryPath}"`);
}
},
}),
env: { NODE_REPL_HISTORY: emptyHiddenHistoryPath },
test: [UP],
expected: [prompt]
@@ -211,7 +209,7 @@ function runTest(assertCleaned) {
const repl = REPL.start({
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
write: common.mustCallAtLeast((chunk, _, next) => {
const output = chunk.toString();
// Ignore escapes and blank lines
@@ -225,7 +223,7 @@ function runTest(assertCleaned) {
throw err;
}
next();
}
}),
}),
prompt: prompt,
useColors: false,
@@ -233,7 +231,7 @@ function runTest(assertCleaned) {
historySize
});
repl.setupHistory(file, function(err, repl) {
repl.setupHistory(file, common.mustCall((err, repl) => {
if (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
@@ -248,7 +246,7 @@ function runTest(assertCleaned) {
onClose();
});
function onClose() {
const onClose = common.mustCall(() => {
const cleaned = clean === false ? false : cleanupTmpFile();
try {
@@ -259,8 +257,8 @@ function runTest(assertCleaned) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}
}
});
repl.inputStream.run(test);
});
}));
}
+6 -6
View File
@@ -301,7 +301,7 @@ function runTest() {
REPL.createInternalRepl(opts.env, {
input: new ActionStream(),
output: new stream.Writable({
write(chunk, _, next) {
write: common.mustCallAtLeast((chunk, _, next) => {
const output = chunk.toString();
if (!opts.showEscapeCodes &&
@@ -325,19 +325,19 @@ function runTest() {
}
next();
}
}),
}),
completer: opts.completer,
prompt,
useColors: opts.useColors || false,
terminal: true
}, function(err, repl) {
}, common.mustCall((err, repl) => {
if (err) {
console.error(`Failed test # ${numtests - tests.length}`);
throw err;
}
repl.once('close', () => {
repl.once('close', common.mustCall(() => {
if (opts.clean)
cleanupTmpFile();
@@ -349,7 +349,7 @@ function runTest() {
}
setImmediate(runTestWrap, true);
});
}));
if (opts.columns) {
Object.defineProperty(repl, 'columns', {
@@ -358,7 +358,7 @@ function runTest() {
});
}
repl.inputStream.run(opts.test);
});
}));
}
// run the tests
+3 -3
View File
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const os = require('os');
@@ -41,9 +41,9 @@ child.stdout.on('data', function(d) { data += d; });
child.stdin.end(`e.setPrompt("${p}");${os.EOL}`);
child.on('close', function(code, signal) {
child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.ok(!signal);
const lines = data.split('\n');
assert.strictEqual(lines.pop(), p);
});
}));
@@ -40,7 +40,7 @@ child.stdout.once('data', common.mustCall(() => {
);
}));
child.on('close', function(code) {
child.on('close', common.mustCall((code) => {
const expected = 'Script execution was interrupted by `SIGINT`';
assert.ok(
stdout.includes(expected),
@@ -50,4 +50,4 @@ child.on('close', function(code) {
stdout.includes('foobar'),
`Expected stdout to contain "foobar", got ${stdout}`
);
});
}));
+2 -2
View File
@@ -39,7 +39,7 @@ child.stdout.once('data', common.mustCall(() => {
'while(true){}\n');
}));
child.on('close', function(code) {
child.on('close', common.mustCall((code) => {
assert.strictEqual(code, 0);
const expected = 'Script execution was interrupted by `SIGINT`';
assert.ok(
@@ -50,4 +50,4 @@ child.on('close', function(code) {
stdout.includes('42042\n'),
`Expected stdout to contain "42042", got ${stdout}`
);
});
}));
@@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
switch (process.argv[2]) {
@@ -47,15 +47,15 @@ function parent() {
child.stdout.on('data', function(c) {
out += c;
});
child.stdout.on('end', function() {
child.stdout.on('end', common.mustCall(() => {
assert.strictEqual(out, '10\n');
console.log('ok - got expected output');
});
}));
child.on('exit', function(c) {
child.on('exit', common.mustCall((c) => {
assert(!c);
console.log('ok - exit success');
});
}));
}
function child() {
@@ -48,10 +48,10 @@ for (const type of [
assert.strictEqual(data[0].includes('ele.biu'), true);
data[0].forEach((key) => {
for (const key of data[0]) {
if (!key || key === 'ele.biu') return;
assert.notStrictEqual(ele[key.slice(4)], undefined);
});
}
})
);
}
@@ -56,9 +56,9 @@ replServer.complete("import\t( 'n", common.mustSucceed((data) => {
assert.strictEqual(completions[lastIndex + 2], 'net');
assert.strictEqual(completions[lastIndex + 3], '');
// It's possible to pick up non-core modules too
completions.slice(lastIndex + 4).forEach((completion) => {
for (const completion of completions.slice(lastIndex + 4)) {
assert.match(completion, /^n/);
});
}
}));
{
@@ -62,20 +62,18 @@ const { startNewREPLServer } = require('../common/repl');
// require(...) completions include `node:`-prefixed modules:
let lastIndex = -1;
publicModules
.filter((lib) => !lib.startsWith('node:'))
.forEach((lib, index) => {
lastIndex = data[0].indexOf(`node:${lib}`);
assert.notStrictEqual(lastIndex, -1);
});
for (const lib of publicModules.filter((lib) => !lib.startsWith('node:'))) {
lastIndex = data[0].indexOf(`node:${lib}`);
assert.notStrictEqual(lastIndex, -1);
}
assert.strictEqual(data[0][lastIndex + 1], '');
// There is only one Node.js module that starts with n:
assert.strictEqual(data[0][lastIndex + 2], 'net');
assert.strictEqual(data[0][lastIndex + 3], '');
// It's possible to pick up non-core modules too
data[0].slice(lastIndex + 4).forEach((completion) => {
for (const completion of data[0].slice(lastIndex + 4)) {
assert.match(completion, /^n/);
});
}
})
);
}
+1 -4
View File
@@ -1,6 +1,5 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
const zlib = require('zlib');
@@ -13,6 +12,4 @@ const testMe = repl.start('', putIn, function(cmd, context, filename,
testMe._domain.on('error', common.mustNotCall());
testMe.complete('', function(err, results) {
assert.strictEqual(err, null);
});
testMe.complete('', common.mustSucceed());
@@ -4,7 +4,7 @@
// does not suppress errors in the whole application. Adding such listener
// should throw.
require('../common');
const common = require('../common');
const assert = require('assert');
const { startNewREPLServer } = require('../common/repl');
@@ -32,10 +32,10 @@ replServer.write(
'}, 1);console.log()\n'
);
setTimeout(() => {
setTimeout(common.mustCall(() => {
replServer.close();
const len = process.listenerCount('uncaughtException');
process.removeAllListeners('uncaughtException');
assert.strictEqual(len, 0);
assert.match(output.accumulator, /ERR_INVALID_REPL_INPUT.*(?!Type)RangeError: abc/s);
}, 2);
}), 2);
+3 -3
View File
@@ -1,6 +1,6 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const repl = require('repl');
const { startNewREPLServer } = require('../common/repl');
@@ -152,7 +152,7 @@ function testError() {
// throws error, async
`);
setImmediate(() => {
setImmediate(common.mustCall(() => {
const lines = output.accumulator.trim().split('\n').filter(
(line) => !line.includes(testingReplPrompt) || line.includes('Uncaught Error')
);
@@ -205,7 +205,7 @@ function testError() {
'Uncaught Error: quux',
'0',
]);
});
}));
}
function assertOutput(output, expected) {
@@ -2,7 +2,7 @@
// This is a regression test for https://github.com/joyent/node/issues/8874.
require('../common');
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
@@ -25,9 +25,9 @@ child.stdout.on('data', (d) => {
out += d;
});
child.stdout.on('end', () => {
child.stdout.on('end', common.mustCall(() => {
assert.match(out, expectOut);
console.log('ok');
});
}));
child.stdin.end(input);
+4 -4
View File
@@ -76,19 +76,19 @@ function test() {
// Load symlinked-script as main
const node = process.execPath;
const child = spawn(node, ['--preserve-symlinks', linkScript]);
child.on('close', function(code, signal) {
child.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert(!signal);
});
}));
// Also verify that symlinks works for setting preserve via env variables
const childEnv = spawn(node, [linkScript], {
env: { ...process.env, NODE_PRESERVE_SYMLINKS: '1' }
});
childEnv.on('close', function(code, signal) {
childEnv.on('close', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert(!signal);
});
}));
// Also verify that symlinks works for setting preserve via env variables in
// Workers.
+4 -4
View File
@@ -1,8 +1,8 @@
'use strict';
require('../common');
const { strictEqual } = require('node:assert');
const assert = require('node:assert');
const test = require('node:test');
strictEqual(test.test, test);
strictEqual(test.it, test);
strictEqual(test.describe, test.suite);
assert.strictEqual(test.test, test);
assert.strictEqual(test.it, test);
assert.strictEqual(test.describe, test.suite);
+4 -4
View File
@@ -230,7 +230,7 @@ test('coverage is combined for multiple processes', skipIfNoInspector, () => {
assert.strictEqual(result.status, 0);
});
test.skip('coverage works with isolation=none', skipIfNoInspector, () => {
test.skip('coverage works with isolation=none', skipIfNoInspector, common.mustCallAtLeast(() => {
// There is a bug in coverage calculation. The branch % in the common.js
// fixture is different depending on the test isolation mode. The 'none' mode
// is closer to what c8 reports here, so the bug is likely in the code that
@@ -270,7 +270,7 @@ test.skip('coverage works with isolation=none', skipIfNoInspector, () => {
assert.strictEqual(result.stderr.toString(), '');
assert(result.stdout.toString().includes(report));
assert.strictEqual(result.status, 0);
});
}, 0));
test('coverage reports on lines, functions, and branches', skipIfNoInspector, async (t) => {
const fixture = fixtures.path('test-runner', 'coverage.js');
@@ -290,9 +290,9 @@ test('coverage reports on lines, functions, and branches', skipIfNoInspector, as
await t.test('does not include node_modules', () => {
assert.strictEqual(coverage.summary.files.length, 3);
const files = ['coverage.js', 'invalid-tap.js', 'throw.js'];
coverage.summary.files.forEach((file, index) => {
coverage.summary.files.forEach(common.mustCallAtLeast((file, index) => {
assert.ok(file.path.endsWith(files[index]));
});
}));
});
const file = coverage.summary.files[0];
@@ -1,11 +1,11 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('node:assert');
const { test, assert: testAssertions } = require('node:test');
testAssertions.register('isOdd', (n) => {
testAssertions.register('isOdd', common.mustCallAtLeast((n) => {
assert.strictEqual(n % 2, 1);
});
}));
testAssertions.register('ok', () => {
return 'ok';
@@ -1,7 +1,7 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const { strictEqual } = require('node:assert');
const assert = require('node:assert');
const { relative } = require('node:path');
const { run } = require('node:test');
const fixture = fixtures.path('test-runner', 'index.js');
@@ -12,9 +12,9 @@ const stream = run({
});
stream.on('test:fail', common.mustCall((result) => {
strictEqual(result.name, relativePath);
strictEqual(result.details.error.failureType, 'testCodeFailure');
strictEqual(result.line, 1);
strictEqual(result.column, 1);
strictEqual(result.file, fixture);
assert.strictEqual(result.name, relativePath);
assert.strictEqual(result.details.error.failureType, 'testCodeFailure');
assert.strictEqual(result.line, 1);
assert.strictEqual(result.column, 1);
assert.strictEqual(result.file, fixture);
}));
@@ -1,6 +1,6 @@
'use strict';
require('../common');
const { match, doesNotMatch, strictEqual } = require('node:assert');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const fixtures = require('../common/fixtures');
const fixture = fixtures.path('test-runner/throws_sync_and_async.js');
@@ -15,11 +15,11 @@ for (const isolation of ['none', 'process']) {
];
const r = spawnSync(process.execPath, args);
strictEqual(r.status, 1);
strictEqual(r.signal, null);
strictEqual(r.stderr.toString(), '');
assert.strictEqual(r.status, 1);
assert.strictEqual(r.signal, null);
assert.strictEqual(r.stderr.toString(), '');
const stdout = r.stdout.toString();
match(stdout, /Error: fails/);
doesNotMatch(stdout, /this should not have a chance to be thrown/);
assert.match(stdout, /Error: fails/);
assert.doesNotMatch(stdout, /this should not have a chance to be thrown/);
}
+16 -16
View File
@@ -2,7 +2,7 @@
require('../common');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { match, strictEqual } = require('node:assert');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { readFileSync } = require('node:fs');
const { test } = require('node:test');
@@ -16,9 +16,9 @@ function runWithReporter(reporter) {
fixtures.path('test-runner', 'reporters.js'),
];
const child = spawnSync(process.execPath, args);
strictEqual(child.stdout.toString(), '');
strictEqual(child.stderr.toString(), '');
strictEqual(child.status, 1);
assert.strictEqual(child.stdout.toString(), '');
assert.strictEqual(child.stderr.toString(), '');
assert.strictEqual(child.status, 1);
return destination;
}
@@ -26,24 +26,24 @@ tmpdir.refresh();
test('junit reporter', () => {
const output = readFileSync(runWithReporter('junit'), 'utf8');
match(output, /<!-- tests 4 -->/);
match(output, /<!-- pass 2 -->/);
match(output, /<!-- fail 2 -->/);
match(output, /<!-- duration_ms/);
match(output, /<\/testsuites>/);
assert.match(output, /<!-- tests 4 -->/);
assert.match(output, /<!-- pass 2 -->/);
assert.match(output, /<!-- fail 2 -->/);
assert.match(output, /<!-- duration_ms/);
assert.match(output, /<\/testsuites>/);
});
test('spec reporter', () => {
const output = readFileSync(runWithReporter('spec'), 'utf8');
match(output, /tests 4/);
match(output, /pass 2/);
match(output, /fail 2/);
assert.match(output, /tests 4/);
assert.match(output, /pass 2/);
assert.match(output, /fail 2/);
});
test('tap reporter', () => {
const output = readFileSync(runWithReporter('tap'), 'utf8');
match(output, /# tests 4/);
match(output, /# pass 2/);
match(output, /# fail 2/);
match(output, /# duration_ms/);
assert.match(output, /# tests 4/);
assert.match(output, /# pass 2/);
assert.match(output, /# fail 2/);
assert.match(output, /# duration_ms/);
});
+2 -2
View File
@@ -25,9 +25,9 @@ if (process.argv[2] === 'child') {
// TODO(benjamingr) add more tests to describe + AbortSignal
// this just tests the parameter is passed
test.describe('Abort Signal in describe', common.mustCall(({ signal }) => {
test.it('Supports AbortSignal', () => {
test.it('Supports AbortSignal', common.mustCall(() => {
assert.strictEqual(signal.aborted, false);
});
}));
}));
} else assert.fail('unreachable');
} else {
+8 -8
View File
@@ -909,15 +909,15 @@ test('local mocks are auto restored after the test finishes', async (t) => {
assert.notStrictEqual(originalFoo, obj.foo);
assert.strictEqual(originalBar, obj.bar);
t.beforeEach(() => {
t.beforeEach(common.mustCallAtLeast(() => {
assert.strictEqual(mockFoo, obj.foo);
assert.strictEqual(originalBar, obj.bar);
});
}));
t.afterEach(() => {
t.afterEach(common.mustCallAtLeast(() => {
assert.strictEqual(mockFoo, obj.foo);
assert.notStrictEqual(originalBar, obj.bar);
});
}));
await t.test('creates mocks that are auto restored', (t) => {
const mockBar = t.mock.method(obj, 'bar');
@@ -1252,15 +1252,15 @@ test('local property mocks are auto restored after the test finishes', async (t)
assert.strictEqual(obj.foo, 888);
assert.strictEqual(obj.bar, 222);
t.beforeEach(() => {
t.beforeEach(common.mustCallAtLeast(() => {
assert.strictEqual(obj.foo, 888);
assert.strictEqual(obj.bar, 222);
});
}));
t.afterEach(() => {
t.afterEach(common.mustCallAtLeast(() => {
assert.strictEqual(obj.foo, 888);
assert.strictEqual(obj.bar, 999);
});
}));
await t.test('creates property mocks that are auto restored', (t) => {
t.mock.property(obj, 'bar', 999);
@@ -1,6 +1,6 @@
import { allowGlobals, mustCall } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { deepStrictEqual } from 'node:assert';
import assert from 'node:assert';
import { run } from 'node:test';
const stream = run({
@@ -13,7 +13,7 @@ stream.on('test:pass', mustCall(4));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
allowGlobals(globalThis.GLOBAL_ORDER);
deepStrictEqual(globalThis.GLOBAL_ORDER, [
assert.deepStrictEqual(globalThis.GLOBAL_ORDER, [
'before one: <root>',
'suite one',
'before two: <root>',
+2 -2
View File
@@ -1,6 +1,6 @@
import { allowGlobals, mustCall, mustNotCall } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { deepStrictEqual } from 'node:assert';
import assert from 'node:assert';
import { run } from 'node:test';
const stream = run({
@@ -16,7 +16,7 @@ stream.on('test:pass', mustCall(4));
// eslint-disable-next-line no-unused-vars
for await (const _ of stream);
allowGlobals(globalThis.GLOBAL_ORDER);
deepStrictEqual(globalThis.GLOBAL_ORDER, [
assert.deepStrictEqual(globalThis.GLOBAL_ORDER, [
'before one: <root>',
'suite one',
'before two: <root>',
+7 -7
View File
@@ -1,7 +1,7 @@
'use strict';
const { spawnPromisified } = require('../common');
const fixtures = require('../common/fixtures');
const { strictEqual } = require('node:assert');
const assert = require('node:assert');
const { test } = require('node:test');
test('root duration is longer than test duration', async () => {
@@ -14,13 +14,13 @@ test('root duration is longer than test duration', async () => {
fixtures.path('test-runner/root-duration.mjs'),
]);
strictEqual(code, 0);
strictEqual(stderr, '');
assert.strictEqual(code, 0);
assert.strictEqual(stderr, '');
const durations = [...stdout.matchAll(/duration_ms:? ([.\d]+)/g)];
strictEqual(durations.length, 2);
assert.strictEqual(durations.length, 2);
const testDuration = Number.parseFloat(durations[0][1]);
const rootDuration = Number.parseFloat(durations[1][1]);
strictEqual(Number.isNaN(testDuration), false);
strictEqual(Number.isNaN(rootDuration), false);
strictEqual(rootDuration >= testDuration, true);
assert.strictEqual(Number.isNaN(testDuration), false);
assert.strictEqual(Number.isNaN(rootDuration), false);
assert.strictEqual(rootDuration >= testDuration, true);
});
@@ -1,4 +1,4 @@
import '../common/index.mjs';
import { mustCall, mustCallAtLeast } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { describe, it, beforeEach, run } from 'node:test';
import assert from 'node:assert';
@@ -13,17 +13,17 @@ const onlyWithAmaro = { skip: !process.config.variables.node_use_amaro };
const testFixtures = fixtures.path('test-runner', 'global-setup-teardown');
const runnerFixture = fixtures.path('test-runner', 'test-runner-global-hooks.mjs');
describe('require(\'node:test\').run with global hooks', { concurrency: false }, () => {
describe('require(\'node:test\').run with global hooks', { concurrency: false }, mustCall(() => {
beforeEach(() => {
tmpdir.refresh();
});
async function runTestWithGlobalHooks({
const runTestWithGlobalHooks = mustCallAtLeast(async ({
globalSetupFile,
testFile = 'test-file.js',
runnerEnv = {},
isolation = 'process'
}) {
}) => {
const testFilePath = path.join(testFixtures, testFile);
const globalSetupPath = path.join(testFixtures, globalSetupFile);
@@ -59,7 +59,7 @@ describe('require(\'node:test\').run with global hooks', { concurrency: false },
await once(child, 'exit');
// Assert in order to print a detailed error message if the test fails
assert.partialDeepStrictEqual(stderr, '');
assert.strictEqual(stderr, '');
assert.match(stdout, /pass (\d+)/);
assert.match(stdout, /fail (\d+)/);
@@ -69,7 +69,7 @@ describe('require(\'node:test\').run with global hooks', { concurrency: false },
};
return { results };
}
});
for (const isolation of ['none', 'process']) {
describe(`with isolation : ${isolation}`, () => {
@@ -226,4 +226,4 @@ describe('require(\'node:test\').run with global hooks', { concurrency: false },
});
});
});
});
}));
@@ -1,15 +1,15 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const { deepStrictEqual, throws } = require('node:assert');
const assert = require('node:assert');
const { convertStringToRegExp } = require('internal/test_runner/utils');
deepStrictEqual(convertStringToRegExp('foo', 'x'), /foo/);
deepStrictEqual(convertStringToRegExp('/bar/', 'x'), /bar/);
deepStrictEqual(convertStringToRegExp('/baz/gi', 'x'), /baz/gi);
deepStrictEqual(convertStringToRegExp('/foo/9', 'x'), /\/foo\/9/);
assert.deepStrictEqual(convertStringToRegExp('foo', 'x'), /foo/);
assert.deepStrictEqual(convertStringToRegExp('/bar/', 'x'), /bar/);
assert.deepStrictEqual(convertStringToRegExp('/baz/gi', 'x'), /baz/gi);
assert.deepStrictEqual(convertStringToRegExp('/foo/9', 'x'), /\/foo\/9/);
throws(
assert.throws(
() => convertStringToRegExp('/foo/abcdefghijk', 'x'),
common.expectsError({
code: 'ERR_INVALID_ARG_VALUE',
+9 -9
View File
@@ -1,30 +1,30 @@
'use strict';
require('../common');
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { strictEqual } = require('node:assert');
const assert = require('node:assert');
const { writeFileSync } = require('node:fs');
const { suite, test } = require('node:test');
tmpdir.refresh();
suite('suite', (t) => {
strictEqual(t.filePath, __filename);
suite('suite', common.mustCall((t) => {
assert.strictEqual(t.filePath, __filename);
test('test', (t) => {
strictEqual(t.filePath, __filename);
assert.strictEqual(t.filePath, __filename);
t.test('subtest', (t) => {
strictEqual(t.filePath, __filename);
assert.strictEqual(t.filePath, __filename);
t.test('subsubtest', (t) => {
strictEqual(t.filePath, __filename);
assert.strictEqual(t.filePath, __filename);
});
});
});
});
}));
test((t) => {
strictEqual(t.filePath, __filename);
assert.strictEqual(t.filePath, __filename);
});
const importedTestFile = tmpdir.resolve('temp.js');
+12 -12
View File
@@ -1,28 +1,28 @@
'use strict';
require('../common');
const { strictEqual } = require('node:assert');
const common = require('../common');
const assert = require('node:assert');
const { before, suite, test } = require('node:test');
before((t) => {
strictEqual(t.fullName, '<root>');
});
before(common.mustCall((t) => {
assert.strictEqual(t.fullName, '<root>');
}));
suite('suite', (t) => {
strictEqual(t.fullName, 'suite');
suite('suite', common.mustCall((t) => {
assert.strictEqual(t.fullName, 'suite');
test('test', (t) => {
strictEqual(t.fullName, 'suite > test');
assert.strictEqual(t.fullName, 'suite > test');
t.test('subtest', (t) => {
strictEqual(t.fullName, 'suite > test > subtest');
assert.strictEqual(t.fullName, 'suite > test > subtest');
t.test('subsubtest', (t) => {
strictEqual(t.fullName, 'suite > test > subtest > subsubtest');
assert.strictEqual(t.fullName, 'suite > test > subtest > subsubtest');
});
});
});
});
}));
test((t) => {
strictEqual(t.fullName, '<anonymous>');
assert.strictEqual(t.fullName, '<anonymous>');
});
+3 -3
View File
@@ -1,6 +1,6 @@
'use strict';
const common = require('../common');
const { strictEqual } = require('node:assert');
const assert = require('node:assert');
const { run, suite, test } = require('node:test');
if (!process.env.NODE_TEST_CONTEXT) {
@@ -8,8 +8,8 @@ if (!process.env.NODE_TEST_CONTEXT) {
stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall((event) => {
strictEqual(event.skip, true);
strictEqual(event.todo, undefined);
assert.strictEqual(event.skip, true);
assert.strictEqual(event.todo, undefined);
}, 4));
} else {
test('test options only', { skip: true, todo: true }, common.mustNotCall());
@@ -1,6 +1,6 @@
// Flags: --expose-internals --no-warnings
import '../common/index.mjs';
import * as common from '../common/index.mjs';
import { describe, it, beforeEach } from 'node:test';
import assert from 'node:assert';
import { finished } from 'node:stream/promises';
@@ -21,10 +21,10 @@ const defaultSerializer = new DefaultSerializer();
defaultSerializer.writeHeader();
const headerLength = defaultSerializer.releaseBuffer().length;
describe('v8 deserializer', () => {
describe('v8 deserializer', common.mustCall(() => {
let fileTest;
let reported;
beforeEach(() => {
beforeEach(common.mustCallAtLeast(() => {
reported = [];
fileTest = new runner.FileTest({
name: 'filetest',
@@ -32,7 +32,7 @@ describe('v8 deserializer', () => {
});
fileTest.reporter.on('data', (data) => reported.push(data));
assert(fileTest.isClearToSend());
});
}));
async function collectReported(chunks) {
chunks.forEach((chunk) => fileTest.parseMessage(chunk));
@@ -103,4 +103,4 @@ describe('v8 deserializer', () => {
);
}
});
}));