GeezerVison is showing github.com — test_runner: fix global after not failing the tests · nodejs/node@71f7ed7
File treeExpand 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 +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -688,6 +688,14 @@ class Test extends AsyncResource { | 688 | 688 | this.parent.processReadySubtestRange(false); | 689 | 689 | this.parent.processPendingSubtests(); | 690 | 690 | } else if (!this.reported) { | | 691 | + if (!this.passed && failed === 0 && this.error) { | | 692 | + this.reporter.fail(0, kFilename, this.subtests.length + 1, kFilename, { | | 693 | + __proto__: null, | | 694 | + duration_ms: this.#duration(), | | 695 | + error: this.error, | | 696 | + }, undefined); | | 697 | + } | | 698 | + | 691 | 699 | this.reported = true; | 692 | 700 | this.reporter.plan(this.nesting, kFilename, this.root.harness.counters.topLevel); | 693 | 701 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/common/assertSnapshot.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,10 @@ function replaceWindowsPaths(str) { | 24 | 24 | return common.isWindows ? str.replaceAll(path.win32.sep, path.posix.sep) : str; | 25 | 25 | } | 26 | 26 |
| | 27 | +function replaceFullPaths(str) { | | 28 | + return str.replaceAll(process.cwd(), ''); | | 29 | +} | | 30 | + | 27 | 31 | function transform(...args) { | 28 | 32 | return (str) => args.reduce((acc, fn) => fn(acc), str); | 29 | 33 | } | @@ -73,6 +77,7 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ... | 73 | 77 | module.exports = { | 74 | 78 | assertSnapshot, | 75 | 79 | getSnapshotPath, | | 80 | + replaceFullPaths, | 76 | 81 | replaceNodeVersion, | 77 | 82 | replaceStackTrace, | 78 | 83 | replaceWindowsLineEndings, | |
Collapse file Copy file name to clipboard +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const { it, after } = require('node:test'); | | 3 | + | | 4 | +after(() => { | | 5 | + throw new Error('this should fail the test') | | 6 | +}); | | 7 | + | | 8 | +it('this is a test', () => { | | 9 | + console.log('this is a test') | | 10 | +}); |
Collapse file Copy file name to clipboard +34Lines changed: 34 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +this is a test | | 2 | +TAP version 13 | | 3 | +# Subtest: this is a test | | 4 | +ok 1 - this is a test | | 5 | + --- | | 6 | + duration_ms: * | | 7 | + ... | | 8 | +not ok 2 - /test/fixtures/test-runner/output/global_after_should_fail_the_test.js | | 9 | + --- | | 10 | + duration_ms: * | | 11 | + failureType: 'hookFailed' | | 12 | + error: 'this should fail the test' | | 13 | + code: 'ERR_TEST_FAILURE' | | 14 | + stack: |- | | 15 | + * | | 16 | + * | | 17 | + * | | 18 | + * | | 19 | + * | | 20 | + * | | 21 | + * | | 22 | + * | | 23 | + * | | 24 | + * | | 25 | + ... | | 26 | +1..1 | | 27 | +# tests 1 | | 28 | +# suites 0 | | 29 | +# pass 1 | | 30 | +# fail 0 | | 31 | +# cancelled 0 | | 32 | +# skipped 0 | | 33 | +# todo 0 | | 34 | +# duration_ms * |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/test-runner/output/hooks-with-no-global-test.js +24-30Lines changed: 24 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,42 +9,36 @@ before(() => testArr.push('global before')); | 9 | 9 | after(() => { | 10 | 10 | testArr.push('global after'); | 11 | 11 |
| 12 | | - try { | 13 | | - assert.deepStrictEqual(testArr, [ | 14 | | - 'global before', | 15 | | - 'describe before', | | 12 | + assert.deepStrictEqual(testArr, [ | | 13 | + 'global before', | | 14 | + 'describe before', | 16 | 15 |
| 17 | | - 'describe beforeEach', | 18 | | - 'describe it 1', | 19 | | - 'describe afterEach', | | 16 | + 'describe beforeEach', | | 17 | + 'describe it 1', | | 18 | + 'describe afterEach', | 20 | 19 |
| 21 | | - 'describe beforeEach', | 22 | | - 'describe test 2', | 23 | | - 'describe afterEach', | | 20 | + 'describe beforeEach', | | 21 | + 'describe test 2', | | 22 | + 'describe afterEach', | 24 | 23 |
| 25 | | - 'describe nested before', | | 24 | + 'describe nested before', | 26 | 25 |
| 27 | | - 'describe beforeEach', | 28 | | - 'describe nested beforeEach', | 29 | | - 'describe nested it 1', | 30 | | - 'describe afterEach', | 31 | | - 'describe nested afterEach', | | 26 | + 'describe beforeEach', | | 27 | + 'describe nested beforeEach', | | 28 | + 'describe nested it 1', | | 29 | + 'describe afterEach', | | 30 | + 'describe nested afterEach', | 32 | 31 |
| 33 | | - 'describe beforeEach', | 34 | | - 'describe nested beforeEach', | 35 | | - 'describe nested test 2', | 36 | | - 'describe afterEach', | 37 | | - 'describe nested afterEach', | | 32 | + 'describe beforeEach', | | 33 | + 'describe nested beforeEach', | | 34 | + 'describe nested test 2', | | 35 | + 'describe afterEach', | | 36 | + 'describe nested afterEach', | 38 | 37 |
| 39 | | - 'describe nested after', | 40 | | - 'describe after', | 41 | | - 'global after', | 42 | | - ]); | 43 | | - } catch (e) { | 44 | | - // TODO(rluvaton): remove the try catch after #48867 is fixed | 45 | | - console.error(e); | 46 | | - process.exit(1); | 47 | | - } | | 38 | + 'describe nested after', | | 39 | + 'describe after', | | 40 | + 'global after', | | 41 | + ]); | 48 | 42 | }); | 49 | 43 |
| 50 | 44 | describe('describe hooks with no global tests', () => { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-output.mjs +22-4Lines changed: 22 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,10 +24,27 @@ function replaceSpecDuration(str) { | 24 | 24 | .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *') | 25 | 25 | .replace(stackTraceBasePath, '$3'); | 26 | 26 | } | 27 | | -const defaultTransform = snapshot | 28 | | - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace, replaceTestDuration); | 29 | | -const specTransform = snapshot | 30 | | - .transform(replaceSpecDuration, snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace); | | 27 | + | | 28 | +function removeWindowsPathEscaping(str) { | | 29 | + return common.isWindows ? str.replaceAll(/\\\\/g, '\\') : str; | | 30 | +} | | 31 | + | | 32 | +const defaultTransform = snapshot.transform( | | 33 | + snapshot.replaceWindowsLineEndings, | | 34 | + snapshot.replaceStackTrace, | | 35 | + replaceTestDuration, | | 36 | +); | | 37 | +const specTransform = snapshot.transform( | | 38 | + replaceSpecDuration, | | 39 | + snapshot.replaceWindowsLineEndings, | | 40 | + snapshot.replaceStackTrace, | | 41 | +); | | 42 | +const withFileNameTransform = snapshot.transform( | | 43 | + defaultTransform, | | 44 | + removeWindowsPathEscaping, | | 45 | + snapshot.replaceFullPaths, | | 46 | + snapshot.replaceWindowsPaths, | | 47 | +); | 31 | 48 |
| 32 | 49 |
| 33 | 50 | const tests = [ | @@ -41,6 +58,7 @@ const tests = [ | 41 | 58 | { name: 'test-runner/output/hooks-with-no-global-test.js' }, | 42 | 59 | { name: 'test-runner/output/before-and-after-each-too-many-listeners.js' }, | 43 | 60 | { name: 'test-runner/output/before-and-after-each-with-timeout-too-many-listeners.js' }, | | 61 | + { name: 'test-runner/output/global_after_should_fail_the_test.js', transform: withFileNameTransform }, | 44 | 62 | { name: 'test-runner/output/no_refs.js' }, | 45 | 63 | { name: 'test-runner/output/no_tests.js' }, | 46 | 64 | { name: 'test-runner/output/only_tests.js' }, | |
|