Skip to content

test(user-agent): add test utility for user-agent module with mock HTTP server - #544

Merged
manusa merged 2 commits into
mainfrom
test/user-agent-no-mock
Oct 7, 2025
Merged

manusa merged 2 commits into
mainfrom
test/user-agent-no-mock

Conversation

@manusa

@manusa manusa commented Oct 7, 2025

Copy link
Copy Markdown
Owner

No description provided.

…TP server

Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa
manusa requested a review from Copilot October 7, 2025 05:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copilot AI Oct 7, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
…mock HTTP server

Signed-off-by: Marc Nuri <marc@marcnuri.com>
@manusa manusa added this to the 0.1.0 milestone Oct 7, 2025
@sonarqubecloud

sonarqubecloud Bot commented Oct 7, 2025

Copy link
Copy Markdown

@manusa
manusa merged commit 24b8a57 into main Oct 7, 2025
6 checks passed
@manusa
manusa deleted the test/user-agent-no-mock branch October 7, 2025 07:20
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