Skip to content

test_runner: use AsyncLocalStorage instead of async_hooks - #66795

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:test-runner-als
Open

mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:test-runner-als

Conversation

@mcollina

@mcollina mcollina commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Track the test that owns the current async context with an AsyncLocalStorage instead of a createHook() init/destroy map, so node:test no longer installs async hooks (including promise hooks) for every run.

Test#runInAsyncScope() enters the test's context directly rather than wrapping AsyncResource#runInAsyncScope(), to avoid adding frames to user stack traces. The snapshot changes drop one <node-internal-frames> line, since that frame now lives in the test runner and is filtered out.

Refs: #61030


AI generated, reviewed by me

Track the test that owns the current async context with an
AsyncLocalStorage instead of a createHook() init/destroy map.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@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 Oct 16, 2026
@mcollina
mcollina requested review from MoLow and atlowChemi and removed request for MoLow October 16, 2026 16:01
@mcollina
mcollina marked this pull request as ready for review October 16, 2026 16:01
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.48%. Comparing base (4096767) to head (ef8d21b).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66795      +/-   ##
==========================================
- Coverage   90.50%   90.48%   -0.02%     
==========================================
  Files         797      797              
  Lines      277652   277656       +4     
  Branches    53345    53337       -8     
==========================================
- Hits       251282   251247      -35     
- Misses      16758    16799      +41     
+ Partials     9612     9610       -2     
Files with missing lines Coverage Δ
lib/internal/test_runner/harness.js 87.32% <100.00%> (-0.81%) ⬇️
lib/internal/test_runner/test.js 97.97% <100.00%> (+0.03%) ⬆️
lib/internal/test_runner/utils.js 66.30% <100.00%> (+0.13%) ⬆️

... and 30 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.

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.

2 participants