Repository navigation
test(user-agent): add test utility for user-agent module with mock HTTP server - #544
Merged
Merged
Conversation
…TP server Signed-off-by: Marc Nuri <marc@marcnuri.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new test utility function testUserAgent to simplify testing of the user-agent module by providing a mock HTTP server setup. The utility replaces manual server setup and teardown logic in test files.
Key changes:
- Created a centralized test utility that configures the user-agent module with mock HTTP responses
- Refactored existing tests to use the new utility instead of manual server management
- Enhanced test setup with proper server cleanup mechanisms
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/__tests__/user-agent.js |
New test utility that creates isolated user-agent instances with mock HTTP server |
src/__tests__/index.js |
Exports the new testUserAgent utility function |
src/__tests__/setup-jest.js |
Adds global cleanup for HTTP test servers |
src/user-agent/__tests__/index.test.js |
Refactored to use testUserAgent utility instead of manual server setup |
src/main/__tests__/init-browser-versions.test.js |
Updated to use testUserAgent and improved async test handling |
Comment on lines
+17
to
+18
| // Store test servers in global scope to ensure cleanup | ||
| // even when jest.resetModules() clears the module cache |
There was a problem hiding this comment.
The comment should explain what happens when jest.resetModules() clears the module cache and why global scope storage is necessary for cleanup.
Suggested change
| // Store test servers in global scope to ensure cleanup | |
| // even when jest.resetModules() clears the module cache | |
| // Store test servers in global scope to ensure cleanup. | |
| // Jest's resetModules() clears the module cache between tests, which causes | |
| // any module-scoped variables (such as arrays of test servers) to be lost. | |
| // By storing test server references in the global scope, we ensure that | |
| // cleanup logic (e.g., in setup-jest.js afterEach) can access and properly | |
| // close all servers, even if modules are reloaded and their local state is reset. |
…mock HTTP server Signed-off-by: Marc Nuri <marc@marcnuri.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



No description provided.