Skip to content

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

Open
bennypowers wants to merge 6 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 6 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

changeset-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fc908c9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

bennypowers and others added 4 commits June 2, 2026 23:50
Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… assertion errors

Replace assert.ok(x.includes(y)) with expectIncludes from test-helpers
across all test files. Shows actual vs expected strings on failure
instead of useless true/false.

Assisted-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bashmish

Copy link
Copy Markdown
Member

@bennypowers I made a couple of changes, quite small, but the one that removes the major update changset I think you'd like to check. Let me know if you agree with the changes.

I also have another idea about test-helpers, but it's best to discuss it in a separate PR which I plan to create when this one is merged. Just giving you heads-up upfront that it might not be the final state before we release all of this.

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.

2 participants