Skip to content

test_runner: add mock-timers support for AbortSignal.timeout#60751

Open
DeveloperViraj wants to merge 4 commits intonodejs:mainfrom
DeveloperViraj:fix/mock-timers-abortsignal-timeout-v3
Open

test_runner: add mock-timers support for AbortSignal.timeout#60751
DeveloperViraj wants to merge 4 commits intonodejs:mainfrom
DeveloperViraj:fix/mock-timers-abortsignal-timeout-v3

Conversation

@DeveloperViraj
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

codecov bot commented Nov 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.62%. Comparing base (3330e5c) to head (177ab11).
⚠️ Report is 1054 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60751      +/-   ##
==========================================
+ Coverage   88.54%   89.62%   +1.08%     
==========================================
  Files         703      706       +3     
  Lines      208252   219181   +10929     
  Branches    40153    41988    +1835     
==========================================
+ Hits       184391   196441   +12050     
+ Misses      15869    14617    -1252     
- Partials     7992     8123     +131     
Files with missing lines Coverage Δ
lib/internal/test_runner/mock/mock_timers.js 98.76% <100.00%> (+0.07%) ⬆️

... and 438 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
Copy Markdown
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
Copy Markdown
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 thread lib/internal/test_runner/mock/mock_timers.js Outdated
Comment thread lib/internal/test_runner/mock/mock_timers.js
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

Comment thread lib/internal/test_runner/mock/mock_timers.js
Comment thread test/parallel/test-mock-timers-abortsignal-timeout.js Outdated
Comment thread test/parallel/test-mock-timers-abortsignal-timeout.js Outdated
@DeveloperViraj
Copy link
Copy Markdown
Author

Hi @Renegade334

I’ve addressed the requested changes:

Reverted the EnableOptions typedef to the narrower SupportedApis version

Updated the AbortSignal.timeout test to use the public mock API from node:test

Removed internal imports and the unused variable as suggested

Everything should now align with the review feedback.
Please let me know if anything else needs adjusting.

Comment thread test/parallel/test-mock-timers-abortsignal-timeout.js Outdated
Comment thread lib/internal/test_runner/mock/mock_timers.js
@JakobJingleheimer
Copy link
Copy Markdown
Member

@DeveloperViraj I think this is very close to landing. One of the items from René #60751 (comment) I consider not a nit. Could you take a look at it? 🙂

@Renegade334
Copy link
Copy Markdown
Member

Let's get this over the line.

Co-authored-by: René <contact.9a5d6388@renegade334.me.uk>
@Renegade334 Renegade334 added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 20, 2026
@Renegade334 Renegade334 moved this from Stuck to In Progress in Test Runner Board Apr 20, 2026
@nodejs-github-bot

This comment was marked as outdated.

@Renegade334 Renegade334 added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Apr 20, 2026
@Renegade334 Renegade334 self-assigned this Apr 20, 2026
@Renegade334 Renegade334 force-pushed the fix/mock-timers-abortsignal-timeout-v3 branch from 1f622a9 to 177ab11 Compare April 20, 2026 18:13
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. test_runner Issues and PRs related to the test runner subsystem.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

mock.timers ignores AbortSignal.timeout

6 participants