GeezerVison is showing github.com — test_runner: run after hooks even if test is aborted · nodejs/node@20a01fc
File tree
Expand file treeCollapse file tree
Open diff view settings
fixtures/test-runner/output
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -763,10 +763,7 @@ class Test extends AsyncResource { |
763 | 763 | } |
764 | 764 |
|
765 | 765 | [kShouldAbort]() { |
766 | | - if (this.signal.aborted) { |
767 | | - return true; |
768 | | - } |
769 | | - if (this.outerSignal?.aborted) { |
| 766 | + if (this.signal.aborted || this.outerSignal?.aborted) { |
770 | 767 | this.#abortHandler(); |
771 | 768 | return true; |
772 | 769 | } |
@@ -866,10 +863,7 @@ class Test extends AsyncResource { |
866 | 863 | await SafePromiseRace([PromiseResolve(promise), stopPromise]); |
867 | 864 | } |
868 | 865 |
|
869 | | - if (this[kShouldAbort]()) { |
870 | | - this.postRun(); |
871 | | - return; |
872 | | - } |
| 866 | + this[kShouldAbort](); |
873 | 867 | this.plan?.check(); |
874 | 868 | this.pass(); |
875 | 869 | await afterEach(); |
|
Collapse file
Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const { test } = require('node:test'); |
| 3 | + |
| 4 | +test('test that aborts', (t, done) => { |
| 5 | + t.after(() => { |
| 6 | + // This should still run. |
| 7 | + console.log('AFTER'); |
| 8 | + }); |
| 9 | + |
| 10 | + setImmediate(() => { |
| 11 | + // This creates an uncaughtException, which aborts the test. |
| 12 | + throw new Error('boom'); |
| 13 | + }); |
| 14 | +}); |
Collapse file
Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +TAP version 13 |
| 2 | +AFTER |
| 3 | +# Subtest: test that aborts |
| 4 | +not ok 1 - test that aborts |
| 5 | + --- |
| 6 | + duration_ms: * |
| 7 | + location: '/test/fixtures/test-runner/output/abort-runs-after-hook.js:(LINE):1' |
| 8 | + failureType: 'uncaughtException' |
| 9 | + error: 'boom' |
| 10 | + code: 'ERR_TEST_FAILURE' |
| 11 | + stack: |- |
| 12 | + * |
| 13 | + * |
| 14 | + ... |
| 15 | +1..1 |
| 16 | +# tests 1 |
| 17 | +# suites 0 |
| 18 | +# pass 0 |
| 19 | +# fail 1 |
| 20 | +# cancelled 0 |
| 21 | +# skipped 0 |
| 22 | +# todo 0 |
| 23 | +# duration_ms * |
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-runner-output.mjs +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,6 +93,7 @@ const lcovTransform = snapshot.transform( |
93 | 93 |
|
94 | 94 | const tests = [ |
95 | 95 | { name: 'test-runner/output/abort.js' }, |
| 96 | + { name: 'test-runner/output/abort-runs-after-hook.js' }, |
96 | 97 | { name: 'test-runner/output/abort_suite.js' }, |
97 | 98 | { name: 'test-runner/output/abort_hooks.js' }, |
98 | 99 | { name: 'test-runner/output/describe_it.js' }, |
|