refactor: migrate to node:test and setup jsdom environment#5667
Conversation
|
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.
1f3bae9 to
3286583
Compare
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
- 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.
…st test helper import
bjohansebas
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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([ |
There was a problem hiding this comment.
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.
* feat(tests): add node test setup and update test utilities - 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. * refactor(tests): update snapshot test descriptions and improve test structure - 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. * refactor(tests): update CLI option tests to use node:test and expect - 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`. * refactor(tests): update web socket tests to use 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. * refactor(tests): migrate tests to use node:test and improve snapshot 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. * refactor: migrate tests from Jest to Node's test module - 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. * fixup! * fixup! * fixup! * fixup! * fixup! * fixup! * fixup! * fixup! * fixup! * fixup! * fixup! * chore: update test runner * fixup! * chore: update snapshots and fix module path in API tests * fixup! * fixup! * chore: update snapshots for watchFiles option tests * refactor: remove unused Logger interface and simplify socket function parameters * fix: update snapshot serialization for Windows compatibility and adjust test helper import * fix: codecov upload * fix: ensure directories are created for test reporter destination * refactor: simplify client resolution and clean up socket tests * refactor: clean up comments and improve clarity in test files * fixup!
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