Skip to content

[npm-check-fork] Add comprehensive unit tests for NpmRegistryClient with http mocking#5568

Merged
TheLarkInn merged 2 commits into
atomic-style-claudefrom
copilot/sub-pr-5565-another-one
Jan 25, 2026
Merged

[npm-check-fork] Add comprehensive unit tests for NpmRegistryClient with http mocking#5568
TheLarkInn merged 2 commits into
atomic-style-claudefrom
copilot/sub-pr-5565-another-one

Conversation

Copilot AI commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

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
TheLarkInn added a commit that referenced this pull request Jan 27, 2026
…5568)

* Initial plan

* test(npm-check-fork): add comprehensive unit tests for NpmRegistryClient with http mocking

Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>
TheLarkInn added a commit that referenced this pull request Jan 27, 2026
* feat(npm-check-fork): add npm registry type definitions

Add INpmRegistryPackageResponse and INpmRegistryVersionMetadata interfaces
to support the upcoming replacement of the package-json dependency with a
local implementation using WebClient.

- INpmRegistryVersionMetadata extends INpmCheckPackageVersion for backward
  compatibility
- INpmRegistryPackageResponse models the full npm registry API response
- Added JSDoc with links to npm registry API documentation

* feat(npm-check-fork): add NpmRegistryClient for fetching package metadata

Implement NpmRegistryClient class to replace external package-json dependency
with a self-contained HTTP client using Node.js built-in modules.

Features:
- INpmRegistryClientOptions for configuring registry URL, user agent, timeout
- INpmRegistryClientResult for consistent error handling
- Automatic scoped package URL encoding (@scope/name -> @scope%2Fname)
- Support for gzip/deflate response decompression
- Proper error handling for 404, HTTP errors, network errors, and timeouts

* refactor(npm-check-fork): use NpmRegistryClient in GetLatestFromRegistry

Replace package-json and throat dependencies with NpmRegistryClient for
fetching npm registry metadata. Preserves existing version sorting and
homepage extraction logic.

Changes:
- Remove package-json and throat imports
- Add lazy-initialized module-level NpmRegistryClient instance
- Update getNpmInfo to use fetchPackageMetadataAsync
- Preserve lodash/semver version sorting
- Preserve bestGuessHomepage extraction

* feat(npm-check-fork): add getNpmInfoBatch for concurrent package fetching

Add batch fetching function to retrieve metadata for multiple packages
concurrently with configurable concurrency limit.

Features:
- getNpmInfoBatch(packageNames, concurrency) returns Map<string, INpmRegistryInfo>
- Default concurrency matches CPU count (like original throat behavior)
- Processes packages in batches using Promise.all

* refactor(npm-check-fork): remove package-json and throat dependencies

Remove external dependencies that have been replaced by NpmRegistryClient:
- package-json: replaced by NpmRegistryClient
- throat: replaced by Promise.all batch processing

Update tests to mock NpmRegistryClient instead of package-json.

* test(npm-check-fork): add unit tests for NpmRegistryClient

Add basic unit tests for NpmRegistryClient constructor options.
Update GetLatestFromRegistry tests with improved module mocking.

* docs(npm-check-fork): update CHANGELOG for dependency replacement

Document the removal of package-json and throat dependencies in favor of
internal NpmRegistryClient implementation.

* cleanup from code review

* remove ai outputs

* rush change

* restore CHANGELOG.md

* docs(npm-check-fork): fix JSDoc claiming interface extends when it doesn't (#5567)

* Initial plan

* docs: reword JSDoc for structural compatibility instead of extends

Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>

* Add comprehensive unit tests for NpmRegistryClient with http mocking (#5568)

* Initial plan

* test(npm-check-fork): add comprehensive unit tests for NpmRegistryClient with http mocking

Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>

* DROP: rush update

---------

Co-authored-by: Sean Larkin <thelarkinn@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: TheLarkInn <3408176+TheLarkInn@users.noreply.github.com>
@octogonz octogonz changed the title Add comprehensive unit tests for NpmRegistryClient with http mocking [npm-check-fork] Add comprehensive unit tests for NpmRegistryClient with http mocking Feb 6, 2026
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