| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a32a598 commit 4890d6b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1152,13 +1152,15 @@ class Test extends AsyncResource { | |||
| 1152 | 1152 | ctx.plan(this.expectedAssertions); | |
| 1153 | 1153 | } | |
| 1154 | 1154 | ||
| 1155 | + const wasSkippedBeforeRun = this.skipped; | ||
| 1156 | + | ||
| 1155 | 1157 | const after = async () => { | |
| 1156 | 1158 | if (this.hooks.after.length > 0) { | |
| 1157 | 1159 | await this.runHook('after', hookArgs); | |
| 1158 | 1160 | } | |
| 1159 | 1161 | }; | |
| 1160 | 1162 | const afterEach = runOnce(async () => { | |
| 1161 | - if (this.parent?.hooks.afterEach.length > 0 && !this.skipped) { | ||
| 1163 | + if (this.parent?.hooks.afterEach.length > 0 && !wasSkippedBeforeRun) { | ||
| 1162 | 1164 | await this.parent.runHook('afterEach', hookArgs); | |
| 1163 | 1165 | } | |
| 1164 | 1166 | }, kRunOnceOptions); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,36 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('node:assert'); | ||
| 5 | + const { beforeEach, afterEach, test } = require('node:test'); | ||
| 6 | + | ||
| 7 | + let beforeEachTotal = 0; | ||
| 8 | + let afterEachRuntimeSkip = 0; | ||
| 9 | + let afterEachTotal = 0; | ||
| 10 | + | ||
| 11 | + beforeEach(common.mustCall(() => { | ||
| 12 | + beforeEachTotal++; | ||
| 13 | + }, 2)); | ||
| 14 | + | ||
| 15 | + afterEach(common.mustCall((t) => { | ||
| 16 | + afterEachTotal++; | ||
| 17 | + if (t.name === 'runtime skip') { | ||
| 18 | + afterEachRuntimeSkip++; | ||
| 19 | + } | ||
| 20 | + }, 2)); | ||
| 21 | + | ||
| 22 | + test('normal test', (t) => { | ||
| 23 | + t.assert.ok(true); | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + test('runtime skip', (t) => { | ||
| 27 | + t.skip('skip after setup'); | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + test('static skip', { skip: true }, common.mustNotCall()); | ||
| 31 | + | ||
| 32 | + process.on('exit', () => { | ||
| 33 | + assert.strictEqual(beforeEachTotal, 2); | ||
| 34 | + assert.strictEqual(afterEachRuntimeSkip, 1); | ||
| 35 | + assert.strictEqual(afterEachTotal, 2); | ||
| 36 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments