diff --git a/test/abort/test-addon-uv-handle-leak.js b/test/abort/test-addon-uv-handle-leak.js index c9614e11734e96..e494b12f2de558 100644 --- a/test/abort/test-addon-uv-handle-leak.js +++ b/test/abort/test-addon-uv-handle-leak.js @@ -90,7 +90,7 @@ if (process.argv[2] === 'child') { switch (state) { case 'initial': - assert(/^uv loop at \[.+\] has open handles:$/.test(line), line); + assert.match(line, /^uv loop at \[.+\] has open handles:$/); state = 'handle-start'; break; case 'handle-start': @@ -98,15 +98,15 @@ if (process.argv[2] === 'child') { state = 'assertion-failure'; break; } - assert(/^\[.+\] timer( \(active\))?$/.test(line), line); + assert.match(line, /^\[.+\] timer( \(active\))?$/); state = 'close-callback'; break; case 'close-callback': - assert(/^Close callback:/.test(line), line); + assert.match(line, /^Close callback:/); state = 'data'; break; case 'data': - assert(/^Data: .+$/.test(line), line); + assert.match(line, /^Data: .+$/); state = 'maybe-first-field'; break; case 'maybe-first-field': @@ -116,7 +116,7 @@ if (process.argv[2] === 'child') { state = 'handle-start'; break; case 'assertion-failure': - assert(/Assertion .+ failed/.test(line), line); + assert.match(line, /Assertion .+ failed/); state = 'done'; break; case 'done': diff --git a/test/addons/errno-exception/test.js b/test/addons/errno-exception/test.js index ddc13b7ce57ae2..4afbb40044ac8a 100644 --- a/test/addons/errno-exception/test.js +++ b/test/addons/errno-exception/test.js @@ -12,4 +12,4 @@ const err = binding.errno(); assert.strictEqual(err.syscall, 'syscall'); assert.strictEqual(err.errno, 10); assert.strictEqual(err.path, 'päth'); -assert.ok(/^Error:\s\w+, some error msg 'päth'$/.test(err.toString())); +assert.match(err.toString(), /^Error:\s\w+, some error msg 'päth'$/); diff --git a/test/async-hooks/test-emit-after-on-destroyed.js b/test/async-hooks/test-emit-after-on-destroyed.js index b015dacddba506..37c54b1c9e0a20 100644 --- a/test/async-hooks/test-emit-after-on-destroyed.js +++ b/test/async-hooks/test-emit-after-on-destroyed.js @@ -54,11 +54,11 @@ if (process.argv[2] === 'child') { child.on('close', common.mustCall((code) => { assert.strictEqual(code, 1); - assert.ok(heartbeatMsg.test(outData.toString()), - 'did not crash until we reached offending line of code ' + - `(found ${outData})`); - assert.ok(corruptedMsg.test(errData.toString()), - 'printed error contains corrupted message ' + - `(found ${errData})`); + assert.match(outData.toString(), heartbeatMsg, + 'did not crash until we reached offending line of code ' + + `(found ${outData})`); + assert.match(errData.toString(), corruptedMsg, + 'printed error contains corrupted message ' + + `(found ${errData})`); })); } diff --git a/test/async-hooks/test-emit-before-on-destroyed.js b/test/async-hooks/test-emit-before-on-destroyed.js index 36a50a050f9324..7b56eeeb63d4d2 100644 --- a/test/async-hooks/test-emit-before-on-destroyed.js +++ b/test/async-hooks/test-emit-before-on-destroyed.js @@ -54,11 +54,11 @@ if (process.argv[2] === 'child') { child.on('close', common.mustCall((code) => { assert.strictEqual(code, 1); - assert.ok(heartbeatMsg.test(outData.toString()), - 'did not crash until we reached offending line of code ' + - `(found ${outData})`); - assert.ok(corruptedMsg.test(errData.toString()), - 'printed error contains corrupted message ' + - `(found ${errData})`); + assert.match(outData.toString(), heartbeatMsg, + 'did not crash until we reached offending line of code ' + + `(found ${outData})`); + assert.match(errData.toString(), corruptedMsg, + 'printed error contains corrupted message ' + + `(found ${errData})`); })); } diff --git a/test/async-hooks/test-improper-order.js b/test/async-hooks/test-improper-order.js index a9d46917df59e0..800c7422b42e31 100644 --- a/test/async-hooks/test-improper-order.js +++ b/test/async-hooks/test-improper-order.js @@ -53,11 +53,11 @@ if (process.argv[2] === 'child') { child.on('close', common.mustCall((code) => { assert.strictEqual(code, 1); - assert.ok(heartbeatMsg.test(outData.toString()), - 'did not crash until we reached offending line of code ' + - `(found ${outData})`); - assert.ok(corruptedMsg.test(errData.toString()), - 'printed error contains corrupted message ' + - `(found ${errData})`); + assert.match(outData.toString(), heartbeatMsg, + 'did not crash until we reached offending line of code ' + + `(found ${outData})`); + assert.match(errData.toString(), corruptedMsg, + 'printed error contains corrupted message ' + + `(found ${errData})`); })); } diff --git a/test/async-hooks/test-improper-unwind.js b/test/async-hooks/test-improper-unwind.js index a62512db974ac6..f2fbef2dbcc469 100644 --- a/test/async-hooks/test-improper-unwind.js +++ b/test/async-hooks/test-improper-unwind.js @@ -57,11 +57,11 @@ if (process.argv[2] === 'child') { child.on('close', common.mustCall((code) => { assert.strictEqual(code, 1); - assert.ok(heartbeatMsg.test(outData.toString()), - 'did not crash until we reached offending line of code ' + - `(found ${outData})`); - assert.ok(corruptedMsg.test(errData.toString()), - 'printed error contains corrupted message ' + - `(found ${errData})`); + assert.match(outData.toString(), heartbeatMsg, + 'did not crash until we reached offending line of code ' + + `(found ${outData})`); + assert.match(errData.toString(), corruptedMsg, + 'printed error contains corrupted message ' + + `(found ${errData})`); })); } diff --git a/test/common/index.js b/test/common/index.js index 2ac4538cbea804..36873eb96f89b4 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -547,7 +547,7 @@ function _expectWarning(name, expected, code) { if (typeof message === 'string') { assert.strictEqual(warning.message, message); } else { - assert(message.test(warning.message)); + assert.match(warning.message, message); } assert.strictEqual(warning.code, code); }, expected.length); diff --git a/test/common/report.js b/test/common/report.js index b1d6b058172590..79d6e97b0f42d2 100644 --- a/test/common/report.js +++ b/test/common/report.js @@ -146,7 +146,7 @@ function _validateContent(report, fields = []) { header.networkInterfaces.forEach((iface) => { assert.strictEqual(typeof iface.name, 'string'); assert.strictEqual(typeof iface.internal, 'boolean'); - assert(/^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i.test(iface.mac)); + assert.match(iface.mac, /^([0-9A-F][0-9A-F]:){5}[0-9A-F]{2}$/i); if (iface.family === 'IPv4') { assert.strictEqual(net.isIPv4(iface.address), true); @@ -171,7 +171,7 @@ function _validateContent(report, fields = []) { assert(typeof frame === 'object' && frame !== null); checkForUnknownFields(frame, ['pc', 'symbol']); assert.strictEqual(typeof frame.pc, 'string'); - assert(/^0x[0-9a-f]+$/.test(frame.pc)); + assert.match(frame.pc, /^0x[0-9a-f]+$/); assert.strictEqual(typeof frame.symbol, 'string'); }); @@ -250,7 +250,7 @@ function _validateContent(report, fields = []) { report.libuv.forEach((resource) => { assert.strictEqual(typeof resource.type, 'string'); assert.strictEqual(typeof resource.address, 'string'); - assert(/^0x[0-9a-f]+$/.test(resource.address)); + assert.match(resource.address, /^0x[0-9a-f]+$/); assert.strictEqual(typeof resource.is_active, 'boolean'); assert.strictEqual(typeof resource.is_referenced, resource.type === 'loop' ? 'undefined' : 'boolean'); diff --git a/test/internet/test-dns-ipv6.js b/test/internet/test-dns-ipv6.js index 6f499b68947322..7d2c18985e2167 100644 --- a/test/internet/test-dns-ipv6.js +++ b/test/internet/test-dns-ipv6.js @@ -142,7 +142,7 @@ TEST(function test_lookup_ipv6_hint(done) { assert(err instanceof Error); assert.strictEqual(err.code, 'EAI_BADFLAGS'); assert.strictEqual(err.hostname, addresses.INET_HOST); - assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message)); + assert.match(err.message, /getaddrinfo EAI_BADFLAGS/); done(); return; } diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 363dc92446a5ef..75f3e04c7cdd20 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -527,7 +527,7 @@ TEST(function test_lookup_failure(done) { assert.ok(err instanceof Error); assert.strictEqual(err.code, dns.NOTFOUND); assert.strictEqual(err.code, 'ENOTFOUND'); - assert.ok(!/ENOENT/.test(err.message)); + assert.doesNotMatch(err.message, !/ENOENT/); assert.ok(err.message.includes(addresses.NOT_FOUND)); done(); @@ -640,7 +640,7 @@ TEST(function test_lookupservice_invalid(done) { const req = dns.lookupService('1.2.3.4', 80, (err) => { assert(err instanceof Error); assert.strictEqual(err.code, 'ENOTFOUND'); - assert.ok(/1\.2\.3\.4/.test(err.message)); + assert.match(err.message, /1\.2\.3\.4/); done(); }); @@ -662,7 +662,7 @@ TEST(function test_reverse_failure(done) { assert(err instanceof Error); assert.strictEqual(err.code, 'ENOTFOUND'); // Silly error code... assert.strictEqual(err.hostname, '203.0.113.0'); - assert.ok(/203\.0\.113\.0/.test(err.message)); + assert.match(err.message, /203\.0\.113\.0/); done(); }); diff --git a/test/internet/test-inspector-help-page.js b/test/internet/test-inspector-help-page.js index a6a38bd0265e78..7baff031daf86c 100644 --- a/test/internet/test-inspector-help-page.js +++ b/test/internet/test-inspector-help-page.js @@ -28,7 +28,7 @@ function check(url, cb) { }); res.on('end', common.mustCall(() => { - assert(/>Debugging GuideDebugging Guide$/.test(util.inspect(buf))); + assert.match(util.inspect(buf), /^$/); } diff --git a/test/parallel/test-cli-syntax-piped-bad.js b/test/parallel/test-cli-syntax-piped-bad.js index d22c21cb7e1605..4af0aa2b6df7ed 100644 --- a/test/parallel/test-cli-syntax-piped-bad.js +++ b/test/parallel/test-cli-syntax-piped-bad.js @@ -29,7 +29,7 @@ syntaxArgs.forEach(function(arg) { assert.strictEqual(c.stdout, ''); // stderr should have a syntax error message - assert(syntaxErrorRE.test(c.stderr), `${syntaxErrorRE} === ${c.stderr}`); + assert.match(c.stderr, syntaxErrorRE); assert.strictEqual(c.status, 1); }); @@ -50,7 +50,7 @@ syntaxArgs.forEach(function(arg) { assert.strictEqual(c.stdout, ''); // stderr should have a syntax error message - assert(syntaxErrorRE.test(c.stderr), `${syntaxErrorRE} === ${c.stderr}`); + assert.match(c.stderr, syntaxErrorRE); assert.strictEqual(c.status, 1); }); diff --git a/test/parallel/test-cluster-fork-windowsHide.js b/test/parallel/test-cluster-fork-windowsHide.js index 9ba809d71a318f..3eb89f208883c0 100644 --- a/test/parallel/test-cluster-fork-windowsHide.js +++ b/test/parallel/test-cluster-fork-windowsHide.js @@ -23,7 +23,7 @@ if (!process.argv[2]) { workerOnline: common.mustCall((msg) => { }), mainWindowHandle: common.mustCall((msg) => { - assert.ok(/0\s*/.test(msg.value)); + assert.match(msg.value, /0\s*/); }), workerExit: common.mustCall((msg) => { assert.strictEqual(msg.code, 0); diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index 24c4f8462eb767..1f374efbb66610 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -34,7 +34,7 @@ const { join } = require('path'); const p = fixtures.path('leakedGlobal.js'); execFile(process.execPath, [p], common.mustCall((err, stdout, stderr) => { assert.notStrictEqual(err.code, 0); - assert.ok(/\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/.test(stderr)); + assert.match(stderr, /\bAssertionError\b.*\bUnexpected global\b.*\bgc\b/); })); } @@ -130,7 +130,7 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ]; // Test `tmpdir`. { tmpdir.refresh(); - assert.ok(/\.tmp\.\d+/.test(tmpdir.path)); + assert.match(tmpdir.path, /\.tmp\.\d+/); const sentinelPath = join(tmpdir.path, 'gaga'); writeFileSync(sentinelPath, 'googoo'); tmpdir.refresh(); diff --git a/test/parallel/test-console.js b/test/parallel/test-console.js index ee2c7c82a6f8e0..85b46a7c992552 100644 --- a/test/parallel/test-console.js +++ b/test/parallel/test-console.js @@ -246,24 +246,27 @@ assert.ok(strings[0].includes('foo: { bar: { baz:')); assert.ok(strings[0].includes('quux')); assert.ok(strings.shift().includes('quux: true')); -assert.ok(/^label: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^__proto__: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^constructor: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^hasOwnProperty: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); +assert.match(strings.shift().trim(), /^label: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^__proto__: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^constructor: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^hasOwnProperty: \d+(\.\d{1,3})?(ms|s)$/); // Verify that console.time() coerces label values to strings as expected -assert.ok(/^: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^null: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^default: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^NaN: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); - -assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); -assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) test$/.test(strings.shift().trim())); -assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/.test(strings.shift().trim())); -assert.ok(/^log1: \d+(\.\d{1,3})?(ms|s)$/.test(strings.shift().trim())); +assert.match(strings.shift().trim(), /^: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), + /^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), + /^\[object Object\]: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^null: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^default: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^NaN: \d+(\.\d{1,3})?(ms|s)$/); + +assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/); +assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s) test$/); +assert.match(strings.shift().trim(), + /^log1: \d+(\.\d{1,3})?(ms|s) {} \[ 1, 2, 3 ]$/); +assert.match(strings.shift().trim(), /^log1: \d+(\.\d{1,3})?(ms|s)$/); // Make sure that we checked all strings assert.strictEqual(strings.length, 0); diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index 3392284f8d1963..fc778614cc68ed 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -105,10 +105,10 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); const { publicKey, privateKey } = ret; assert.strictEqual(typeof publicKey, 'string'); - assert(pkcs1PubExp.test(publicKey)); + assert.match(publicKey, pkcs1PubExp); assertApproximateSize(publicKey, 162); assert.strictEqual(typeof privateKey, 'string'); - assert(pkcs8Exp.test(privateKey)); + assert.match(privateKey, pkcs8Exp); assertApproximateSize(privateKey, 512); testEncryptDecrypt(publicKey, privateKey); @@ -183,7 +183,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); assertApproximateSize(publicKeyDER, 74); assert.strictEqual(typeof privateKey, 'string'); - assert(pkcs1PrivExp.test(privateKey)); + assert.match(privateKey, pkcs1PrivExp); assertApproximateSize(privateKey, 512); const publicKey = { key: publicKeyDER, ...publicKeyEncoding }; @@ -207,7 +207,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); assertApproximateSize(publicKeyDER, 74); assert.strictEqual(typeof privateKey, 'string'); - assert(pkcs1EncExp('AES-256-CBC').test(privateKey)); + assert.match(privateKey, pkcs1EncExp('AES-256-CBC')); // Since the private key is encrypted, signing shouldn't work anymore. const publicKey = { key: publicKeyDER, ...publicKeyEncoding }; @@ -367,7 +367,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } }, common.mustSucceed((publicKey, privateKeyDER) => { assert.strictEqual(typeof publicKey, 'string'); - assert(spkiExp.test(publicKey)); + assert.match(publicKey, spkiExp); // The private key is DER-encoded. assert(Buffer.isBuffer(privateKeyDER)); @@ -432,9 +432,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } }, common.mustSucceed((publicKey, privateKey) => { assert.strictEqual(typeof publicKey, 'string'); - assert(spkiExp.test(publicKey)); + assert.match(publicKey, spkiExp); assert.strictEqual(typeof privateKey, 'string'); - assert(sec1Exp.test(privateKey)); + assert.match(privateKey, sec1Exp); testSignVerify(publicKey, privateKey); })); @@ -454,9 +454,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } }, common.mustSucceed((publicKey, privateKey) => { assert.strictEqual(typeof publicKey, 'string'); - assert(spkiExp.test(publicKey)); + assert.match(publicKey, spkiExp); assert.strictEqual(typeof privateKey, 'string'); - assert(sec1Exp.test(privateKey)); + assert.match(privateKey, sec1Exp); testSignVerify(publicKey, privateKey); })); @@ -477,9 +477,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } }, common.mustSucceed((publicKey, privateKey) => { assert.strictEqual(typeof publicKey, 'string'); - assert(spkiExp.test(publicKey)); + assert.match(publicKey, spkiExp); assert.strictEqual(typeof privateKey, 'string'); - assert(sec1EncExp('AES-128-CBC').test(privateKey)); + assert.match(privateKey, sec1EncExp('AES-128-CBC')); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), @@ -511,9 +511,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } }, common.mustSucceed((publicKey, privateKey) => { assert.strictEqual(typeof publicKey, 'string'); - assert(spkiExp.test(publicKey)); + assert.match(publicKey, spkiExp); assert.strictEqual(typeof privateKey, 'string'); - assert(sec1EncExp('AES-128-CBC').test(privateKey)); + assert.match(privateKey, sec1EncExp('AES-128-CBC')); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), @@ -548,9 +548,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } }, common.mustSucceed((publicKey, privateKey) => { assert.strictEqual(typeof publicKey, 'string'); - assert(spkiExp.test(publicKey)); + assert.match(publicKey, spkiExp); assert.strictEqual(typeof privateKey, 'string'); - assert(pkcs8EncExp.test(privateKey)); + assert.match(privateKey, pkcs8EncExp); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), @@ -585,9 +585,9 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } }, common.mustSucceed((publicKey, privateKey) => { assert.strictEqual(typeof publicKey, 'string'); - assert(spkiExp.test(publicKey)); + assert.match(publicKey, spkiExp); assert.strictEqual(typeof privateKey, 'string'); - assert(pkcs8EncExp.test(privateKey)); + assert.match(privateKey, pkcs8EncExp); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), @@ -759,11 +759,11 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); }).then(common.mustCall((keys) => { const { publicKey, privateKey } = keys; assert.strictEqual(typeof publicKey, 'string'); - assert(pkcs1PubExp.test(publicKey)); + assert.match(publicKey, pkcs1PubExp); assertApproximateSize(publicKey, 180); assert.strictEqual(typeof privateKey, 'string'); - assert(pkcs1PrivExp.test(privateKey)); + assert.match(privateKey, pkcs1PrivExp); assertApproximateSize(privateKey, 512); testEncryptDecrypt(publicKey, privateKey); diff --git a/test/parallel/test-dgram-cluster-bind-error.js b/test/parallel/test-dgram-cluster-bind-error.js index 11c2bc1796f25a..baf0ae01ee2dcd 100644 --- a/test/parallel/test-dgram-cluster-bind-error.js +++ b/test/parallel/test-dgram-cluster-bind-error.js @@ -19,7 +19,7 @@ if (cluster.isPrimary) { const socket = dgram.createSocket('udp4'); socket.on('error', common.mustCall((err) => { - assert(/^Error: bind UNKNOWN 0\.0\.0\.0$/.test(err.toString())); + assert.match(err.toString(), /^Error: bind UNKNOWN 0\.0\.0\.0$/); process.nextTick(common.mustCall(() => { assert.strictEqual(socket._bindState, 0); // BIND_STATE_UNBOUND socket.close(); diff --git a/test/parallel/test-dgram-recv-error.js b/test/parallel/test-dgram-recv-error.js index 9850d944ce1011..0fe65f266eec9c 100644 --- a/test/parallel/test-dgram-recv-error.js +++ b/test/parallel/test-dgram-recv-error.js @@ -11,7 +11,7 @@ s.on('error', common.mustCall((err) => { s.close(); // Don't check the full error message, as the errno is not important here. - assert(/^Error: recvmsg/.test(err)); + assert.match(String(err), /^Error: recvmsg/); assert.strictEqual(err.syscall, 'recvmsg'); })); diff --git a/test/parallel/test-domain-implicit-fs.js b/test/parallel/test-domain-implicit-fs.js index c785ff75c67656..e609616024c582 100644 --- a/test/parallel/test-domain-implicit-fs.js +++ b/test/parallel/test-domain-implicit-fs.js @@ -37,7 +37,7 @@ d.on('error', common.mustCall(function(er) { assert.strictEqual(er.domainThrown, true); assert.ok(!er.domainEmitter); assert.strictEqual(er.actual.code, 'ENOENT'); - assert.ok(/\bthis file does not exist\b/i.test(er.actual.path)); + assert.match(er.actual.path, /\bthis file does not exist\b/i); assert.strictEqual(typeof er.actual.errno, 'number'); })); diff --git a/test/parallel/test-error-reporting.js b/test/parallel/test-error-reporting.js index 7568206d46bd00..75574641ec7b79 100644 --- a/test/parallel/test-error-reporting.js +++ b/test/parallel/test-error-reporting.js @@ -44,38 +44,39 @@ const syntaxErrorMessage = /\bSyntaxError\b/; // Simple throw error errExec('throws_error.js', common.mustCall((err, stdout, stderr) => { - assert.ok(/blah/.test(stderr)); + assert.match(stderr, /blah/); })); // Trying to JSON.parse(undefined) errExec('throws_error2.js', common.mustCall((err, stdout, stderr) => { - assert.ok(syntaxErrorMessage.test(stderr)); + assert.match(stderr, syntaxErrorMessage); })); // Trying to JSON.parse(undefined) in nextTick errExec('throws_error3.js', common.mustCall((err, stdout, stderr) => { - assert.ok(syntaxErrorMessage.test(stderr)); + assert.match(stderr, syntaxErrorMessage); })); // throw ILLEGAL error errExec('throws_error4.js', common.mustCall((err, stdout, stderr) => { - assert.ok(syntaxErrorMessage.test(stderr)); + assert.match(stderr, syntaxErrorMessage); })); // Specific long exception line doesn't result in stack overflow errExec('throws_error5.js', common.mustCall((err, stdout, stderr) => { - assert.ok(syntaxErrorMessage.test(stderr)); + assert.match(stderr, syntaxErrorMessage); })); // Long exception line with length > errorBuffer doesn't result in assertion errExec('throws_error6.js', common.mustCall((err, stdout, stderr) => { - assert.ok(syntaxErrorMessage.test(stderr)); + assert.match(stderr, syntaxErrorMessage); })); // Object that throws in toString() doesn't print garbage errExec('throws_error7.js', common.mustCall((err, stdout, stderr) => { - assert.ok(/throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/.test(stderr)); + assert.match(stderr, + /throw {\r?\n\^\r?\n{ toString: \[Function: toString] }\r?\n$/); })); diff --git a/test/parallel/test-error-serdes.js b/test/parallel/test-error-serdes.js index a65781c25eb261..82db8582444af3 100644 --- a/test/parallel/test-error-serdes.js +++ b/test/parallel/test-error-serdes.js @@ -22,7 +22,7 @@ for (let i = 0; i < 10; i++) { assert(Object.prototype.toString.call(err), '[object Error]'); assert.strictEqual(err.name, 'Error'); assert.strictEqual(err.message, 'foo'); - assert(/^Error: foo\n/.test(err.stack)); + assert.match(err.stack, /^Error: foo\n/); const prev = err; err = cycle(err); @@ -45,7 +45,7 @@ assert.strictEqual(cycle(Function), '[Function: Function]'); { const err = new ERR_INVALID_ARG_TYPE('object', 'Object', 42); - assert(/^TypeError \[ERR_INVALID_ARG_TYPE\]:/.test(err)); + assert.match(String(err), /^TypeError \[ERR_INVALID_ARG_TYPE\]:/); assert.strictEqual(err.name, 'TypeError'); assert.strictEqual(err.code, 'ERR_INVALID_ARG_TYPE'); } diff --git a/test/parallel/test-events-uncaught-exception-stack.js b/test/parallel/test-events-uncaught-exception-stack.js index c55322a5aa56c4..793a6b0c2ae5e9 100644 --- a/test/parallel/test-events-uncaught-exception-stack.js +++ b/test/parallel/test-events-uncaught-exception-stack.js @@ -9,7 +9,7 @@ process.on('uncaughtException', common.mustCall((err) => { const lines = err.stack.split('\n'); assert.strictEqual(lines[0], 'Error'); lines.slice(1).forEach((line) => { - assert(/^ at/.test(line), `${line} has an unexpected format`); + assert.match(line, /^ at/); }); })); diff --git a/test/parallel/test-fs-error-messages.js b/test/parallel/test-fs-error-messages.js index dd9639d99657b6..e47dee023c9623 100644 --- a/test/parallel/test-fs-error-messages.js +++ b/test/parallel/test-fs-error-messages.js @@ -199,8 +199,7 @@ function re(literals, ...values) { `expect ${err.dest} to end with 'foo'`); const regexp = new RegExp('^ENOENT: no such file or directory, link ' + re`'${nonexistentFile}' -> ` + '\'.*foo\''); - assert.ok(regexp.test(err.message), - `Expect ${err.message} to match ${regexp}`); + assert.match(err.message, regexp); assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'link'); @@ -291,8 +290,7 @@ function re(literals, ...values) { `expect ${err.dest} to end with 'foo'`); const regexp = new RegExp('ENOENT: no such file or directory, rename ' + re`'${nonexistentFile}' -> ` + '\'.*foo\''); - assert.ok(regexp.test(err.message), - `Expect ${err.message} to match ${regexp}`); + assert.match(err.message, regexp); assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); assert.strictEqual(err.syscall, 'rename'); @@ -641,13 +639,11 @@ if (!common.isAIX) { { const validateError = (err) => { const pathPrefix = new RegExp('^' + re`${nonexistentDir}`); - assert(pathPrefix.test(err.path), - `Expect ${err.path} to match ${pathPrefix}`); + assert.match(err.path, pathPrefix); const prefix = new RegExp('^ENOENT: no such file or directory, mkdtemp ' + re`'${nonexistentDir}`); - assert(prefix.test(err.message), - `Expect ${err.message} to match ${prefix}`); + assert.match(err.message, prefix); assert.strictEqual(err.errno, UV_ENOENT); assert.strictEqual(err.code, 'ENOENT'); diff --git a/test/parallel/test-fs-mkdir-rmdir.js b/test/parallel/test-fs-mkdir-rmdir.js index 80162934d1f399..738cfc0de0023b 100644 --- a/test/parallel/test-fs-mkdir-rmdir.js +++ b/test/parallel/test-fs-mkdir-rmdir.js @@ -29,7 +29,7 @@ fs.mkdir(d, 0o666, common.mustSucceed(() => { fs.mkdir(d, 0o666, common.mustCall(function(err) { assert.strictEqual(this, undefined); assert.ok(err, 'got no error'); - assert.ok(/^EEXIST/.test(err.message), 'got no EEXIST message'); + assert.match(err.message, /^EEXIST/); assert.strictEqual(err.code, 'EEXIST'); assert.strictEqual(err.path, d); diff --git a/test/parallel/test-fs-readfile-error.js b/test/parallel/test-fs-readfile-error.js index 9d92638ed48dbe..8c5a3a71c6f530 100644 --- a/test/parallel/test-fs-readfile-error.js +++ b/test/parallel/test-fs-readfile-error.js @@ -47,13 +47,13 @@ function test(env, cb) { } test({ NODE_DEBUG: '' }, common.mustCall((data) => { - assert(/EISDIR/.test(data)); - assert(/test-fs-readfile-error/.test(data)); + assert.match(data, /EISDIR/); + assert.match(data, /test-fs-readfile-error/); })); test({ NODE_DEBUG: 'fs' }, common.mustCall((data) => { - assert(/EISDIR/.test(data)); - assert(/test-fs-readfile-error/.test(data)); + assert.match(data, /EISDIR/); + assert.match(data, /test-fs-readfile-error/); })); assert.throws( diff --git a/test/parallel/test-global-console-exists.js b/test/parallel/test-global-console-exists.js index bcebfadf0d7620..899b01b36f1f67 100644 --- a/test/parallel/test-global-console-exists.js +++ b/test/parallel/test-global-console-exists.js @@ -28,7 +28,7 @@ process.on('exit', () => { process.stderr.write = (data) => { if (writeTimes === 0) - assert.ok(leakWarning.test(data)); + assert.match(data, leakWarning); else assert.fail('stderr.write should be called only once'); diff --git a/test/parallel/test-http-chunked-304.js b/test/parallel/test-http-chunked-304.js index 2a8c33a5901f92..b94d776595f89d 100644 --- a/test/parallel/test-http-chunked-304.js +++ b/test/parallel/test-http-chunked-304.js @@ -57,9 +57,9 @@ function test(statusCode) { conn.on('end', common.mustCall(() => { // Connection: close should be in the response - assert.strictEqual(/^Connection: close\r\n$/m.test(resp), true); + assert.match(resp, /^Connection: close\r\n$/m); // Make sure this doesn't end with 0\r\n\r\n - assert.strictEqual(/^0\r\n$/m.test(resp), false); + assert.doesNotMatch(resp, /^0\r\n$/m); })); }) ); diff --git a/test/parallel/test-http-client-reject-chunked-with-content-length.js b/test/parallel/test-http-client-reject-chunked-with-content-length.js index 8683b5726e2758..a3da5180e18f73 100644 --- a/test/parallel/test-http-client-reject-chunked-with-content-length.js +++ b/test/parallel/test-http-client-reject-chunked-with-content-length.js @@ -19,7 +19,7 @@ server.listen(0, () => { // header, which is a violation of the HTTP spec. const req = http.get({ port: server.address().port }, common.mustNotCall()); req.on('error', common.mustCall((err) => { - assert(/^Parse Error/.test(err.message)); + assert.match(err.message, /^Parse Error/); assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); server.close(); })); diff --git a/test/parallel/test-http-client-reject-cr-no-lf.js b/test/parallel/test-http-client-reject-cr-no-lf.js index bd303888bb63f9..be82caf296d9a2 100644 --- a/test/parallel/test-http-client-reject-cr-no-lf.js +++ b/test/parallel/test-http-client-reject-cr-no-lf.js @@ -18,7 +18,7 @@ server.listen(0, () => { // header field that ends only in \r with no following \n const req = http.get({ port: server.address().port }, common.mustNotCall()); req.on('error', common.mustCall((err) => { - assert(/^Parse Error/.test(err.message)); + assert.match(err.message, /^Parse Error/); assert.strictEqual(err.code, 'HPE_LF_EXPECTED'); server.close(); })); diff --git a/test/parallel/test-http-double-content-length.js b/test/parallel/test-http-double-content-length.js index 53f924d652dd75..62e9c6853b5e21 100644 --- a/test/parallel/test-http-double-content-length.js +++ b/test/parallel/test-http-double-content-length.js @@ -9,7 +9,7 @@ const assert = require('assert'); // Content-Length header is received. const server = http.createServer(common.mustNotCall()); server.on('clientError', common.mustCall((err, socket) => { - assert(/^Parse Error/.test(err.message)); + assert.match(err.message, /^Parse Error/); assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); socket.destroy(); })); diff --git a/test/parallel/test-http-parser-finish-error.js b/test/parallel/test-http-parser-finish-error.js index 6d47a762dc8bfa..674b0a8bd34399 100644 --- a/test/parallel/test-http-parser-finish-error.js +++ b/test/parallel/test-http-parser-finish-error.js @@ -11,7 +11,7 @@ const str = 'GET / HTTP/1.1\r\n' + const server = http.createServer(common.mustNotCall()); server.on('clientError', common.mustCall((err, socket) => { - assert(/^Parse Error/.test(err.message)); + assert.match(err.message, /^Parse Error/); assert.strictEqual(err.code, 'HPE_INVALID_EOF_STATE'); socket.destroy(); }, 1)); diff --git a/test/parallel/test-http-server-reject-chunked-with-content-length.js b/test/parallel/test-http-server-reject-chunked-with-content-length.js index b3bc4295a84c0b..4e287ec184308a 100644 --- a/test/parallel/test-http-server-reject-chunked-with-content-length.js +++ b/test/parallel/test-http-server-reject-chunked-with-content-length.js @@ -11,7 +11,7 @@ const reqstr = 'POST / HTTP/1.1\r\n' + const server = http.createServer(common.mustNotCall()); server.on('clientError', common.mustCall((err) => { - assert(/^Parse Error/.test(err.message)); + assert.match(err.message, /^Parse Error/); assert.strictEqual(err.code, 'HPE_UNEXPECTED_CONTENT_LENGTH'); server.close(); })); diff --git a/test/parallel/test-http-server-reject-cr-no-lf.js b/test/parallel/test-http-server-reject-cr-no-lf.js index 5dace4f7bfd706..61c8489571f14f 100644 --- a/test/parallel/test-http-server-reject-cr-no-lf.js +++ b/test/parallel/test-http-server-reject-cr-no-lf.js @@ -13,7 +13,7 @@ const str = 'GET / HTTP/1.1\r\n' + const server = http.createServer(common.mustNotCall()); server.on('clientError', common.mustCall((err) => { - assert(/^Parse Error/.test(err.message)); + assert.match(err.message, /^Parse Error/); assert.strictEqual(err.code, 'HPE_LF_EXPECTED'); server.close(); })); diff --git a/test/parallel/test-http-server.js b/test/parallel/test-http-server.js index dcefc761728d36..fcbb8cd4b9178b 100644 --- a/test/parallel/test-http-server.js +++ b/test/parallel/test-http-server.js @@ -131,10 +131,10 @@ process.on('exit', function() { assert.strictEqual(requests_sent, 4); const hello = new RegExp('/hello'); - assert.ok(hello.test(server_response)); + assert.match(server_response, hello); const quit = new RegExp('/quit'); - assert.ok(quit.test(server_response)); + assert.match(server_response, quit); assert.strictEqual(client_got_eof, true); }); diff --git a/test/parallel/test-http2-propagate-session-destroy-code.js b/test/parallel/test-http2-propagate-session-destroy-code.js index f9e1d535720801..c54e52e085af4b 100644 --- a/test/parallel/test-http2-propagate-session-destroy-code.js +++ b/test/parallel/test-http2-propagate-session-destroy-code.js @@ -15,14 +15,14 @@ server.on('error', common.mustNotCall()); server.on('session', (session) => { session.on('close', common.mustCall()); session.on('error', common.mustCall((err) => { - assert.ok(errRegEx.test(err), `server session err: ${err}`); + assert.match(err.message, errRegEx); assert.strictEqual(session.closed, false); assert.strictEqual(session.destroyed, true); })); session.on('stream', common.mustCall((stream) => { stream.on('error', common.mustCall((err) => { - assert.ok(errRegEx.test(err), `server stream err: ${err}`); + assert.match(err.message, errRegEx); assert.strictEqual(session.closed, false); assert.strictEqual(session.destroyed, true); assert.strictEqual(stream.rstCode, destroyCode); @@ -36,7 +36,7 @@ server.listen(0, common.mustCall(() => { const session = http2.connect(`http://localhost:${server.address().port}`); session.on('error', common.mustCall((err) => { - assert.ok(errRegEx.test(err), `client session err: ${err}`); + assert.match(err.message, errRegEx); assert.strictEqual(session.closed, false); assert.strictEqual(session.destroyed, true); })); @@ -44,7 +44,7 @@ server.listen(0, common.mustCall(() => { const stream = session.request({ [http2.constants.HTTP2_HEADER_PATH]: '/' }); stream.on('error', common.mustCall((err) => { - assert.ok(errRegEx.test(err), `client stream err: ${err}`); + assert.match(err.message, errRegEx); assert.strictEqual(stream.rstCode, destroyCode); })); diff --git a/test/parallel/test-http2-stream-client.js b/test/parallel/test-http2-stream-client.js index 59e88ece98d2b0..f975e90cbdac61 100644 --- a/test/parallel/test-http2-stream-client.js +++ b/test/parallel/test-http2-stream-client.js @@ -11,10 +11,10 @@ const server = http2.createServer(); server.on('stream', common.mustCall((stream) => { assert.strictEqual(stream.aborted, false); const insp = util.inspect(stream); - assert.ok(/Http2Stream {/.test(insp)); - assert.ok(/ state:/.test(insp)); - assert.ok(/ readableState:/.test(insp)); - assert.ok(/ writableState:/.test(insp)); + assert.match(insp, /Http2Stream {/); + assert.match(insp, / state:/); + assert.match(insp, / readableState:/); + assert.match(insp, / writableState:/); stream.end('ok'); })); server.listen(0, common.mustCall(() => { diff --git a/test/parallel/test-https-agent-create-connection.js b/test/parallel/test-https-agent-create-connection.js index d4840298aa6e08..cea335a422ebc7 100644 --- a/test/parallel/test-https-agent-create-connection.js +++ b/test/parallel/test-https-agent-create-connection.js @@ -29,8 +29,8 @@ const checkRequest = (socket, server) => { result += chunk; })); socket.on('end', common.mustCall(() => { - assert(expectedHeader.test(result)); - assert(expectedBody.test(result)); + assert.match(result, expectedHeader); + assert.match(result, expectedBody); server.close(); })); }; @@ -112,7 +112,7 @@ function createServer() { const options = null; const socket = agent.createConnection(port, host, options); socket.on('error', common.mustCall((e) => { - assert(expectCertError.test(e.toString())); + assert.match(e.toString(), expectCertError); server.close(); })); })); @@ -127,7 +127,7 @@ function createServer() { const options = undefined; const socket = agent.createConnection(port, host, options); socket.on('error', common.mustCall((e) => { - assert(expectCertError.test(e.toString())); + assert.match(e.toString(), expectCertError); server.close(); })); })); diff --git a/test/parallel/test-https-client-renegotiation-limit.js b/test/parallel/test-https-client-renegotiation-limit.js index 6b5aad2d30933f..35fcc6bfcc6e43 100644 --- a/test/parallel/test-https-client-renegotiation-limit.js +++ b/test/parallel/test-https-client-renegotiation-limit.js @@ -58,7 +58,7 @@ function test(next) { const conn = req.connection; conn.on('error', (err) => { console.error(`Caught exception: ${err}`); - assert(/TLS session renegotiation attack/.test(err)); + assert.match(err.message, /TLS session renegotiation attack/); conn.destroy(); }); res.end('ok'); diff --git a/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js b/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js index 5dc9c9bb2dff3a..8b367e98c37f49 100644 --- a/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js +++ b/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js @@ -27,7 +27,7 @@ session.post('Runtime.evaluate', { assert.ifError(error); const { exception } = res.exceptionDetails; assert.strictEqual(exception.className, 'EvalError'); - assert(/Possible side-effect/.test(exception.description)); + assert.match(exception.description, /Possible side-effect/); assert(context); // Keep 'context' alive and make linter happy. }); diff --git a/test/parallel/test-internal-fs.js b/test/parallel/test-internal-fs.js index bd4ed5742fba9e..4204890cdf5de0 100644 --- a/test/parallel/test-internal-fs.js +++ b/test/parallel/test-internal-fs.js @@ -26,7 +26,7 @@ assert.throws( ); if (process.platform === 'win32') { - assert.strictEqual(/^\\\\\?\\/.test(preprocessSymlinkDestination), true); + assert.match(preprocessSymlinkDestination, /^\\\\\?\\/); } else { assert.strictEqual(preprocessSymlinkDestination, pathString); } diff --git a/test/parallel/test-internal-util-decorate-error-stack.js b/test/parallel/test-internal-util-decorate-error-stack.js index b125a29741cb73..b36714b44b8b72 100644 --- a/test/parallel/test-internal-util-decorate-error-stack.js +++ b/test/parallel/test-internal-util-decorate-error-stack.js @@ -31,9 +31,9 @@ function checkStack(stack) { // displays the line of code (`var foo bar;`) that is causing a problem. // ChakraCore does not display the line of code but includes `;` in the phrase // `Expected ';' `. - assert.ok(/;/g.test(stack)); + assert.match(stack, /;/g); // Test that it's a multiline string. - assert.ok(/\n/g.test(stack)); + assert.match(stack, /\n/g); } let err; const badSyntaxPath = diff --git a/test/parallel/test-net-connect-options-port.js b/test/parallel/test-net-connect-options-port.js index d9f310afc7549e..1225ba209281bb 100644 --- a/test/parallel/test-net-connect-options-port.js +++ b/test/parallel/test-net-connect-options-port.js @@ -194,7 +194,7 @@ function canConnect(port) { function asyncFailToConnect(port) { const onError = () => common.mustCall((err) => { const regexp = /^Error: connect E\w+.+$/; - assert(regexp.test(String(err)), String(err)); + assert.match(String(err), regexp); }); const dont = () => common.mustNotCall(); diff --git a/test/parallel/test-net-server-listen-path.js b/test/parallel/test-net-server-listen-path.js index 99144ceb494a64..2be36b90252479 100644 --- a/test/parallel/test-net-server-listen-path.js +++ b/test/parallel/test-net-server-listen-path.js @@ -85,7 +85,7 @@ function randomPipePath() { server2.on('error', common.mustCall((err) => { server1.close(); assert.strictEqual(err.code, 'EADDRINUSE'); - assert(/^listen EADDRINUSE: address already in use/.test(err.message)); + assert.match(err.message, /^listen EADDRINUSE: address already in use/); })); }); } diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index da61a0a235ee0f..80c32ea2a996c0 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -75,7 +75,7 @@ if (common.isWindows) { const endianness = os.endianness(); is.string(endianness); -assert.ok(/[BL]E/.test(endianness)); +assert.match(endianness, /[BL]E/); const hostname = os.hostname(); is.string(hostname); @@ -110,7 +110,7 @@ is.string(release); assert.ok(release.length > 0); // TODO: Check format on more than just AIX if (common.isAIX) - assert.ok(/^\d+\.\d+$/.test(release)); + assert.match(release, /^\d+\.\d+$/); const platform = os.platform(); is.string(platform); diff --git a/test/parallel/test-preload.js b/test/parallel/test-preload.js index 4636a46007001c..3e18e39e0b9d2e 100644 --- a/test/parallel/test-preload.js +++ b/test/parallel/test-preload.js @@ -168,7 +168,7 @@ childProcess.exec( fixtures.path('cluster-preload-test.js')}"`, function(err, stdout, stderr) { assert.ifError(err); - assert.ok(/worker terminated with code 43/.test(stdout)); + assert.match(stdout, /worker terminated with code 43/); } ); @@ -198,6 +198,6 @@ childProcess.exec( { cwd: fixtures.fixturesDir }, function(err, stdout, stderr) { assert.ifError(err); - assert.ok(/worker terminated with code 43/.test(stdout)); + assert.match(stdout, /worker terminated with code 43/); } ); diff --git a/test/parallel/test-process-emitwarning.js b/test/parallel/test-process-emitwarning.js index 1bfac40ecbce30..e1c7473f8aad3d 100644 --- a/test/parallel/test-process-emitwarning.js +++ b/test/parallel/test-process-emitwarning.js @@ -12,7 +12,7 @@ const testType = 'CustomWarning'; process.on('warning', common.mustCall((warning) => { assert(warning); - assert(/^(?:Warning|CustomWarning)/.test(warning.name)); + assert.match(warning.name, /^(?:Warning|CustomWarning)/); assert.strictEqual(warning.message, testMsg); if (warning.code) assert.strictEqual(warning.code, testCode); if (warning.detail) assert.strictEqual(warning.detail, testDetail); diff --git a/test/parallel/test-process-env-allowed-flags.js b/test/parallel/test-process-env-allowed-flags.js index 9337263d5cc979..a4558200fa8af8 100644 --- a/test/parallel/test-process-env-allowed-flags.js +++ b/test/parallel/test-process-env-allowed-flags.js @@ -51,8 +51,7 @@ const assert = require('assert'); // Assert all "canonical" flags begin with dash(es) { process.allowedNodeEnvironmentFlags.forEach((flag) => { - assert(/^--?[a-zA-Z0-9._-]+$/.test(flag), - `Unexpected format for flag ${flag}`); + assert.match(flag, /^--?[a-zA-Z0-9._-]+$/); }); } diff --git a/test/parallel/test-process-redirect-warnings-env.js b/test/parallel/test-process-redirect-warnings-env.js index 678f4b0868fafc..50abdbf64b70dd 100644 --- a/test/parallel/test-process-redirect-warnings-env.js +++ b/test/parallel/test-process-redirect-warnings-env.js @@ -21,6 +21,6 @@ const warnpath = path.join(tmpdir.path, 'warnings.txt'); fork(warnmod, { env: { ...process.env, NODE_REDIRECT_WARNINGS: warnpath } }) .on('exit', common.mustCall(() => { fs.readFile(warnpath, 'utf8', common.mustSucceed((data) => { - assert(/\(node:\d+\) Warning: a bad practice warning/.test(data)); + assert.match(data, /\(node:\d+\) Warning: a bad practice warning/); })); })); diff --git a/test/parallel/test-process-redirect-warnings.js b/test/parallel/test-process-redirect-warnings.js index dd66c87e633224..9eb7bbc639fc18 100644 --- a/test/parallel/test-process-redirect-warnings.js +++ b/test/parallel/test-process-redirect-warnings.js @@ -21,6 +21,6 @@ const warnpath = path.join(tmpdir.path, 'warnings.txt'); fork(warnmod, { execArgv: [`--redirect-warnings=${warnpath}`] }) .on('exit', common.mustCall(() => { fs.readFile(warnpath, 'utf8', common.mustSucceed((data) => { - assert(/\(node:\d+\) Warning: a bad practice warning/.test(data)); + assert.match(data, /\(node:\d+\) Warning: a bad practice warning/); })); })); diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index ab2f217e963261..e63848b1faff90 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -38,16 +38,18 @@ assert.deepStrictEqual(actual_keys, expected_keys); const commonTemplate = /^\d+\.\d+\.\d+(?:-.*)?$/; -assert(commonTemplate.test(process.versions.ares)); -assert(commonTemplate.test(process.versions.brotli)); -assert(commonTemplate.test(process.versions.llhttp)); -assert(commonTemplate.test(process.versions.node)); -assert(commonTemplate.test(process.versions.uv)); -assert(commonTemplate.test(process.versions.zlib)); +assert.match(process.versions.ares, commonTemplate); +assert.match(process.versions.brotli, commonTemplate); +assert.match(process.versions.llhttp, commonTemplate); +assert.match(process.versions.node, commonTemplate); +assert.match(process.versions.uv, commonTemplate); +assert.match(process.versions.zlib, commonTemplate); -assert(/^\d+\.\d+\.\d+(?:\.\d+)?-node\.\d+(?: \(candidate\))?$/ - .test(process.versions.v8)); -assert(/^\d+$/.test(process.versions.modules)); +assert.match( + process.versions.v8, + /^\d+\.\d+\.\d+(?:\.\d+)?-node\.\d+(?: \(candidate\))?$/ +); +assert.match(process.versions.modules, /^\d+$/); if (common.hasCrypto) { const versionRegex = common.hasOpenSSL3 ? @@ -56,7 +58,7 @@ if (common.hasCrypto) { // and linking against the main development branch of OpenSSL. /^\d+\.\d+\.\d+(?:[-+][a-z0-9]+)*$/ : /^\d+\.\d+\.\d+[a-z]?(\+quic)?(-fips)?$/; - assert(versionRegex.test(process.versions.openssl)); + assert.match(process.versions.openssl, versionRegex); } for (let i = 0; i < expected_keys.length; i++) { diff --git a/test/parallel/test-readline-undefined-columns.js b/test/parallel/test-readline-undefined-columns.js index f1ef7b5bba2eee..25bafe957fa40a 100644 --- a/test/parallel/test-readline-undefined-columns.js +++ b/test/parallel/test-readline-undefined-columns.js @@ -32,13 +32,15 @@ oStream.on('end', common.mustCall(() => { const expect = 'process.stdout\r\n' + 'process.stdin\r\n' + 'process.stderr'; - assert(new RegExp(expect).test(output)); + assert.match(output, new RegExp(expect)); })); iStream.write('process.s\t'); -assert(/process\.std\b/.test(output)); // Completion works. -assert(!/stdout/.test(output)); // Completion doesn’t show all results yet. +// Completion works. +assert.match(output, /process\.std\b/); +// Completion doesn’t show all results yet. +assert.doesNotMatch(output, /stdout/); iStream.write('\t'); oStream.end(); diff --git a/test/parallel/test-repl-definecommand.js b/test/parallel/test-repl-definecommand.js index efa22ed56f740f..0057eb51ebdd4e 100644 --- a/test/parallel/test-repl-definecommand.js +++ b/test/parallel/test-repl-definecommand.js @@ -35,9 +35,8 @@ r.defineCommand('say2', function() { }); inputStream.write('.help\n'); -assert(/\n\.say1 help for say1\n/.test(output), - 'help for say1 not present'); -assert(/\n\.say2\n/.test(output), 'help for say2 not present'); +assert.match(output, /\n\.say1 help for say1\n/); +assert.match(output, /\n\.say2\n/); inputStream.write('.say1 node developer\n'); assert.ok(output.startsWith('hello node developer\n'), `say1 output starts incorrectly: "${output}"`); diff --git a/test/parallel/test-repl-harmony.js b/test/parallel/test-repl-harmony.js index 88b2c9deca1b05..f03cd03d0f97b2 100644 --- a/test/parallel/test-repl-harmony.js +++ b/test/parallel/test-repl-harmony.js @@ -43,7 +43,7 @@ child.stdout.on('data', (d) => { out += d; }); child.stdout.on('end', () => { - assert(expectOut.test(out)); + assert.match(out, expectOut); console.log('ok'); }); diff --git a/test/parallel/test-repl-mode.js b/test/parallel/test-repl-mode.js index d8131d34f93b44..0cfcfba56bc8a5 100644 --- a/test/parallel/test-repl-mode.js +++ b/test/parallel/test-repl-mode.js @@ -30,8 +30,8 @@ function testStrictMode() { const cli = initRepl(repl.REPL_MODE_STRICT); cli.input.emit('data', 'x = 3\n'); - assert.ok(/ReferenceError: x is not defined/.test( - cli.output.accumulator.join(''))); + assert.match(cli.output.accumulator.join(''), + /ReferenceError: x is not defined/); cli.output.accumulator.length = 0; cli.input.emit('data', 'let y = 3\n'); diff --git a/test/parallel/test-repl-require.js b/test/parallel/test-repl-require.js index 391b629b1b3a3b..fc431dea9f0f69 100644 --- a/test/parallel/test-repl-require.js +++ b/test/parallel/test-repl-require.js @@ -33,8 +33,8 @@ const repl = require('repl'); }); process.on('exit', function() { - assert.strictEqual(/Cannot find module/.test(answer), false); - assert.strictEqual(/Error/.test(answer), false); + assert.doesNotMatch(answer, /Cannot find module/); + assert.doesNotMatch(answer, /Error/); assert.strictEqual(answer, '\'eye catcher\'\n\'perhaps I work\'\n'); }); } @@ -63,9 +63,9 @@ const repl = require('repl'); }); process.on('exit', function() { - assert.strictEqual(/Uncaught Error: Cannot find module '\.\/bar'/.test(answer), true); + assert.match(answer, /Uncaught Error: Cannot find module '\.\/bar'/); - assert.strictEqual(/code: 'MODULE_NOT_FOUND'/.test(answer), true); - assert.strictEqual(/requireStack: \[ '' \]/.test(answer), true); + assert.match(answer, /code: 'MODULE_NOT_FOUND'/); + assert.match(answer, /requireStack: \[ '' \]/); }); } diff --git a/test/parallel/test-repl-uncaught-exception-async.js b/test/parallel/test-repl-uncaught-exception-async.js index 7b14ebd5d94caa..366a4e6f2968af 100644 --- a/test/parallel/test-repl-uncaught-exception-async.js +++ b/test/parallel/test-repl-uncaught-exception-async.js @@ -40,5 +40,5 @@ setTimeout(() => { const len = process.listenerCount('uncaughtException'); process.removeAllListeners('uncaughtException'); assert.strictEqual(len, 0); - assert(/ERR_INVALID_REPL_INPUT.*(?!Type)RangeError: abc/s.test(accum)); + assert.match(accum, /ERR_INVALID_REPL_INPUT.*(?!Type)RangeError: abc/s); }, 2); diff --git a/test/parallel/test-repl-uncaught-exception.js b/test/parallel/test-repl-uncaught-exception.js index 9d443b4e2ca553..d3dbe0acb0106d 100644 --- a/test/parallel/test-repl-uncaught-exception.js +++ b/test/parallel/test-repl-uncaught-exception.js @@ -24,7 +24,7 @@ function run({ command, expected, useColors = false }) { if (typeof expected === 'string') { assert.strictEqual(accum, expected); } else { - assert(expected.test(accum), accum); + assert.match(accum, expected); } // Verify that the repl is still working as expected. diff --git a/test/parallel/test-repl-underscore.js b/test/parallel/test-repl-underscore.js index 1802f8b8ff1e86..8f4470b94963b3 100644 --- a/test/parallel/test-repl-underscore.js +++ b/test/parallel/test-repl-underscore.js @@ -199,7 +199,7 @@ function testError() { if (typeof expected === 'string') assert.strictEqual(line, expected); else - assert(expected.test(line), `${line} should match ${expected}`); + assert.match(line, expected); } assert.strictEqual(expectedLines.length, 0); diff --git a/test/parallel/test-repl-unexpected-token-recoverable.js b/test/parallel/test-repl-unexpected-token-recoverable.js index 242b86479ab195..ddab589ddec8b9 100644 --- a/test/parallel/test-repl-unexpected-token-recoverable.js +++ b/test/parallel/test-repl-unexpected-token-recoverable.js @@ -26,7 +26,7 @@ child.stdout.on('data', (d) => { }); child.stdout.on('end', () => { - assert(expectOut.test(out)); + assert.match(out, expectOut); console.log('ok'); }); diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index bbb95f3fa39f68..2db174d9691362 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -90,8 +90,7 @@ async function runReplTests(socket, prompt, tests) { if (typeof expectedLine === 'string') { assert.strictEqual(actualLine, expectedLine); } else { - assert(expectedLine.test(actualLine), - `${actualLine} match ${expectedLine}`); + assert.match(actualLine, expectedLine); } } } diff --git a/test/parallel/test-tls-cli-min-max-conflict.js b/test/parallel/test-tls-cli-min-max-conflict.js index 68aae4c635bcec..fe4eba558fee01 100644 --- a/test/parallel/test-tls-cli-min-max-conflict.js +++ b/test/parallel/test-tls-cli-min-max-conflict.js @@ -10,5 +10,5 @@ const child_process = require('child_process'); const args = ['--tls-min-v1.3', '--tls-max-v1.2', '-p', 'process.version']; child_process.execFile(process.argv[0], args, (err) => { assert(err); - assert(/not both/.test(err.message)); + assert.match(err.message, /not both/); }); diff --git a/test/parallel/test-tls-client-renegotiation-limit.js b/test/parallel/test-tls-client-renegotiation-limit.js index 9a08efe96f5098..71d7a85bae468b 100644 --- a/test/parallel/test-tls-client-renegotiation-limit.js +++ b/test/parallel/test-tls-client-renegotiation-limit.js @@ -56,7 +56,7 @@ function test(next) { const server = tls.createServer(options, (conn) => { conn.on('error', (err) => { console.error(`Caught exception: ${err}`); - assert(/TLS session renegotiation attack/.test(err)); + assert.match(err.message, /TLS session renegotiation attack/); conn.destroy(); }); conn.pipe(conn); diff --git a/test/parallel/test-tls-econnreset.js b/test/parallel/test-tls-econnreset.js index 1ffd7b1e97522f..a056f908190fd6 100644 --- a/test/parallel/test-tls-econnreset.js +++ b/test/parallel/test-tls-econnreset.js @@ -47,6 +47,6 @@ const server = tls.createServer({ process.on('exit', function() { assert(clientError); - assert(/socket hang up/.test(clientError.message)); - assert(/ECONNRESET/.test(clientError.code)); + assert.match(clientError.message, /socket hang up/); + assert.match(clientError.code, /ECONNRESET/); }); diff --git a/test/parallel/test-tls-empty-sni-context.js b/test/parallel/test-tls-empty-sni-context.js index 9b963e66294c32..0c999b2c448f47 100644 --- a/test/parallel/test-tls-empty-sni-context.js +++ b/test/parallel/test-tls-empty-sni-context.js @@ -16,7 +16,7 @@ const options = { const server = tls.createServer(options, (c) => { assert.fail('Should not be called'); }).on('tlsClientError', common.mustCall((err, c) => { - assert(/SSL_use_certificate:passed a null parameter/i.test(err.message)); + assert.match(err.message, /SSL_use_certificate:passed a null parameter/i); server.close(); })).listen(0, common.mustCall(() => { const c = tls.connect({ @@ -26,6 +26,6 @@ const server = tls.createServer(options, (c) => { }, common.mustNotCall()); c.on('error', common.mustCall((err) => { - assert(/Client network socket disconnected/.test(err.message)); + assert.match(err.message, /Client network socket disconnected/); })); })); diff --git a/test/parallel/test-tls-enable-trace-cli.js b/test/parallel/test-tls-enable-trace-cli.js index 951dca4a87f1ed..7b6f7e22397af6 100644 --- a/test/parallel/test-tls-enable-trace-cli.js +++ b/test/parallel/test-tls-enable-trace-cli.js @@ -35,8 +35,8 @@ child.on('close', common.mustCall((code, signal) => { assert.strictEqual(code, 0); assert.strictEqual(signal, null); assert.strictEqual(stdout.trim(), ''); - assert(/Warning: Enabling --trace-tls can expose sensitive/.test(stderr)); - assert(/Sent Record/.test(stderr)); + assert.match(stderr, /Warning: Enabling --trace-tls can expose sensitive/); + assert.match(stderr, /Sent Record/); })); function test() { diff --git a/test/parallel/test-tls-enable-trace.js b/test/parallel/test-tls-enable-trace.js index a3b1721ade10c2..9126f58ee17314 100644 --- a/test/parallel/test-tls-enable-trace.js +++ b/test/parallel/test-tls-enable-trace.js @@ -23,8 +23,8 @@ let stderr = ''; child.stderr.setEncoding('utf8'); child.stderr.on('data', (data) => stderr += data); child.on('close', common.mustCall(() => { - assert(/Received Record/.test(stderr)); - assert(/ClientHello/.test(stderr)); + assert.match(stderr, /Received Record/); + assert.match(stderr, /ClientHello/); })); // For debugging and observation of actual trace output. diff --git a/test/parallel/test-tls-env-bad-extra-ca.js b/test/parallel/test-tls-env-bad-extra-ca.js index 5ba1e227d29ac0..0e5e784fb00cc5 100644 --- a/test/parallel/test-tls-env-bad-extra-ca.js +++ b/test/parallel/test-tls-env-bad-extra-ca.js @@ -38,7 +38,7 @@ fork(__filename, opts) // encoding-wise if (!common.isWindows) { const re = /Warning: Ignoring extra certs from.*no-such-file-exists-🐢.* load failed:.*No such file or directory/; - assert(re.test(stderr), stderr); + assert.match(stderr, re); } })) .stderr.setEncoding('utf8').on('data', function(str) { diff --git a/test/parallel/test-unhandled-exception-rethrow-error.js b/test/parallel/test-unhandled-exception-rethrow-error.js index a4d326d9839d71..883351e2a4bf72 100644 --- a/test/parallel/test-unhandled-exception-rethrow-error.js +++ b/test/parallel/test-unhandled-exception-rethrow-error.js @@ -22,7 +22,7 @@ if (process.argv[2] === 'child') { assert.strictEqual(result.stdout.toString().trim(), ''); // Verify that the error was thrown and that the stack was preserved. const stderr = result.stderr.toString(); - assert(/Error: boom/.test(stderr)); - assert(/at throwException/.test(stderr)); - assert(/rethrow: true/.test(stderr)); + assert.match(stderr, /Error: boom/); + assert.match(stderr, /at throwException/); + assert.match(stderr, /rethrow: true/); } diff --git a/test/parallel/test-utf8-scripts.js b/test/parallel/test-utf8-scripts.js index 24ee6455973ed1..4bf5b0cd5b1e3d 100644 --- a/test/parallel/test-utf8-scripts.js +++ b/test/parallel/test-utf8-scripts.js @@ -27,4 +27,4 @@ const assert = require('assert'); console.log('Σὲ γνωρίζω ἀπὸ τὴν κόψη'); -assert.strictEqual(/Hellö Wörld/.test('Hellö Wörld'), true); +assert.match('Hellö Wörld', /Hellö Wörld/); diff --git a/test/parallel/test-util-emit-experimental-warning.js b/test/parallel/test-util-emit-experimental-warning.js index 1c1759a428307e..06d3df7a73bd9a 100644 --- a/test/parallel/test-util-emit-experimental-warning.js +++ b/test/parallel/test-util-emit-experimental-warning.js @@ -9,7 +9,7 @@ const { emitExperimentalWarning } = require('internal/util'); // when passed the same feature multiple times. process.on('warning', common.mustCall((warning) => { - assert(/is an experimental feature/.test(warning.message)); + assert.match(warning.message, /is an experimental feature/); }, 2)); emitExperimentalWarning('feature1'); diff --git a/test/parallel/test-util-inspect.js b/test/parallel/test-util-inspect.js index 10f187f9d1aa07..fe01c4c0f92858 100644 --- a/test/parallel/test-util-inspect.js +++ b/test/parallel/test-util-inspect.js @@ -156,12 +156,14 @@ assert.match(util.inspect((new JSStream())._externalStream), assert.strictEqual(util.inspect({ a: regexp }, false, 0), '{ a: /regexp/ }'); } -assert(/Object/.test( - util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true) -)); -assert(!/Object/.test( - util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true) -)); +assert.match( + util.inspect({ a: { a: { a: { a: {} } } } }, undefined, undefined, true), + /Object/ +); +assert.doesNotMatch( + util.inspect({ a: { a: { a: { a: {} } } } }, undefined, null, true), + /Object/ +); { const showHidden = true; @@ -1467,13 +1469,13 @@ if (typeof Symbol !== 'undefined') { // Set single option through property assignment. util.inspect.defaultOptions.maxArrayLength = null; - assert(!/1 more item/.test(util.inspect(arr))); + assert.doesNotMatch(util.inspect(arr), /1 more item/); util.inspect.defaultOptions.maxArrayLength = oldOptions.maxArrayLength; - assert(/1 more item/.test(util.inspect(arr))); + assert.match(util.inspect(arr), /1 more item/); util.inspect.defaultOptions.depth = null; - assert(!/Object/.test(util.inspect(obj))); + assert.doesNotMatch(util.inspect(obj), /Object/); util.inspect.defaultOptions.depth = oldOptions.depth; - assert(/Object/.test(util.inspect(obj))); + assert.match(util.inspect(obj), /Object/); assert.strictEqual( JSON.stringify(util.inspect.defaultOptions), JSON.stringify(oldOptions) @@ -1481,11 +1483,11 @@ if (typeof Symbol !== 'undefined') { // Set multiple options through object assignment. util.inspect.defaultOptions = { maxArrayLength: null, depth: 2 }; - assert(!/1 more item/.test(util.inspect(arr))); - assert(/Object/.test(util.inspect(obj))); + assert.doesNotMatch(util.inspect(arr), /1 more item/); + assert.match(util.inspect(obj), /Object/); util.inspect.defaultOptions = oldOptions; - assert(/1 more item/.test(util.inspect(arr))); - assert(/Object/.test(util.inspect(obj))); + assert.match(util.inspect(arr), /1 more item/); + assert.match(util.inspect(obj), /Object/); assert.strictEqual( JSON.stringify(util.inspect.defaultOptions), JSON.stringify(oldOptions) @@ -2183,12 +2185,12 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'"); value.foo = 'bar'; let res = util.inspect(value); assert.notStrictEqual(res, expectedWithoutProto); - assert(/foo: 'bar'/.test(res), res); + assert.match(res, /foo: 'bar'/); delete value.foo; value[Symbol('foo')] = 'yeah'; res = util.inspect(value); assert.notStrictEqual(res, expectedWithoutProto); - assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res); + assert.match(res, /\[Symbol\(foo\)]: 'yeah'/); }); assert.strictEqual(inspect(1n), '1n'); diff --git a/test/parallel/test-util-internal.js b/test/parallel/test-util-internal.js index cd38f3e7c57f44..36d65e54d5b6ca 100644 --- a/test/parallel/test-util-internal.js +++ b/test/parallel/test-util-internal.js @@ -33,4 +33,4 @@ try { getHiddenValue(err, kArrowMessagePrivateSymbolIndex); } -assert(/bad_syntax\.js:1/.test(arrowMessage)); +assert.match(arrowMessage, /bad_syntax\.js:1/); diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index bcfbb327bf72e8..9f2d7fd03af93a 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -22,7 +22,6 @@ 'use strict'; require('../common'); const assert = require('assert'); -const { inspect } = require('util'); const vm = require('vm'); const Script = vm.Script; let script = new Script('"passed";'); @@ -58,8 +57,7 @@ try { vm.runInContext('throw new Error()', context, 'expected-filename.js'); } catch (e) { gh1140Exception = e; - assert.ok(/expected-filename/.test(e.stack), - `expected appearance of filename in Error stack: ${inspect(e)}`); + assert.match(e.stack, /expected-filename/); } // This is outside of catch block to confirm catch block ran. assert.strictEqual(gh1140Exception.toString(), 'Error'); diff --git a/test/parallel/test-vm-syntax-error-stderr.js b/test/parallel/test-vm-syntax-error-stderr.js index dd0667c65302ae..d0cba338ce978a 100644 --- a/test/parallel/test-vm-syntax-error-stderr.js +++ b/test/parallel/test-vm-syntax-error-stderr.js @@ -19,7 +19,7 @@ let output = ''; p.stderr.on('data', (data) => output += data); p.stderr.on('end', common.mustCall(() => { - assert(/BEGIN CERT/.test(output)); - assert(/^\s+\^/m.test(output)); - assert(/Invalid left-hand side expression in prefix operation/.test(output)); + assert.match(output, /BEGIN CERT/); + assert.match(output, /^\s+\^/m); + assert.match(output, /Invalid left-hand side expression in prefix operation/); })); diff --git a/test/parallel/test-worker-esm-missing-main.js b/test/parallel/test-worker-esm-missing-main.js index 07bfb6a0276cd5..51dba34a7916c7 100644 --- a/test/parallel/test-worker-esm-missing-main.js +++ b/test/parallel/test-worker-esm-missing-main.js @@ -12,5 +12,5 @@ const worker = new Worker(missing); worker.on('error', common.mustCall((err) => { // eslint-disable-next-line node-core/no-unescaped-regexp-dot - assert(/Cannot find module .+does-not-exist.js/.test(err.message), err); + assert.match(err.message, /Cannot find module .+does-not-exist.js/); })); diff --git a/test/parallel/test-worker-exit-code.js b/test/parallel/test-worker-exit-code.js index db8986f9ef6c92..bfa3df924bd71c 100644 --- a/test/parallel/test-worker-exit-code.js +++ b/test/parallel/test-worker-exit-code.js @@ -36,8 +36,7 @@ function parent() { if (error) { w.on('error', common.mustCall((err) => { console.log(err); - assert(error.test(err), - `wrong error for ${arg}\nexpected:${error} but got:${err}`); + assert.match(String(err), error); })); } w.postMessage(arg); diff --git a/test/parallel/test-worker-uncaught-exception-async.js b/test/parallel/test-worker-uncaught-exception-async.js index 8126c89192e206..78ad88d9dd903b 100644 --- a/test/parallel/test-worker-uncaught-exception-async.js +++ b/test/parallel/test-worker-uncaught-exception-async.js @@ -10,7 +10,7 @@ if (!process.env.HAS_STARTED_WORKER) { w.on('message', common.mustNotCall()); w.on('error', common.mustCall((err) => { console.log(err.message); - assert(/^Error: foo$/.test(err)); + assert.match(String(err), /^Error: foo$/); })); w.on('exit', common.mustCall((code) => { // uncaughtException is code 1 diff --git a/test/parallel/test-worker-uncaught-exception.js b/test/parallel/test-worker-uncaught-exception.js index 43a41ca30dd2fb..2176779159205b 100644 --- a/test/parallel/test-worker-uncaught-exception.js +++ b/test/parallel/test-worker-uncaught-exception.js @@ -10,7 +10,7 @@ if (!process.env.HAS_STARTED_WORKER) { w.on('message', common.mustNotCall()); w.on('error', common.mustCall((err) => { console.log(err.message); - assert(/^Error: foo$/.test(err)); + assert.match(String(err), /^Error: foo$/); })); w.on('exit', common.mustCall((code) => { // uncaughtException is code 1 diff --git a/test/parallel/test-zlib-dictionary-fail.js b/test/parallel/test-zlib-dictionary-fail.js index ccec8d9d2c7245..269b733e2c6d56 100644 --- a/test/parallel/test-zlib-dictionary-fail.js +++ b/test/parallel/test-zlib-dictionary-fail.js @@ -31,7 +31,7 @@ const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]); const stream = zlib.createInflate(); stream.on('error', common.mustCall(function(err) { - assert(/Missing dictionary/.test(err.message)); + assert.match(err.message, /Missing dictionary/); })); stream.write(input); @@ -41,7 +41,7 @@ const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]); const stream = zlib.createInflate({ dictionary: Buffer.from('fail') }); stream.on('error', common.mustCall(function(err) { - assert(/Bad dictionary/.test(err.message)); + assert.match(err.message, /Bad dictionary/); })); stream.write(input); @@ -53,7 +53,7 @@ const input = Buffer.from([0x78, 0xBB, 0x04, 0x09, 0x01, 0xA5]); stream.on('error', common.mustCall(function(err) { // It's not possible to separate invalid dict and invalid data when using // the raw format - assert(/invalid/.test(err.message)); + assert.match(err.message, /invalid/); })); stream.write(input); diff --git a/test/parallel/test-zlib-truncated.js b/test/parallel/test-zlib-truncated.js index bcd55923c9999c..8e6768c21d0408 100644 --- a/test/parallel/test-zlib-truncated.js +++ b/test/parallel/test-zlib-truncated.js @@ -45,7 +45,7 @@ const errMessage = /unexpected end of file/; // Async truncated input test zlib[methods.decomp](truncated, function(err, result) { - assert(errMessage.test(err.message)); + assert.match(err.message, errMessage); }); const syncFlushOpt = { finishFlush: zlib.constants.Z_SYNC_FLUSH }; diff --git a/test/pummel/test-regress-GH-892.js b/test/pummel/test-regress-GH-892.js index d5e8cc0215635c..a873c60663251b 100644 --- a/test/pummel/test-regress-GH-892.js +++ b/test/pummel/test-regress-GH-892.js @@ -58,7 +58,7 @@ function makeRequest() { const child = spawn(process.execPath, args); child.on('exit', function(code) { - assert.ok(/DONE/.test(stderrBuffer)); + assert.match(stderrBuffer, /DONE/); assert.strictEqual(code, 0); }); diff --git a/test/sequential/test-cli-syntax-bad.js b/test/sequential/test-cli-syntax-bad.js index 319746adfb670e..5c87bf11419af6 100644 --- a/test/sequential/test-cli-syntax-bad.js +++ b/test/sequential/test-cli-syntax-bad.js @@ -39,7 +39,7 @@ const syntaxErrorRE = /^SyntaxError: \b/m; assert.strictEqual(stdout, ''); // Stderr should have a syntax error message - assert(syntaxErrorRE.test(stderr), `${syntaxErrorRE} === ${stderr}`); + assert.match(stderr, syntaxErrorRE); // stderr should include the filename assert(stderr.startsWith(file), `${stderr} starts with ${file}`); diff --git a/test/sequential/test-cli-syntax-file-not-found.js b/test/sequential/test-cli-syntax-file-not-found.js index 6a4c6338311d58..61f84d8e71624d 100644 --- a/test/sequential/test-cli-syntax-file-not-found.js +++ b/test/sequential/test-cli-syntax-file-not-found.js @@ -31,7 +31,7 @@ const notFoundRE = /^Error: Cannot find module/m; assert.strictEqual(stdout, ''); // `stderr` should have a module not found error message. - assert(notFoundRE.test(stderr), `${notFoundRE} === ${stderr}`); + assert.match(stderr, notFoundRE); assert.strictEqual(err.code, 1, `code ${err.code} !== 1 for error:\n\n${err}`); diff --git a/test/sequential/test-cli-syntax-require.js b/test/sequential/test-cli-syntax-require.js index c309b1f4556c3f..e97eb5953aac0b 100644 --- a/test/sequential/test-cli-syntax-require.js +++ b/test/sequential/test-cli-syntax-require.js @@ -27,7 +27,7 @@ const syntaxErrorRE = /^SyntaxError: \b/m; assert.strictEqual(stdout, ''); // stderr should have a syntax error message - assert(syntaxErrorRE.test(stderr), `${syntaxErrorRE} === ${stderr}`); + assert.match(stderr, syntaxErrorRE); // stderr should include the filename assert(stderr.startsWith(file), `${stderr} starts with ${file}`); diff --git a/test/sequential/test-deprecation-flags.js b/test/sequential/test-deprecation-flags.js index 61a3d84ecefb78..30ac4a605ee8ce 100644 --- a/test/sequential/test-deprecation-flags.js +++ b/test/sequential/test-deprecation-flags.js @@ -44,7 +44,7 @@ execFile(node, normal, function(er, stdout, stderr) { console.error('normal: show deprecation warning'); assert.strictEqual(er, null); assert.strictEqual(stdout, ''); - assert(/this function is deprecated/.test(stderr)); + assert.match(stderr, /this function is deprecated/); console.log('normal ok'); }); @@ -62,8 +62,8 @@ execFile(node, traceDep, function(er, stdout, stderr) { assert.strictEqual(stdout, ''); const stack = stderr.trim().split('\n'); // Just check the top and bottom. - assert(/this function is deprecated/.test(stack[1])); - assert(/This is deprecated/.test(stack[0])); + assert.match(stack[1], /this function is deprecated/); + assert.match(stack[0], /This is deprecated/); console.log('trace ok'); }); @@ -71,18 +71,18 @@ execFile(node, [depUserlandFunction], function(er, stdout, stderr) { console.error('normal: testing deprecated userland function'); assert.strictEqual(er, null); assert.strictEqual(stdout, ''); - assert(/deprecatedFunction is deprecated/.test(stderr)); + assert.match(stderr, /deprecatedFunction is deprecated/); console.error('normal: ok'); }); execFile(node, [depUserlandClass], function(er, stdout, stderr) { assert.strictEqual(er, null); assert.strictEqual(stdout, ''); - assert(/deprecatedClass is deprecated/.test(stderr)); + assert.match(stderr, /deprecatedClass is deprecated/); }); execFile(node, [depUserlandSubClass], function(er, stdout, stderr) { assert.strictEqual(er, null); assert.strictEqual(stdout, ''); - assert(/deprecatedClass is deprecated/.test(stderr)); + assert.match(stderr, /deprecatedClass is deprecated/); }); diff --git a/test/sequential/test-fs-stat-sync-overflow.js b/test/sequential/test-fs-stat-sync-overflow.js index 9c9109989a19c3..8855c374bf7d2b 100644 --- a/test/sequential/test-fs-stat-sync-overflow.js +++ b/test/sequential/test-fs-stat-sync-overflow.js @@ -37,5 +37,5 @@ const cmd = `"${process.execPath}" "${fixturesDir}/test-fs-stat-sync-overflow.js"`; exec(cmd, function(err, stdout, stderr) { - assert(/RangeError: Maximum call stack size exceeded/.test(stderr)); + assert.match(stderr, /RangeError: Maximum call stack size exceeded/); }); diff --git a/test/sequential/test-heapdump-flag.js b/test/sequential/test-heapdump-flag.js index 65401b9d7165ff..93612a9319f7ed 100644 --- a/test/sequential/test-heapdump-flag.js +++ b/test/sequential/test-heapdump-flag.js @@ -24,7 +24,7 @@ if (process.argv[2] === 'child') { assert.strictEqual(files.length, 2); for (let i = 0; i < files.length; i++) { - assert(/^Heap\..+\.heapsnapshot$/.test(files[i])); + assert.match(files[i], /^Heap\..+\.heapsnapshot$/); JSON.parse(fs.readFileSync(files[i])); } })(); diff --git a/test/sequential/test-http-econnrefused.js b/test/sequential/test-http-econnrefused.js index 5650e7430859ca..e1abde32bd81b1 100644 --- a/test/sequential/test-http-econnrefused.js +++ b/test/sequential/test-http-econnrefused.js @@ -74,26 +74,26 @@ function afterPing(result) { const successRE = /success/; switch (responses.length) { case 2: - assert.ok(ECONNREFUSED_RE.test(responses[0])); - assert.ok(ECONNREFUSED_RE.test(responses[1])); + assert.match(responses[0], ECONNREFUSED_RE); + assert.match(responses[1], ECONNREFUSED_RE); serverOn(); break; case 4: - assert.ok(successRE.test(responses[2])); - assert.ok(successRE.test(responses[3])); + assert.match(responses[2], successRE); + assert.match(responses[3], successRE); serverOff(); break; case 6: - assert.ok(ECONNREFUSED_RE.test(responses[4])); - assert.ok(ECONNREFUSED_RE.test(responses[5])); + assert.match(responses[4], ECONNREFUSED_RE); + assert.match(responses[5], ECONNREFUSED_RE); serverOn(); break; case 8: - assert.ok(successRE.test(responses[6])); - assert.ok(successRE.test(responses[7])); + assert.match(responses[6], successRE); + assert.match(responses[7], successRE); server.close(); // We should go to process.on('exit') from here. break; diff --git a/test/sequential/test-inspector-port-zero.js b/test/sequential/test-inspector-port-zero.js index 1683394a1dd4a3..3f55e2777cc39d 100644 --- a/test/sequential/test-inspector-port-zero.js +++ b/test/sequential/test-inspector-port-zero.js @@ -19,7 +19,7 @@ function test(arg, port = '') { proc.stderr.on('close', (hadErr) => assert(!hadErr)); proc.stderr.on('data', () => { if (!stderr.includes('\n')) return; - assert(/Debugger listening on (.+)/.test(stderr)); + assert.match(stderr, /Debugger listening on (.+)/); port = new URL(RegExp.$1).port; assert(+port > 0); }); diff --git a/test/sequential/test-inspector.js b/test/sequential/test-inspector.js index 84e0bb1c5e0c44..a62013ebb46896 100644 --- a/test/sequential/test-inspector.js +++ b/test/sequential/test-inspector.js @@ -32,8 +32,8 @@ function checkVersion(response) { function checkBadPath(err) { assert(err instanceof SyntaxError); - assert(/Unexpected token/.test(err.message), err.message); - assert(/WebSockets request was expected/.test(err.body), err.body); + assert.match(err.message, /Unexpected token/); + assert.match(err.body, /WebSockets request was expected/); } function checkException(message) { diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js index 6fb24f2f0210a9..ebbbcbb6c937ef 100644 --- a/test/sequential/test-module-loading.js +++ b/test/sequential/test-module-loading.js @@ -214,9 +214,9 @@ assert.throws( (e) => { // Not a real .node module, but we know we require'd the right thing. if (common.isOpenBSD) { // OpenBSD errors with non-ELF object error - assert.ok(/File not an ELF object/.test(e.message.replace(backslash, '/'))); + assert.match(e.message, /File not an ELF object/); } else { - assert.ok(/file3\.node/.test(e.message.replace(backslash, '/'))); + assert.match(e.message, /file3\.node/); } return true; } @@ -229,9 +229,9 @@ assert.throws( () => require(`${loadOrder}file7`), (e) => { if (common.isOpenBSD) { - assert.ok(/File not an ELF object/.test(e.message.replace(backslash, '/'))); + assert.match(e.message, /File not an ELF object/); } else { - assert.ok(/file7\/index\.node/.test(e.message.replace(backslash, '/'))); + assert.match(e.message.replace(backslash, '/'), /file7\/index\.node/); } return true; } diff --git a/test/sequential/test-process-warnings.js b/test/sequential/test-process-warnings.js index 2d4700561e404a..f4457e137ec08c 100644 --- a/test/sequential/test-process-warnings.js +++ b/test/sequential/test-process-warnings.js @@ -17,20 +17,20 @@ execFile(node, normal, function(er, stdout, stderr) { // Show Process Warnings assert.strictEqual(er, null); assert.strictEqual(stdout, ''); - assert(warningMessage.test(stderr)); + assert.match(stderr, warningMessage); }); execFile(node, noWarn, function(er, stdout, stderr) { // Hide Process Warnings assert.strictEqual(er, null); assert.strictEqual(stdout, ''); - assert(!warningMessage.test(stderr)); + assert.doesNotMatch(stderr, warningMessage); }); execFile(node, traceWarn, function(er, stdout, stderr) { // Show Warning Trace assert.strictEqual(er, null); assert.strictEqual(stdout, ''); - assert(warningMessage.test(stderr)); - assert(/at Object\.\s\(.+warnings\.js:3:9\)/.test(stderr)); + assert.match(stderr, warningMessage); + assert.match(stderr, /at Object\.\s\(.+warnings\.js:3:9\)/); }); diff --git a/test/sequential/test-vm-timeout-rethrow.js b/test/sequential/test-vm-timeout-rethrow.js index c38460c4c89925..d4682fe9752abc 100644 --- a/test/sequential/test-vm-timeout-rethrow.js +++ b/test/sequential/test-vm-timeout-rethrow.js @@ -39,6 +39,6 @@ if (process.argv[2] === 'child') { }); process.on('exit', function() { - assert.ok(/Script execution timed out after 1ms/.test(err)); + assert.match(err, /Script execution timed out after 1ms/); }); } diff --git a/test/tick-processor/test-tick-processor-polyfill-brokenfile.js b/test/tick-processor/test-tick-processor-polyfill-brokenfile.js index 926c96e4d7e6cd..e5e13fd3db122f 100644 --- a/test/tick-processor/test-tick-processor-polyfill-brokenfile.js +++ b/test/tick-processor/test-tick-processor-polyfill-brokenfile.js @@ -52,8 +52,8 @@ function runPolyfill(content) { [ '--prof-process', LOG_FILE, ]); - assert(WARN_REG_EXP.test(child.stderr.toString())); - assert(WARN_DETAIL_REG_EXP.test(child.stderr.toString())); + assert.match(child.stderr.toString(), WARN_REG_EXP); + assert.match(child.stderr.toString(), WARN_DETAIL_REG_EXP); assert.strictEqual(child.status, 0); }