| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1812,15 +1812,22 @@ class Suite extends Test { | |||
| 1812 | 1812 | publishError(err); | |
| 1813 | 1813 | } | |
| 1814 | 1814 | this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure)); | |
| 1815 | - } finally { | ||
| 1816 | - if (testChannel.end.hasSubscribers) { | ||
| 1817 | - publishEnd(); | ||
| 1818 | - } | ||
| 1819 | 1815 | } | |
| 1820 | 1816 | ||
| 1817 | + this.#publishEnd = publishEnd; | ||
| 1821 | 1818 | this.buildPhaseFinished = true; | |
| 1822 | 1819 | } | |
| 1823 | 1820 | ||
| 1821 | + #publishEnd = null; | ||
| 1822 | + | ||
| 1823 | + #publishSuiteEnd() { | ||
| 1824 | + const publishEnd = this.#publishEnd; | ||
| 1825 | + this.#publishEnd = null; | ||
| 1826 | + if (publishEnd !== null && testChannel.end.hasSubscribers) { | ||
| 1827 | + publishEnd(); | ||
| 1828 | + } | ||
| 1829 | + } | ||
| 1830 | + | ||
| 1824 | 1831 | #ctx; | |
| 1825 | 1832 | getCtx() { | |
| 1826 | 1833 | this.#ctx ??= new TestContext(this); | |
@@ -1872,6 +1879,7 @@ class Suite extends Test { | |||
| 1872 | 1879 | } | |
| 1873 | 1880 | } finally { | |
| 1874 | 1881 | stopPromise?.[SymbolDispose](); | |
| 1882 | + this.#publishSuiteEnd(); | ||
| 1875 | 1883 | } | |
| 1876 | 1884 | ||
| 1877 | 1885 | this.postRun(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,9 +9,14 @@ const { join } = require('path'); | |||
| 9 | 9 | ||
| 10 | 10 | const events = []; | |
| 11 | 11 | ||
| 12 | - dc.subscribe('tracing:node.test:start', (data) => events.push({ event: 'start', name: data.name })); | ||
| 13 | - dc.subscribe('tracing:node.test:end', (data) => events.push({ event: 'end', name: data.name })); | ||
| 14 | - dc.subscribe('tracing:node.test:error', (data) => events.push({ event: 'error', name: data.name })); | ||
| 12 | + dc.subscribe('tracing:node.test:start', (data) => events.push({ event: 'start', name: data.name, type: data.type })); | ||
| 13 | + dc.subscribe('tracing:node.test:end', (data) => events.push({ event: 'end', name: data.name, type: data.type })); | ||
| 14 | + dc.subscribe('tracing:node.test:error', (data) => events.push({ event: 'error', name: data.name, type: data.type })); | ||
| 15 | + | ||
| 16 | + describe('suite end ordering', () => { | ||
| 17 | + it('child a', async () => { await new Promise((r) => setTimeout(r, 5)); }); | ||
| 18 | + it('child b', () => {}); | ||
| 19 | + }); | ||
| 15 | 20 | ||
| 16 | 21 | test('passing test fires start and end', async () => {}); | |
| 17 | 22 | ||
@@ -54,6 +59,19 @@ process.on('exit', () => { | |||
| 54 | 59 | const asyncEnd = events.filter((e) => e.event === 'end' && e.name === asyncTestName); | |
| 55 | 60 | assert.strictEqual(asyncStart.length, 1); | |
| 56 | 61 | assert.strictEqual(asyncEnd.length, 1); | |
| 62 | + | ||
| 63 | + const suiteNames = new Set(['suite end ordering', 'child a', 'child b']); | ||
| 64 | + const suiteSequence = events | ||
| 65 | + .filter((e) => suiteNames.has(e.name)) | ||
| 66 | + .map((e) => `${e.event}:${e.name}`); | ||
| 67 | + assert.deepStrictEqual(suiteSequence, [ | ||
| 68 | + 'start:suite end ordering', | ||
| 69 | + 'start:child a', | ||
| 70 | + 'end:child a', | ||
| 71 | + 'start:child b', | ||
| 72 | + 'end:child b', | ||
| 73 | + 'end:suite end ordering', | ||
| 74 | + ]); | ||
| 57 | 75 | }); | |
| 58 | 76 | ||
| 59 | 77 | // Test bindStore context propagation | |
| Back | FazBrowse Home | New Git URL |
0 commit comments