Skip to content

refactor: migrate to node:test and setup jsdom environment#5667

Merged
bjohansebas merged 30 commits into
nextfrom
migrate-jest-to-node-test-runner
May 10, 2026
Merged

refactor: migrate to node:test and setup jsdom environment#5667
bjohansebas merged 30 commits into
nextfrom
migrate-jest-to-node-test-runner

Conversation

@bjohansebas
Copy link
Copy Markdown
Member

Summary

What kind of change does this PR introduce?

Did you add tests for your changes?

Does this PR introduce a breaking change?

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Use of AI

@bjohansebas bjohansebas marked this pull request as draft May 2, 2026 00:17
@alexander-akait
Copy link
Copy Markdown
Member

Looks like test are failed...

- Introduced a new script for node test setup (`scripts/node-test-setup.mjs`) to configure snapshot serializers and resolve snapshot paths for webpack tests.
- Added new npm script `test:node` in `package.json` for running node tests with specific configurations.
- Updated Jest snapshots in `proxy-option.test.js.snap.webpack5` to reflect changes in test descriptions.
- Refactored tests in `open-option.test.js` and `proxy-option.test.js` to utilize `jest-mock` for mocking and spying, replacing previous Jest mocking methods.
- Changed `beforeAll` and `afterAll` hooks to `before` and `after` for better test isolation and readability.
…tructure

- Changed snapshot test descriptions to include a more structured format.
- Updated snapshot assertions to use `t.assert.snapshot` for consistency.
- Refactored test setup and teardown methods to use `before` and `after` from `node:test`.
- Adjusted the test cases in `normalize-options.test.js` and `validate-options.test.js` for improved clarity and maintainability.
@bjohansebas bjohansebas force-pushed the migrate-jest-to-node-test-runner branch from 1f3bae9 to 3286583 Compare May 9, 2026 23:14
@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

❌ Patch coverage is 99.00862% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.59%. Comparing base (a7ab30f) to head (74e1aeb).

Files with missing lines Patch % Lines
test/cli/basic.test.js 90.08% 12 Missing ⚠️
test/e2e/lazy-compilation.test.js 55.55% 4 Missing ⚠️
test/cli/host-option.test.js 90.90% 2 Missing ⚠️
test/e2e/ipc.test.js 83.33% 2 Missing ⚠️
test/e2e/server-and-client-transport.test.js 94.73% 2 Missing ⚠️
test/e2e/setup-exit-signals.test.js 97.87% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             next    #5667       +/-   ##
===========================================
+ Coverage   83.73%   94.59%   +10.85%     
===========================================
  Files          11      135      +124     
  Lines        1943    32826    +30883     
  Branches      719        2      -717     
===========================================
+ Hits         1627    31052    +29425     
- Misses        283     1774     +1491     
+ Partials       33        0       -33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

bjohansebas added 24 commits May 9, 2026 19:33
- Refactored multiple test files to utilize the `node:test` module for structuring tests.
- Replaced direct assertions with `t.assert.snapshot` for snapshot testing.
- Ensured consistency across tests by adding async context to test functions.
- Updated imports to include necessary testing utilities from `node:test` and `expect`.
…assertions

- Replaced traditional test structure with node:test for better test organization.
- Updated snapshot assertions to use the new test framework's syntax.
- Ensured all test cases in web-socket-communication.test.js, web-socket-server-url.test.js, and web-socket-server.test.js are consistent with the new structure.
…organization

- Updated test files to utilize the `node:test` module for better compatibility and performance.
- Replaced `jest.fn()` with `jest-mock` functions for mocking in various test cases.
- Enhanced snapshot descriptions for clarity and consistency across tests.
- Introduced a new `jsdom-setup.js` helper to streamline JSDOM configuration for tests.
- Adjusted test cases to use `t.assert.snapshot()` for snapshot assertions.
- Cleaned up mock implementations and reset logic in tests for improved reliability.
- Updated package.json to remove Jest dependencies and adjust test scripts for Node's test module.
- Deleted globalSetupTest.js and setupTest.js as they are no longer needed.
- Refactored ReactErrorBoundary.test.js to utilize real jsdom window/document.
- Updated WebsocketClient.test.js to use async/await and improved test structure.
- Skipped index.test.js due to dependency on Jest's mocking capabilities.
- Refactored socket-helper.test.js to create a mock WebSocketClient class.
- Updated log.test.js to simplify logger tests and remove unnecessary mocks.
- Enhanced jsdom-setup.js to replace jsdom's WebSocket with Node's ws library for better testing of WebSocket connections.
@bjohansebas bjohansebas marked this pull request as ready for review May 10, 2026 22:10
Copy link
Copy Markdown
Member Author

@bjohansebas bjohansebas left a comment

Choose a reason for hiding this comment

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

Okay, once CI passes, I’m going to merge it. There really aren’t any major changes, and I made it so the snapshots wouldn’t change too much, although some of them did. But those are changes I verified myself. Jest components are still being used, but everything works normally. Otherwise, this PR would become even bigger, and I need this to unblock the http-proxy-middleware update, since Jest was a factor preventing us from updating it.

Comment thread scripts/run-tests.mjs
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

t may look weird to run the test runner like that, but with so many flags there was a point where the fixtures were getting executed too, so I had to filter them out. And when using test-shard, it wouldn’t recognize them because of a Node.js bug, so this was the workaround.

process.env.CHOKIDAR_USEPOLLING = "true";

// Normalize "\r\n" and "\r" to "\n" so snapshots are platform-agnostic.
snapshot.setDefaultSnapshotSerializers([
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So the snapshots can keep working very similarly to how they worked with Jest, since there isn’t enough time to migrate to the Node.js format.

@bjohansebas bjohansebas requested a review from Copilot May 10, 2026 22:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@bjohansebas bjohansebas merged commit 4d2acaa into next May 10, 2026
101 of 189 checks passed
@bjohansebas bjohansebas deleted the migrate-jest-to-node-test-runner branch May 10, 2026 22:47
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