Skip to content

Conversation

@DeveloperViraj
Copy link

Fixes: #60509

This PR completes the fix for making AbortSignal.timeout() compatible with
the test runner's mock timers, and adds a regression test to ensure correct
behavior going forward.

What’s included

1. Mock timers fix

  • Added "AbortSignal.timeout" as a discrete mock-timers API target.
  • Implemented dedicated store/restore handlers for the original
    AbortSignal.timeout property (no silent failures).
  • Integrated the mock implementation into the toFake/toReal paths to match
    the design of other mockable timer APIs.
  • Restored documentation comments and internal validation that were
    unintentionally removed earlier.

2. New regression test

  • Added test/parallel/test-mock-timers-abortsignal-timeout.js
  • Verifies that:
    • enabling mock timers with { apis: ['AbortSignal.timeout'] } works
    • mock.tick() correctly triggers abortion after the expected delay

Notes

I created a fresh branch to ensure a clean diff without unrelated changes and
to fully incorporate the feedback from @Renegade334 and @ErickWendel.

Please let me know if you'd like any adjustments to the test or implementation.
Thanks for the clear guidance and review support

@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. test_runner Issues and PRs related to the test runner subsystem. labels Nov 16, 2025
@DeveloperViraj
Copy link
Author

Hi @Renegade334 @ErickWendel 👋

I’ve opened a fresh PR with a clean branch so it’s easier to review.
All the requested changes have been applied, including the dedicated API
target for AbortSignal.timeout and the new regression test.

Please let me know if anything needs adjusting, happy to update it!
Thanks again for the guidance. 🙏

@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

❌ Patch coverage is 76.36364% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.52%. Comparing base (3330e5c) to head (ef06137).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/mock/mock_timers.js 76.36% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60751      +/-   ##
==========================================
- Coverage   88.54%   88.52%   -0.02%     
==========================================
  Files         703      703              
  Lines      208252   208306      +54     
  Branches    40153    40160       +7     
==========================================
+ Hits       184391   184413      +22     
- Misses      15869    15893      +24     
- Partials     7992     8000       +8     
Files with missing lines Coverage Δ
lib/internal/test_runner/mock/mock_timers.js 97.16% <76.36%> (-1.53%) ⬇️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DeveloperViraj DeveloperViraj changed the title test_runner: fix AbortSignal.timeout mock-timers support and add regression test test_runner: add mock-timers support for AbortSignal.timeout Nov 16, 2025
@DeveloperViraj DeveloperViraj force-pushed the fix/mock-timers-abortsignal-timeout-v3 branch 2 times, most recently from 8cbc185 to 1b2d32f Compare November 16, 2025 20:49
@DeveloperViraj
Copy link
Author

I've updated both the implementation and the regression test:

Fixed the missing function name & trailing comma issues in mock_timers.js

Cleaned up unused variables

Ensured the mock AbortSignal.timeout() matches Node.js behavior

Updated the test file to avoid restricted syntax and comply with Node’s linting rules

The PR is ready for the next round of review
Let me know if you’d like any additional adjustments!

Copy link
Member

@Renegade334 Renegade334 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good! Just a couple of recommended tweaks.

Comment on lines 633 to 635
if (NumberIsNaN(delay)) {
throw new ERR_INVALID_ARG_VALUE('delay', delay, 'delay must be a number');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (NumberIsNaN(delay)) {
throw new ERR_INVALID_ARG_VALUE('delay', delay, 'delay must be a number');
}
validateUint32(delay, 'delay', false);

This should use validateUint32() for consistency with AbortSignal.timeout(). (You'll need to add it to the list of imports from internal/validators.)

Comment on lines 62 to 64
/**
* @enum {('setTimeout'|'setInterval'|'setImmediate'|'Date'|'scheduler.wait')[]} Supported timers
*/
Copy link
Member

@Renegade334 Renegade334 Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docblock should be restored, with the addition of 'AbortSignal.timeout' to the list.

Comment on lines 711 to 716
* EnableOptions type:
*
* @typedef {object} EnableOptions
* @property {Array<string>} apis List of timers to enable, defaults to all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* EnableOptions type:
*
* @typedef {object} EnableOptions
* @property {Array<string>} apis List of timers to enable, defaults to all
* @typedef {object} EnableOptions
* @property {SUPPORTED_APIS} apis List of timers to enable, defaults to all

Comment on lines +311 to +320
if (this.#realAbortSignalTimeout) {
ObjectDefineProperty(AbortSignal, 'timeout', this.#realAbortSignalTimeout);
} else {
delete AbortSignal.timeout;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.#realAbortSignalTimeout) {
ObjectDefineProperty(AbortSignal, 'timeout', this.#realAbortSignalTimeout);
} else {
delete AbortSignal.timeout;
}
ObjectDefineProperty(AbortSignal, 'timeout', this.#realAbortSignalTimeout);

AbortSignal.timeout() exists in all supported versions of Node.js, so this conditional is unnecessary; the internal property will always be defined if this code is reached.

Copy link
Contributor

@StefanStojanovic StefanStojanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Make sure you fix issues found by the linter.

@DeveloperViraj DeveloperViraj force-pushed the fix/mock-timers-abortsignal-timeout-v3 branch from 1b2d32f to ef06137 Compare November 17, 2025 12:50
@DeveloperViraj
Copy link
Author

DeveloperViraj commented Nov 17, 2025

All requested updates have now been applied.

Summary of changes:

Updated mock_timers.js according to the reviewer’s feedback

Preserved the required comment and applied all suggested code adjustments

Updated the test file to follow the Node.js test style (including loading common first)

Verified everything locally, all lint issues are resolved

@StefanStojanovic @Renegade334
Please let me know if anything else is needed. Thanks for the review and guidance!

@DeveloperViraj
Copy link
Author

@Renegade334
Just a quick follow-up, I’ve applied all the requested changes and fixed all lint issues locally.
If you get a moment, could you please take another look and let me know if anything else is needed?
Thanks a lot for your time and guidance!

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. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mock.timers ignores AbortSignal.timeout

5 participants