Title: `t.skip` does not invoke `test.afterEach` · Issue #61462 · nodejs/node · GitHub
Open Graph Title: `t.skip` does not invoke `test.afterEach` · Issue #61462 · nodejs/node
X Title: `t.skip` does not invoke `test.afterEach` · Issue #61462 · nodejs/node
Description: 'use strict' const test = require('node:test') test.afterEach(() => { process._rawDebug('!!! afterEach') }) test('one', (t) => { t.assert.ok('one is good') }) test('two', (t) => { if (process.env.TEST_SKIP === 'false') { t.assert.ok('two...
Open Graph Description: 'use strict' const test = require('node:test') test.afterEach(() => { process._rawDebug('!!! afterEach') }) test('one', (t) => { t.assert.ok('one is good') }) test('two', (t) => { if (process.env.T...
X Description: 'use strict' const test = require('node:test') test.afterEach(() => { process._rawDebug('!!! afterEach') }) test('one', (t) => { t.assert.ok('one is good...
Opengraph URL: https://github.com/nodejs/node/issues/61462
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`t.skip` does not invoke `test.afterEach`","articleBody":"```js\n'use strict'\n\nconst test = require('node:test')\n\ntest.afterEach(() =\u003e {\n process._rawDebug('!!! afterEach')\n})\n\ntest('one', (t) =\u003e {\n t.assert.ok('one is good')\n})\n\ntest('two', (t) =\u003e {\n if (process.env.TEST_SKIP === 'false') {\n t.assert.ok('two is good')\n } else {\n t.skip('two gets skipped after some logic')\n }\n})\n```\n\nI expect that `!!! afterEach` will be printed twice when this test suite is run. However, on Node.js 20.20.0 and 24.13.0, that is not the case. Instead, the result is:\n\n```sh\n❯ node index.js\n!!! afterEach\n✔ one (1.120209ms)\n﹣ two (0.08625ms) # two gets skipped after some logic\nℹ tests 2\nℹ suites 0\nℹ pass 1\nℹ fail 0\nℹ cancelled 0\nℹ skipped 1\nℹ todo 0\nℹ duration_ms 5.285417\n```\n\nThis is a problem when the test being skipped depends upon logic internal to the test. As an example, we may have a test setup like:\n\n```js\ntest.beforeEach((ctx) =\u003e {\n ctx.testNamespace = {\n foo: 'bar'\n // other more complicated bootstrapping\n }\n})\n\ntest.afterEach((ctx) =\u003e {\n cleanUp(ctx.testNamespace.somethingThatNeedsCleaningAfterEachTest)\n})\n\ntest('something', (t) =\u003e {\n const { foo } = t.testNamespace\n if (foo !== 'bar') return t.skip('reason')\n t.assert.ok('whatever')\n})\n```","author":{"url":"https://github.com/jsumners-nr","@type":"Person","name":"jsumners-nr"},"datePublished":"2026-01-21T14:32:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/61462/node/issues/61462"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c8ced48f-9aab-b48c-de07-a8b2b283c670 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C192:2EE522:C7DAC2:108503D:6A4C469E |
| html-safe-nonce | bd8fc17ac9ef688ddd5cfdd8f8f01073009c3b75abb54f68cf20c0e16f85ab25 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTkyOjJFRTUyMjpDN0RBQzI6MTA4NTAzRDo2QTRDNDY5RSIsInZpc2l0b3JfaWQiOiI4OTg1OTAwMjYwMzAwNDQxMjQ2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 57a9517db65459770ffe79bf9b06a24c1b6ac24c3575c475378a192e22b484f4 |
| hovercard-subject-tag | issue:3838539653 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/61462/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d2b0ed157233f574a08b5ca6ca2a1d7a7a95b09f86aae225ab0fda7be37d6da1/nodejs/node/issues/61462 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d2b0ed157233f574a08b5ca6ca2a1d7a7a95b09f86aae225ab0fda7be37d6da1/nodejs/node/issues/61462 |
| og:image:alt | 'use strict' const test = require('node:test') test.afterEach(() => { process._rawDebug('!!! afterEach') }) test('one', (t) => { t.assert.ok('one is good') }) test('two', (t) => { if (process.env.T... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jsumners-nr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3996b3b83990e134be6c099ab9a7f48f140ae80f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width