Skip to content

Commit 29c517f

Browse files
Han5991atlowChemi
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: nodejs#51908 Signed-off-by: sangwook <rewq5991@gmail.com> PR-URL: nodejs#63780 Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 9baabd4 commit 29c517f

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
@@ -3580,6 +3580,74 @@ Global events are emitted once per test run:
35803580
The root test also emits [`'test:plan'`][] and [`'test:diagnostic'`][] events
35813581
at the end of the run to report run level totals.
35823582

3583+
### Event lifecycle
3584+
3585+
The tables above group the events; the diagram below places them on a
3586+
timeline. The declaration ordered events form the main spine, buffered so that
3587+
a reporter sees them in source order, while each execution ordered twin is
3588+
emitted immediately, when the work actually happens. In particular,
3589+
[`'test:start'`][] marks when a test begins _reporting_ its own and its
3590+
subtests' status, not when its body begins executing; that moment is
3591+
[`'test:dequeue'`][].
3592+
3593+
```text
3594+
node:test reporter event lifecycle
3595+
main spine = DECLARATION order (buffered; matches source order)
3596+
right side = EXECUTION order (emitted immediately); β—„ marks each twin
3597+
3598+
LEAF TEST
3599+
─────────
3600+
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” test:enqueue
3601+
β”‚ test:start β”‚ ◄──── twins ──── (queued for execution;
3602+
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ type: 'suite' | 'test')
3603+
β”‚ begins REPORTING test:dequeue
3604+
β”‚ (not the start of (about to run; emitted right
3605+
β”‚ the test body) before the test body runs)
3606+
β”‚
3607+
β”‚ [ between the twins, on the execution timeline, the test
3608+
β”‚ body runs: context.log() emits test:log live, and
3609+
β”‚ test:stdout / test:stderr stream with --test ]
3610+
β”‚
3611+
β–Ό
3612+
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
3613+
β”‚ test:pass β”‚ test:fail β”‚ ◄──── twin ──── test:complete
3614+
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ result (details.passed says which)
3615+
β”‚
3616+
β–Ό
3617+
test:diagnostic the test's own context.diagnostic() messages,
3618+
buffered while it runs, flushed after its result
3619+
3620+
3621+
SUITE / PARENT TEST (each subtest is the whole LEAF flow above)
3622+
───────────────────
3623+
test:start ─► [ full flow of each subtest ... ] ─►
3624+
test:plan (count = subtests) ─► test:pass β”‚ test:fail ─►
3625+
test:diagnostic
3626+
3627+
3628+
RUN-LEVEL FINALE (root, after all top-level tests)
3629+
────────────────
3630+
test:plan top-level count
3631+
β”‚
3632+
β–Ό
3633+
test:diagnostic x N tests, suites, pass, fail, cancelled,
3634+
β”‚ skipped, todo, duration_ms (+ coverage errors)
3635+
β–Ό
3636+
test:coverage only if coverage is enabled
3637+
β”‚
3638+
β–Ό
3639+
test:summary ─► stream ends
3640+
3641+
3642+
INTERRUPTION (SIGINT, e.g. Ctrl+C, while tests are still running)
3643+
────────────
3644+
test:interrupted the innermost tests still running at that moment
3645+
β”‚ (not emitted if none were running)
3646+
β–Ό
3647+
the run exits immediately β€” the buffered spine never flushes, so
3648+
neither the finale above nor those tests' own results are emitted
3649+
```
3650+
35833651
### Event: `'test:coverage'`
35843652

35853653
* `data` {Object}

0 commit comments

Comments
Β (0)