Skip to content

test(dev-server-core): migrate from mocha/chai to node:test#3098

Open
bennypowers wants to merge 3 commits into
masterfrom
migrate/dev-server-core-node-test
Open

test(dev-server-core): migrate from mocha/chai to node:test#3098
bennypowers wants to merge 3 commits into
masterfrom
migrate/dev-server-core-node-test

Conversation

@bennypowers
Copy link
Copy Markdown
Member

Summary

  • Migrate all 14 test files (97 tests) from mocha/chai/hanbi to node:test/node:assert/strict
  • Replace hanbi stubMethod with mock.method from node:test
  • Update test script from mocha to node --experimental-strip-types --test
  • Update published src/test-helpers.ts to use node:assert instead of chai (breaking change, changeset included)

Breaking change

src/test-helpers.ts is exported via exports["./test-helpers"]. Its fetchText function now throws node:assert's AssertionError instead of chai's on non-200 responses. Functionally identical, different error class. Pending team decision on acceptability.

Test plan

  • All 97 tests pass on Node 22
  • All 97 tests pass on Node 24
  • CI green

Replace mocha/chai/hanbi with node:test and node:assert/strict across
all 14 test files (97 tests), test helpers, and the published
`src/test-helpers.ts` utility.

Key changes:
- chai `expect` assertions to node:assert/strict
- hanbi `stubMethod` to `mock.method` from node:test
- `__dirname` to `import.meta.dirname`
- Source imports (`../src/`) to dist imports (`../dist/`)
- Test-local imports use `.ts` extension for strip-types compat
- `context()` to `describe()` (mocha alias not in node:test)
- mocha test script to `node --experimental-strip-types --test`

Note: `src/test-helpers.ts` is a published utility exported via
`exports["./test-helpers"]`. Its `fetchText` function now uses
`node:assert` instead of `chai` for the status check -- pending
team decision on whether this is acceptable.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 2, 2026

🦋 Changeset detected

Latest commit: 4bef3c1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@web/dev-server-core Major
@web/dev-server-esbuild Patch
@web/dev-server-hmr Patch
@web/dev-server-import-maps Patch
@web/dev-server-legacy Patch
@web/dev-server-rollup Patch
@web/dev-server Patch
@web/storybook-builder Patch
@web/test-runner-core Patch
@web/test-runner-module-mocking Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant