From 8636f9df2697fdea1bef20e9343f525970fc5ee6 Mon Sep 17 00:00:00 2001 From: Ankit-bit-cyber <208ankitkumarssm@gmail.com> Date: Tue, 25 Nov 2025 02:31:10 +0530 Subject: [PATCH] test: replace assert.ok(regex.test()) with assert.match() --- test/common/benchmark.js | 3 +-- test/js-native-api/test_general/testV8Instanceof2.js | 2 +- test/parallel/test-dns-resolver-max-timeout.js | 2 +- test/parallel/test-http2-https-fallback.js | 5 ++++- test/parallel/test-runner-mock-timers-date.js | 5 ++++- test/parallel/test-worker-cpu-usage.js | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/common/benchmark.js b/test/common/benchmark.js index 7211ff8703e0e8..72ad7306d27483 100644 --- a/test/common/benchmark.js +++ b/test/common/benchmark.js @@ -42,8 +42,7 @@ function runBenchmark(name, env) { for (let testIdx = 1; testIdx < splitTests.length - 1; testIdx++) { const lines = splitTests[testIdx].split('\n'); - assert.ok(/.+/.test(lines[0])); - + assert.match(lines[0], /.+/); if (!lines[1].includes('group="')) { assert.strictEqual(lines.length, 2, `benchmark file not running exactly one configuration in test: ${stdout}`); } diff --git a/test/js-native-api/test_general/testV8Instanceof2.js b/test/js-native-api/test_general/testV8Instanceof2.js index a118b5c43294b8..fb29e570bd6cc5 100644 --- a/test/js-native-api/test_general/testV8Instanceof2.js +++ b/test/js-native-api/test_general/testV8Instanceof2.js @@ -304,7 +304,7 @@ function InstanceTest(x, func) { const answer = addon.doInstanceOf(x, func); assert.strictEqual(correct_answers[correct_answer_index], answer); } catch (e) { - assert.ok(/prototype/.test(e)); + assert.match(e, /prototype/); assert.strictEqual(correct_answers[correct_answer_index], except); } correct_answer_index++; diff --git a/test/parallel/test-dns-resolver-max-timeout.js b/test/parallel/test-dns-resolver-max-timeout.js index fff1a705ca4116..b88d5e51bebd1b 100644 --- a/test/parallel/test-dns-resolver-max-timeout.js +++ b/test/parallel/test-dns-resolver-max-timeout.js @@ -21,7 +21,7 @@ const dgram = require('dgram'); try { new dns.Resolver({ maxTimeout }); } catch (e) { - assert.ok(/ERR_OUT_OF_RANGE|ERR_INVALID_ARG_TYPE/i.test(e.code)); + assert.match(e.code, /ERR_OUT_OF_RANGE|ERR_INVALID_ARG_TYPE/i); } }); diff --git a/test/parallel/test-http2-https-fallback.js b/test/parallel/test-http2-https-fallback.js index 32b355f5ec451a..5bc452619f53b2 100644 --- a/test/parallel/test-http2-https-fallback.js +++ b/test/parallel/test-http2-https-fallback.js @@ -165,7 +165,10 @@ function onSession(session, next) { .setEncoding('utf8') .on('data', (chunk) => text += chunk) .on('end', common.mustCall(() => { - assert.ok(/Missing ALPN Protocol, expected `h2` to be available/.test(text)); + assert.match( + text, + /Missing ALPN Protocol, expected `h2` to be available/ + ); cleanup(); })); } diff --git a/test/parallel/test-runner-mock-timers-date.js b/test/parallel/test-runner-mock-timers-date.js index 7cee835eccaba3..5fab9a1f364a9a 100644 --- a/test/parallel/test-runner-mock-timers-date.js +++ b/test/parallel/test-runner-mock-timers-date.js @@ -62,7 +62,10 @@ describe('Mock Timers Date Test Suite', () => { const returned = Date(); // Matches the format: 'Mon Jan 01 1970 00:00:00' // We don't care about the date, just the format - assert.ok(/\w{3}\s\w{3}\s\d{1,2}\s\d{2,4}\s\d{1,2}:\d{2}:\d{2}/.test(returned)); + assert.match( + returned, + /\w{3}\s\w{3}\s\d{1,2}\s\d{2,4}\s\d{1,2}:\d{2}:\d{2}/ + ); }); it('should return the date with different argument calls', (t) => { diff --git a/test/parallel/test-worker-cpu-usage.js b/test/parallel/test-worker-cpu-usage.js index b043f4fbd182f9..666c8f89b69b4e 100644 --- a/test/parallel/test-worker-cpu-usage.js +++ b/test/parallel/test-worker-cpu-usage.js @@ -33,7 +33,7 @@ function check(worker) { try { worker.cpuUsage(value); } catch (e) { - assert.ok(/ERR_OUT_OF_RANGE|ERR_INVALID_ARG_TYPE/i.test(e.code)); + assert.match(e.code, /ERR_OUT_OF_RANGE|ERR_INVALID_ARG_TYPE/i); } }); }