Bridge the test context in the node:test shim - #37
Conversation
The suites reach for `t.skip()` to pass over a compared implementation that has nothing to compare, and the shim did not hand the body anything. It now builds a context around mocha's own skip. The wrapper stopped passing short calls straight through to do it, which also removed the branch: every call is wrapped, and the mocha callback keeps its zero arity either way. Co-authored-by: Claude <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
🟢 Approval recommended
The change is a small, correct, browser-test-only shim fix whose logic I verified against all t.skip() call sites and the rollup aliasing, with no impact on the shipped library.
Pull request overview
This PR fixes the browser test shim for node:test (aliased in via builder/rollup-browser-test.config.ts) so that test bodies receive a context object exposing skip(). Previously the shim's it only passed (name, fn) through and its context construction was incomplete for the it.skip path, so the t.skip() calls used by the compat (test/80.compat.test.ts) and benchmark (test/99.benchmark.test.ts) suites had no context to call. The wrapper now builds a {skip} context around mocha's own this.skip(), wraps every registration (including it.skip), and keeps the mocha callback zero-arity so mocha does not mistakenly switch to done-callback style.
Changes:
- Wrap all
it/it.skipregistrations through a singlewrapIthelper that supplies aTestContextwithskip()and preserves zero-arity mocha callbacks. - Add support for the
it(name, {timeout}, fn)options form, translating{timeout}intothis.timeout(ms). - Trim the shim's
TestContextto{skip}(dropping the unuseddiagnostic) and tighten the related type aliases.
File summaries
| File | Description |
|---|---|
| builder/node-test.shim.ts | Reworks the it wrapper to always inject a {skip} context, adds options/timeout handling, wraps it.skip, and updates the supporting type definitions. |
Notes on correctness verified during review:
- No test references
t.diagnostic, so removing it from the shim'sTestContextis safe. - All
t.skip()callers in the compat and benchmark suites are handled by the new{skip: () => this.skip()}context, including the asynccrypto.subtle.digest()case (the wrapper returns the promise from a zero-arity callback). test/90.*(which importstestfromnode:test) is excluded from the browser bundle, so the shim not exportingtestis fine.Body = () => unknownis equivalent to the previousbefore/aftersignatures, so those type changes are behavior-preserving.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The browser shim for
node:testnever handed the test body a context, sot.skip()— which the compat and benchmark suites use to pass over an implementation with nothing to compare — had nothing to call. It now builds one around mocha's ownskip.Doing that meant the wrapper could no longer pass short calls straight through, which removed its branch: every call is wrapped now, and the mocha callback keeps its zero arity either way. That arity is load-bearing — mocha reads it and switches to the done-callback style if the function declares an argument, which leaves the test unfinished.
The options form
it(name, {timeout: ms}, fn)is unchanged, and.skipnow goes through the same wrapper, so it accepts the same shapes.Verified
Drove all four paths against a stand-in for mocha's globals:
it(name, fn)it(name, {timeout}, fn)this.timeout(ms)it(name, (t) => t.skip())this.skip()it.skip(name, {timeout}, fn)this.timeout(ms)tsc --noEmit: green.🤖 Generated with Claude Code