Skip to content

Conversation

@Ankit-bit-cyber
Copy link

test: replace assert.ok(regex.test()) with assert.match()

This pull request updates several tests to use assert.match() instead of the older pattern assert.ok(regex.test()). The newer API improves readability, provides clearer assertion errors, and follows the recommended assertion style used across the Node.js test suite.

What this PR changes

  • Replaces occurrences of:
    assert.ok(/pattern/.test(value));
    with:
    assert.match(value, /pattern/);
  • Updates the following test files:
    • test/parallel/test-dns-resolver-max-timeout.js
    • test/parallel/test-worker-cpu-usage.js
    • test/parallel/test-runner-mock-timers-date.js
    • test/parallel/test-http2-https-fallback.js
    • test/js-native-api/test_general/testV8Instanceof2.js
    • test/common/benchmark.js

Why this improvement

  • assert.match() better communicates the intent of regex-based assertions.
  • Produces more helpful and consistent error messages.
  • Aligns with current Node.js testing best practices.
  • Helps gradually remove legacy assertion patterns.

Testing

All updated tests pass locally with:

make -j4 test

Notes

This change is mechanical and does not affect runtime behavior. It only improves code quality within the test suite.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests. labels Nov 24, 2025
@aduh95
Copy link
Contributor

aduh95 commented Nov 24, 2025

Isn't that a duplicate of #60832?

@Ankit-bit-cyber
Copy link
Author

Thank you for pointing that out. I'll review my PR and do changes accordingly.

@github-project-automation github-project-automation bot moved this from Need Triage to Done in Node-API Team Project Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants