Skip to content

test_runner: run afterEach for runtime t.skip()#61525

Merged
nodejs-github-bot merged 2 commits intonodejs:mainfrom
igor-shevelenkov:main
Feb 26, 2026
Merged

test_runner: run afterEach for runtime t.skip()#61525
nodejs-github-bot merged 2 commits intonodejs:mainfrom
igor-shevelenkov:main

Conversation

@igor-shevelenkov
Copy link
Contributor

Ensure afterEach runs when a test is skipped at runtime (t.skip()), while keeping static { skip: true } behavior unchanged.

Runtime t.skip() previously set skipped and prevented afterEach, even if beforeEach ran.
This left resources uncleaned and differed from user expectations.

Fixes: #61462

@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 Jan 26, 2026
Copy link

@jsumners-nr jsumners-nr left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@ljharb
Copy link
Member

ljharb commented Jan 26, 2026

This looks fine, but t.skip() shouldn't be marking the overarching test as skipped at all - its purpose is to generate a string comment that will show up as a skipped assertion.

@igor-shevelenkov
Copy link
Contributor Author

Thanks @ljharb. I see from tape-testing/tape#545 that in tape, t.skip() is designed as an assertion-level skip. Not a test-level skip. That aligns with TAP semantics.
However, Node's test runner has established t.skip() as a test-level runtime skip. It marks the whole test as skipped, not just an assertion. If we choose to change that i think it'll be a breaking change.
I think something like a separate t.skipAssertion() method would be better

Comment on lines +32 to +36
process.on('exit', () => {
assert.strictEqual(beforeEachTotal, 2);
assert.strictEqual(afterEachRuntimeSkip, 1);
assert.strictEqual(afterEachTotal, 2);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need the beforeEachTotal or afterEachTotal variables. The common.mustCall()s will enforce those for you.

@ljharb
Copy link
Member

ljharb commented Jan 26, 2026

@igor-shevelenkov deviating from TAP semantics seems like a pretty big design issue, but fair that it'd be a breaking change. I'd still suggest making it (in a different PR ofc)

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.73%. Comparing base (abddfc9) to head (2127b04).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #61525   +/-   ##
=======================================
  Coverage   89.72%   89.73%           
=======================================
  Files         676      676           
  Lines      205988   205990    +2     
  Branches    39490    39489    -1     
=======================================
+ Hits       184830   184846   +16     
+ Misses      13295    13291    -4     
+ Partials     7863     7853   -10     
Files with missing lines Coverage Δ
lib/internal/test_runner/test.js 97.28% <100.00%> (+<0.01%) ⬆️

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

@igor-shevelenkov
Copy link
Contributor Author

@ljharb i'll research this topic, pros and cons and come back with possible solutions

@pmarchini
Copy link
Member

@igor-shevelenkov deviating from TAP semantics seems like a pretty big design issue, but fair that it'd be a breaking change. I'd still suggest making it (in a different PR ofc)

I think that this might be a good discussion point for the next Node.js Test Runner Bi-Weekly Meeting 👀

cc @nodejs/test_runner

@cjihrig
Copy link
Contributor

cjihrig commented Jan 27, 2026

FWIW, I would strongly advise against letting TAP influence any decisions outside of the TAP reporter itself.

@ljharb
Copy link
Member

ljharb commented Jan 27, 2026

@cjihrig true, it's not TAP specifically, it's the prior art of pre-existing TAP-generating test frameworks, most of which (possibly all) don't have a dynamic mechanism to skip a test from inside the test that's already begun.

@cjihrig
Copy link
Contributor

cjihrig commented Jan 27, 2026

I can't speak to whether or not anything else supports them, but they have been there for three and a half years (#43730) at this point. It doesn't seem like a good idea to break users who are depending on it at this point when this seems to be a straightforward fix.

@JakobJingleheimer
Copy link
Member

This was discussed in a couple test runner team meetings, and we reached consensus that this PR is 👍 I read through the remaining comments and I see no outstanding items that weren't addressed in the meeting. I'm adding author-ready and will land in 2 days assuming nobody speaks out.

@JakobJingleheimer JakobJingleheimer added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 23, 2026
@JakobJingleheimer JakobJingleheimer added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 25, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Feb 25, 2026
@nodejs-github-bot

This comment has been minimized.

@JakobJingleheimer JakobJingleheimer added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Feb 25, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 25, 2026
@nodejs-github-bot
Copy link
Collaborator

@JakobJingleheimer JakobJingleheimer added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 25, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Feb 25, 2026
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/61525
✔  Done loading data for nodejs/node/pull/61525
----------------------------------- PR info ------------------------------------
Title      test_runner: run afterEach for runtime t.skip() (#61525)
   ⚠  Could not retrieve the email or name of the PR author's from user's GitHub profile!
Branch     igor-shevelenkov:main -> nodejs:main
Labels     author ready, needs-ci, commit-queue-squash, test_runner
Commits    4
 - test_runner: run afterEach on runtime skip
 - Merge branch 'nodejs:main' into main
 - test: track beforeEach calls in runtime-skip test
 - Merge branch 'nodejs:main' into main
Committers 2
 - Igor <igorshevelenkov4@gmail.com>
 - GitHub <noreply@github.com>
PR-URL: https://github.com/nodejs/node/pull/61525
Fixes: https://github.com/nodejs/node/issues/61462
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/61525
Fixes: https://github.com/nodejs/node/issues/61462
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Mon, 26 Jan 2026 10:50:20 GMT
   ✔  Approvals: 4
   ✔  - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/61525#pullrequestreview-3707520585
   ✔  - Chemi Atlow (@atlowChemi): https://github.com/nodejs/node/pull/61525#pullrequestreview-3713408859
   ✔  - Moshe Atlow (@MoLow): https://github.com/nodejs/node/pull/61525#pullrequestreview-3718102648
   ✔  - Pietro Marchini (@pmarchini): https://github.com/nodejs/node/pull/61525#pullrequestreview-3846531064
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-02-25T18:44:10Z: https://ci.nodejs.org/job/node-test-pull-request/71459/
- Querying data for job/node-test-pull-request/71459/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 61525
From https://github.com/nodejs/node
 * branch                  refs/pull/61525/merge -> FETCH_HEAD
✔  Fetched commits as 764e9a756082..3a29ef0407fa
--------------------------------------------------------------------------------
Auto-merging lib/internal/test_runner/test.js
error: commit 332f669ee2e3a7674327867145e02ac3d5053846 is a merge but no -m option was given.
fatal: cherry-pick failed
[main e85a169712] test_runner: run afterEach on runtime skip
 Author: Igor <igorshevelenkov4@gmail.com>
 Date: Mon Jan 26 13:06:41 2026 +0300
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 test/parallel/test-runner-aftereach-runtime-skip.js
   ✘  Failed to apply patches
https://github.com/nodejs/node/actions/runs/22413356910

@JakobJingleheimer
Copy link
Member

Uuuugh. @igor-shevelenkov I think there's a conflict with main. Could you try rebasing your branch onto the latest from main?

If that doesn't produce a conflict, it's something else (don't push).

If it does produce a conflict, could you resolve it and force-push? I'll have to re-run CI etc.

@igor-shevelenkov
Copy link
Contributor Author

@JakobJingleheimer, I rebased my branch onto the latest main and got no conflicts.

@JakobJingleheimer
Copy link
Member

Ahh, I see the problem:

image

Our tooling does not support merges. The merge commits will have to be removed. The easiest way is:

  1. create a new branch (with the same name as the original) off of nodejs/node's latest main
  2. cherry-pick 062059d and 9979c2f
  3. force-push to the original remote branch (overwriting it)

I'll re-run CI etc when that's done.

Signed-off-by: Igor <igorshevelenkov4@gmail.com>
Increment a beforeEach counter and assert it runs twice when a test
is skipped at runtime.

Signed-off-by: Igor <igorshevelenkov4@gmail.com>
@JakobJingleheimer JakobJingleheimer added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Feb 26, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 26, 2026
@JakobJingleheimer JakobJingleheimer added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 26, 2026
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Feb 26, 2026
@github-actions
Copy link
Contributor

Failed to start CI
- Validating Jenkins credentials
✔  Jenkins credentials valid
- Starting PR CI job
✘  Failed to start PR CI: 200 OK
https://github.com/nodejs/node/actions/runs/22451470137

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@avivkeller avivkeller added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 26, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 26, 2026
@nodejs-github-bot nodejs-github-bot merged commit 2ae6d8f into nodejs:main Feb 26, 2026
70 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 2ae6d8f

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. 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. request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

t.skip does not invoke test.afterEach

10 participants