Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

Addresses code review feedback requesting test coverage for the custom HTTP client implementation introduced in the package-json and throat dependency replacement.

Changes

Test Coverage: Added 17 unit tests mocking http.request/https.request to validate:

  • URL encoding for scoped packages (@scope/name@scope%2Fname)
  • Protocol selection (http vs https)
  • Request headers (User-Agent, Accept-Encoding)
  • Response decompression (gzip, deflate)
  • Timeout handling
  • Status code handling (404, 5xx, non-2xx)
  • Error paths (network errors, stream errors, parse errors)
  • Custom configuration (registry URL, user agent, timeout)

Implementation

Tests use Jest mocks and EventEmitter to simulate HTTP request/response lifecycle without network calls:

const mockData: INpmRegistryPackageResponse = {
  name: 'test-package',
  versions: { '1.0.0': { name: 'test-package', version: '1.0.0' } },
  'dist-tags': { latest: '1.0.0' }
};

mockHttpsRequest.mockImplementation((options, callback) => {
  setImmediate(() => callback(response as http.IncomingMessage));
  return request;
});

const fetchPromise = client.fetchPackageMetadataAsync('test-package');

response.statusCode = 200;
setImmediate(() => {
  response.emit('data', Buffer.from(JSON.stringify(mockData)));
  response.emit('end');
});

const result = await fetchPromise;
expect(result.data).toEqual(mockData);

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…ent with http mocking

Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP to address feedback on package-json and throat dependency replacements Add comprehensive unit tests for NpmRegistryClient with http mocking Jan 25, 2026
Copilot AI requested a review from TheLarkInn January 25, 2026 00:07
@TheLarkInn TheLarkInn marked this pull request as ready for review January 25, 2026 00:19
@TheLarkInn TheLarkInn merged commit 5da83eb into atomic-style-claude Jan 25, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from Needs triage to Closed in Bug Triage Jan 25, 2026
@TheLarkInn TheLarkInn deleted the copilot/sub-pr-5565-another-one branch January 25, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants