GeezerVison is showing github.com — test_runner: fix global before not called when no global test exists · nodejs/node@66ea9bd
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 +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -828,6 +828,10 @@ class Suite extends Test { | 828 | 828 | return; | 829 | 829 | } | 830 | 830 |
| | 831 | + if (this.parent.hooks.before.length > 0) { | | 832 | + await this.parent.runHook('before', this.parent.getRunArgs()); | | 833 | + } | | 834 | + | 831 | 835 | await this.runHook('before', hookArgs); | 832 | 836 |
| 833 | 837 | const stopPromise = stopTest(this.timeout, this.signal); | |
Collapse file Copy file name to clipboard +84Lines changed: 84 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const { test, describe, it, before, after, beforeEach, afterEach } = require('node:test'); | | 3 | +const assert = require("assert"); | | 4 | + | | 5 | +// This file should not have any global tests to reproduce bug #48844 | | 6 | +const testArr = []; | | 7 | + | | 8 | +before(() => testArr.push('global before')); | | 9 | +after(() => { | | 10 | + testArr.push('global after'); | | 11 | + | | 12 | + try { | | 13 | + assert.deepStrictEqual(testArr, [ | | 14 | + 'global before', | | 15 | + 'describe before', | | 16 | + | | 17 | + 'describe beforeEach', | | 18 | + 'describe it 1', | | 19 | + 'describe afterEach', | | 20 | + | | 21 | + 'describe beforeEach', | | 22 | + 'describe test 2', | | 23 | + 'describe afterEach', | | 24 | + | | 25 | + 'describe nested before', | | 26 | + | | 27 | + 'describe beforeEach', | | 28 | + 'describe nested beforeEach', | | 29 | + 'describe nested it 1', | | 30 | + 'describe afterEach', | | 31 | + 'describe nested afterEach', | | 32 | + | | 33 | + 'describe beforeEach', | | 34 | + 'describe nested beforeEach', | | 35 | + 'describe nested test 2', | | 36 | + 'describe afterEach', | | 37 | + 'describe nested afterEach', | | 38 | + | | 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 | + } | | 48 | +}); | | 49 | + | | 50 | +describe('describe hooks with no global tests', () => { | | 51 | + before(() => { | | 52 | + testArr.push('describe before'); | | 53 | + }); | | 54 | + after(()=> { | | 55 | + testArr.push('describe after'); | | 56 | + }); | | 57 | + beforeEach(() => { | | 58 | + testArr.push('describe beforeEach'); | | 59 | + }); | | 60 | + afterEach(() => { | | 61 | + testArr.push('describe afterEach'); | | 62 | + }); | | 63 | + | | 64 | + it('1', () => testArr.push('describe it 1')); | | 65 | + test('2', () => testArr.push('describe test 2')); | | 66 | + | | 67 | + describe('nested', () => { | | 68 | + before(() => { | | 69 | + testArr.push('describe nested before') | | 70 | + }); | | 71 | + after(() => { | | 72 | + testArr.push('describe nested after') | | 73 | + }); | | 74 | + beforeEach(() => { | | 75 | + testArr.push('describe nested beforeEach') | | 76 | + }); | | 77 | + afterEach(() => { | | 78 | + testArr.push('describe nested afterEach') | | 79 | + }); | | 80 | + | | 81 | + it('nested 1', () => testArr.push('describe nested it 1')); | | 82 | + test('nested 2', () => testArr.push('describe nested test 2')); | | 83 | + }); | | 84 | +}); |
Collapse file Copy file name to clipboard +44Lines changed: 44 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +TAP version 13 | | 2 | +# Subtest: describe hooks with no global tests | | 3 | + # Subtest: 1 | | 4 | + ok 1 - 1 | | 5 | + --- | | 6 | + duration_ms: * | | 7 | + ... | | 8 | + # Subtest: 2 | | 9 | + ok 2 - 2 | | 10 | + --- | | 11 | + duration_ms: * | | 12 | + ... | | 13 | + # Subtest: nested | | 14 | + # Subtest: nested 1 | | 15 | + ok 1 - nested 1 | | 16 | + --- | | 17 | + duration_ms: * | | 18 | + ... | | 19 | + # Subtest: nested 2 | | 20 | + ok 2 - nested 2 | | 21 | + --- | | 22 | + duration_ms: * | | 23 | + ... | | 24 | + 1..2 | | 25 | + ok 3 - nested | | 26 | + --- | | 27 | + duration_ms: * | | 28 | + type: 'suite' | | 29 | + ... | | 30 | + 1..3 | | 31 | +ok 1 - describe hooks with no global tests | | 32 | + --- | | 33 | + duration_ms: * | | 34 | + type: 'suite' | | 35 | + ... | | 36 | +1..1 | | 37 | +# tests 4 | | 38 | +# suites 2 | | 39 | +# pass 4 | | 40 | +# fail 0 | | 41 | +# cancelled 0 | | 42 | +# skipped 0 | | 43 | +# todo 0 | | 44 | +# 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 |
|---|
@@ -36,6 +36,7 @@ const tests = [ | 36 | 36 | { name: 'test-runner/output/describe_it.js' }, | 37 | 37 | { name: 'test-runner/output/describe_nested.js' }, | 38 | 38 | { name: 'test-runner/output/hooks.js' }, | | 39 | + { name: 'test-runner/output/hooks-with-no-global-test.js' }, | 39 | 40 | { name: 'test-runner/output/no_refs.js' }, | 40 | 41 | { name: 'test-runner/output/no_tests.js' }, | 41 | 42 | { name: 'test-runner/output/only_tests.js' }, | |
|