Skip to content

Bridge the test context in the node:test shim - #37

Merged
kawanet merged 1 commit into
kawanet:mainfrom
kawanet-bot:feature/shim-context
Sep 3, 2026
Merged

Bridge the test context in the node:test shim#37
kawanet merged 1 commit into
kawanet:mainfrom
kawanet-bot:feature/shim-context

Conversation

@kawanet-bot

Copy link
Copy Markdown
Contributor

The browser shim for node:test never handed the test body a context, so t.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 own skip.

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 .skip now goes through the same wrapper, so it accepts the same shapes.

Verified

Drove all four paths against a stand-in for mocha's globals:

call mocha callback arity bridged
it(name, fn) 0
it(name, {timeout}, fn) 0 this.timeout(ms)
it(name, (t) => t.skip()) 0 this.skip()
it.skip(name, {timeout}, fn) 0 this.timeout(ms)
  • Browser suite: unchanged from the current shim, same passing and pending counts.
  • Node suite and tsc --noEmit: green.

🤖 Generated with Claude Code

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>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@kawanet
kawanet requested a balanced review from Copilot September 3, 2026 05:15
@kawanet

kawanet commented Sep 3, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: f056c5e56c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 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.skip registrations through a single wrapIt helper that supplies a TestContext with skip() and preserves zero-arity mocha callbacks.
  • Add support for the it(name, {timeout}, fn) options form, translating {timeout} into this.timeout(ms).
  • Trim the shim's TestContext to {skip} (dropping the unused diagnostic) 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's TestContext is safe.
  • All t.skip() callers in the compat and benchmark suites are handled by the new {skip: () => this.skip()} context, including the async crypto.subtle.digest() case (the wrapper returns the promise from a zero-arity callback).
  • test/90.* (which imports test from node:test) is excluded from the browser bundle, so the shim not exporting test is fine.
  • Body = () => unknown is equivalent to the previous before/after signatures, 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.

@kawanet
kawanet merged commit da47918 into kawanet:main Sep 3, 2026
6 checks passed
@kawanet-bot
kawanet-bot deleted the feature/shim-context branch September 3, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants