事件生命周期
🌐 Event lifecycle
上面的表格将事件进行了分组;下面的图表则把它们放在时间线上。声明顺序的事件构成了主要脉络,有缓冲处理,这样报告器就能按来源顺序看到它们,而每个执行顺序的双胞事件会在工作实际发生时立即发出。特别是,'test:start' 标记的是测试开始报告自身及其子测试状态的时间,而不是其主体开始执行的时间;那个时刻是 'test:dequeue'。
🌐 The tables above group the events; the diagram below places them on a
timeline. The declaration ordered events form the main spine, buffered so that
a reporter sees them in source order, while each execution ordered twin is
emitted immediately, when the work actually happens. In particular,
'test:start' marks when a test begins reporting its own and its
subtests' status, not when its body begins executing; that moment is
'test:dequeue'.
node:test reporter event lifecycle
main spine = DECLARATION order (buffered; matches source order)
right side = EXECUTION order (emitted immediately); ◄ marks each twin
LEAF TEST
─────────
┌──────────────┐ test:enqueue
│ test:start │ ◄──── twins ──── (queued for execution;
└──────────────┘ type: 'suite' | 'test')
│ begins REPORTING test:dequeue
│ (not the start of (about to run; emitted right
│ the test body) before the test body runs)
│
│ [ between the twins, on the execution timeline, the test
│ body runs: context.log() emits test:log live, and
│ test:stdout / test:stderr stream with --test ]
│
▼
┌───────────────────────┐
│ test:pass │ test:fail │ ◄──── twin ──── test:complete
└───────────────────────┘ result (details.passed says which)
│
▼
test:diagnostic the test's own context.diagnostic() messages,
buffered while it runs, flushed after its result
SUITE / PARENT TEST (each subtest is the whole LEAF flow above)
───────────────────
test:start ─► [ full flow of each subtest ... ] ─►
test:plan (count = subtests) ─► test:pass │ test:fail ─►
test:diagnostic
RUN-LEVEL FINALE (root, after all top-level tests)
────────────────
test:plan top-level count
│
▼
test:diagnostic x N tests, suites, pass, fail, cancelled,
│ skipped, todo, duration_ms (+ coverage errors)
▼
test:coverage only if coverage is enabled
│
▼
test:summary ─► stream ends
INTERRUPTION (SIGINT, e.g. Ctrl+C, while tests are still running)
────────────
test:interrupted the innermost tests still running at that moment
│ (not emitted if none were running)
▼
the run exits immediately — the buffered spine never flushes, so
neither the finale above nor those tests' own results are emitted