Skip to content

Commit 8bc17b0

Browse files
Han5991aduh95
authored andcommitted
doc: add test reporter event lifecycle diagram
Document the lifecycle of node:test reporter events under Class: TestsStream, with an ASCII diagram that distinguishes declaration-order events from their execution-order twins (test:dequeue/test:complete), the leaf vs suite flow, and the run-level finale. Fixes: #51908 Signed-off-by: sangwook <rewq5991@gmail.com> PR-URL: #63780 Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 5240f00 commit 8bc17b0

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

β€Ždoc/api/test.mdβ€Ž

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,6 +3500,74 @@ Global events are emitted once per test run:
35003500
The root test also emits [`'test:plan'`][] and [`'test:diagnostic'`][] events
35013501
at the end of the run to report run level totals.
35023502

3503+
### Event lifecycle
3504+
3505+
The tables above group the events; the diagram below places them on a
3506+
timeline. The declaration ordered events form the main spine, buffered so that
3507+
a reporter sees them in source order, while each execution ordered twin is
3508+
emitted immediately, when the work actually happens. In particular,
3509+
[`'test:start'`][] marks when a test begins _reporting_ its own and its
3510+
subtests' status, not when its body begins executing; that moment is
3511+
[`'test:dequeue'`][].
3512+
3513+
```text
3514+
node:test reporter event lifecycle
3515+
main spine = DECLARATION order (buffered; matches source order)
3516+
right side = EXECUTION order (emitted immediately); β—„ marks each twin
3517+
3518+
LEAF TEST
3519+
─────────
3520+
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” test:enqueue
3521+
β”‚ test:start β”‚ ◄──── twins ──── (queued for execution;
3522+
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ type: 'suite' | 'test')
3523+
β”‚ begins REPORTING test:dequeue
3524+
β”‚ (not the start of (about to run; emitted right
3525+
β”‚ the test body) before the test body runs)
3526+
β”‚
3527+
β”‚ [ between the twins, on the execution timeline, the test
3528+
β”‚ body runs: context.log() emits test:log live, and
3529+
β”‚ test:stdout / test:stderr stream with --test ]
3530+
β”‚
3531+
β–Ό
3532+
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
3533+
β”‚ test:pass β”‚ test:fail β”‚ ◄──── twin ──── test:complete
3534+
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ result (details.passed says which)
3535+
β”‚
3536+
β–Ό
3537+
test:diagnostic the test's own context.diagnostic() messages,
3538+
buffered while it runs, flushed after its result
3539+
3540+
3541+
SUITE / PARENT TEST (each subtest is the whole LEAF flow above)
3542+
───────────────────
3543+
test:start ─► [ full flow of each subtest ... ] ─►
3544+
test:plan (count = subtests) ─► test:pass β”‚ test:fail ─►
3545+
test:diagnostic
3546+
3547+
3548+
RUN-LEVEL FINALE (root, after all top-level tests)
3549+
────────────────
3550+
test:plan top-level count
3551+
β”‚
3552+
β–Ό
3553+
test:diagnostic x N tests, suites, pass, fail, cancelled,
3554+
β”‚ skipped, todo, duration_ms (+ coverage errors)
3555+
β–Ό
3556+
test:coverage only if coverage is enabled
3557+
β”‚
3558+
β–Ό
3559+
test:summary ─► stream ends
3560+
3561+
3562+
INTERRUPTION (SIGINT, e.g. Ctrl+C, while tests are still running)
3563+
────────────
3564+
test:interrupted the innermost tests still running at that moment
3565+
β”‚ (not emitted if none were running)
3566+
β–Ό
3567+
the run exits immediately β€” the buffered spine never flushes, so
3568+
neither the finale above nor those tests' own results are emitted
3569+
```
3570+
35033571
### Event: `'test:coverage'`
35043572

35053573
* `data` {Object}

0 commit comments

Comments
Β (0)