Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -3457,6 +3457,82 @@ object, streaming a series of events representing the execution of the tests.
Some of the events are guaranteed to be emitted in the same order as the tests
are defined, while others are emitted in the order that the tests execute.

### Event lifecycle

Most events are emitted in **declaration order** — the order in which the tests
appear in the source. `'test:dequeue'` and `'test:complete'` are instead
emitted in **execution order**, which can differ when tests run concurrently.
Each is the twin of a declaration-order event marking the same moment:
`'test:dequeue'` (about to run) pairs with `'test:start'`, and
`'test:complete'` (finished running) pairs with `'test:pass'` / `'test:fail'`.
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'`.

```text
node:test reporter event lifecycle
main spine = DECLARATION order (reporting; matches source order)
right side = EXECUTION order (when work happens); ◄ marks each twin

LEAF TEST
─────────
┌──────────────┐
│ test:enqueue │ queued for execution; type: 'suite' | 'test'
└──────────────┘
┌──────────────┐
│ test:start │ ◄──── twin ──── test:dequeue
└──────────────┘ begins (about to run; emitted right
│ REPORTING before the test body runs)
│ (not exec start)
│ [ between the twins, on the execution timeline, the test
│ body runs: context.diagnostic() is called here, and
│ test:stdout / test:stderr stream live with --test ]
┌───────────────────────┐
│ test:pass │ test:fail │ ◄──── twin ──── test:complete
└───────────────────────┘ result (finished running the body)
test:diagnostic the test's own context.diagnostic() messages,
flushed after its result


SUITE / PARENT TEST (each subtest is the whole LEAF flow above)
───────────────────
test:enqueue ─► 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; declaration order)
────────────────
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
```

A few events are kept off the main path above:

* `'test:stdout'` and `'test:stderr'` are emitted only when the [`--test`][]
flag is used, and are not guaranteed to follow declaration order.
* `'test:interrupted'` is emitted if the run is interrupted by a `SIGINT`
signal (for example, <kbd>Ctrl</kbd>+<kbd>C</kbd>).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this will work, I recall seeing an issue with anchor tag recently (related to the new parser or something around those lines)

@avivkeller would you know?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — I checked and the link doesn't resolve (doc-kit slugs the heading to #test, but the ref points at #--test). It follows the existing pattern though — the [--test][] link just above (line 671) already does the same — and the reference still seems useful, so I left it in for now. Looks like the doc-kit anchor issue you mentioned.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was refering to the <kbd> tags, not sure what you meant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused. It renders well, just like the image!

image

* In watch mode, `'test:watch:drained'` is emitted when no more tests are queued
for execution, and `'test:watch:restarted'` when a file change restarts tests.
* With process-level test isolation, a `'test:summary'` event is emitted for
each test file in addition to the final cumulative summary.

### Event: `'test:coverage'`

* `data` {Object}
Expand Down
Loading