- Role
- Author of the parser (external contributor to Node.js core)
- Period
- 2022 (pull request opened June 2022, merged November 2022, shipped in Node.js v19.2.0)
Context & problem
Node.js 18 introduced a built-in test runner (node:test). With --test, it runs each test file in its own child process, and each child reports its results as TAP (Test Anything Protocol) text.
The runner treated each file as a single test, so a file with dozens of tests counted as one. The problem was reported publicly in nodejs/node#43344.
Code in Node.js core has to follow the project's conventions, such as primordials, and pass review from several collaborators before it lands.
My role & scope
- Wrote a TAP13/TAP14 grammar, a handwritten lexer, an LL(1) recursive-descent parser and a separate checker that validates the version, plan and test-point numbering.
- Built the parser as a Transform stream that parses each child process's output as it arrives, including nested subtests and YAML diagnostic blocks.
- Integrated the parser into the test runner with help from Moshe Atlow, so results are reported per test rather than per file.
- Wrote about 2,500 lines of tests covering the lexer, parser, stream behaviour and checker.
- Took the change through five months of review (107 reviews and 131 comments) with Node.js collaborators, including Moshe Atlow, Colin Ihrig, Antoine du Hamel, Rich Trott and Franziska Hinkelmann.
Key decisions
Write a handwritten lexer and LL(1) parser against an explicit TAP grammar.
- Rejected alternative
- Matching TAP output line by line with regular expressions.
- Trade-off
- More code to write and review (about 1,650 lines across lexer, parser and checker). Accepted because nested subtests and YAML blocks depend on indentation and context, which a token-based grammar handles predictably and with clear errors.
Separate parsing from validation: the parser builds the document and a separate checker enforces the TAP rules when asked.
- Rejected alternative
- Validating the TAP rules while parsing.
- Trade-off
- A second pass over the parsed results. Accepted so the parser can tolerate real-world output while strict checks stay explicit, and so each part can be tested on its own.
Parse output chunk by chunk as a stream instead of buffering each child process's output until it exits.
- Rejected alternative
- Collecting all output and parsing it when the child process ends.
- Trade-off
- Parser state has to survive chunk boundaries, such as partial lines and unterminated YAML blocks. Accepted so results appear while tests are still running.
Who I aligned
- Node.js test runner maintainers, including Moshe Atlow and Colin Ihrig: runner integration and design.
- Node.js collaborators and reviewers: 107 reviews over five months before the change landed.
- node:test users, through the public issue nodejs/node#43344.
Outcomes
- Merged into Node.js core in November 2022 (+4,418/−31 lines across 19 files). Pull request ↗
- Shipped in Node.js v19.2.0 as “test_runner: add initial TAP parser”. Release notes ↗
- The issue about the test count (nodejs/node#43344) was closed the day after the parser landed. Issue ↗
What outlived me
- Other contributors kept improving the parser after it landed, for example the primordials refactor (#45745)
- In May 2023, the test runner replaced TAP with v8.serialize between parent and child processes, which removed the parser from core
- Per-test reporting from child processes, which the parser introduced, carried over to the new protocol.
Lessons
- Landing code in Node.js core is a long design conversation: plan for months of review, not days.
- Choose the protocol for whoever is on the other end. TAP suits third-party tools; once Node.js owned both ends, a binary format replaced it.