Skip to content

refactor: replace nock with undici#104

Merged
Garbee merged 11 commits intomainfrom
garbee/replace/nock
Mar 30, 2026
Merged

refactor: replace nock with undici#104
Garbee merged 11 commits intomainfrom
garbee/replace/nock

Conversation

@Garbee
Copy link
Copy Markdown
Member

@Garbee Garbee commented Mar 20, 2026

Summary

  • Replace nock with undici's MockAgent for HTTP request interception in tests
  • Aligns test mocks with the actual HTTP stack used by Node's native fetch
  • Removes nock and @types/nock dependencies

Test plan

  • All 43 existing tests pass
  • Coverage maintained

No QA Required

Garbee added 9 commits March 20, 2026 08:50
All file patterns were simple extension checks (e.g. **/*.js), so
minimatch can be replaced with path.extname() and a Set of allowed
extensions. This removes an external dependency with no behavior change.
Extract isSupportedFile helper that skips path segments starting with
"." (replicating minimatch's default dot:false) and deduplicates the
filter logic between the PR and push code paths.
The yaml package has built-in TypeScript types and a cleaner API,
removing the need for the separate @types/js-yaml package.
Use undici's MockAgent to intercept fetch requests in tests, aligning
mocks with the actual HTTP stack used by Node's native fetch.
undici is available as a Node 24 built-in; installing it as a package
caused ncc to bundle v7 into dist/index.js, nearly doubling its size.
@Garbee Garbee self-assigned this Mar 20, 2026
Base automatically changed from garbee/remove/chai to main March 23, 2026 13:19
@Garbee Garbee marked this pull request as ready for review March 23, 2026 13:38
@Garbee Garbee requested a review from a team as a code owner March 23, 2026 13:38
@Garbee Garbee requested review from Copilot and straker March 23, 2026 13:38
@Garbee Garbee enabled auto-merge (squash) March 23, 2026 13:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the test HTTP mocking layer to use Undici’s MockAgent instead of nock, aligning request interception with Node’s native fetch stack and removing nock-related dependencies.

Changes:

  • Replaced nock usage in linter tests with undici MockAgent interceptors.
  • Removed nock / @types/nock from devDependencies and pruned lockfile entries.
  • Cleaned up duplicate dotfile exclusion tests in git test suite.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
yarn.lock Removes nock and its transitive dependencies from the lockfile.
package.json Drops nock and @types/nock from devDependencies.
src/linter.test.ts Migrates HTTP mocking from nock to Undici MockAgent + interceptors.
src/git.test.ts Removes duplicate test cases around dotfile/dot-directory exclusion.
Comments suppressed due to low confidence (1)

package.json:35

  • undici is imported/used in this test file but it isn't declared in package.json dependencies/devDependencies. Relying on a transitive/hoisted undici install (currently present in yarn.lock) can break in different package managers or after dependency graph changes. Add undici as an explicit devDependency (and keep the lockfile updated accordingly).
  "devDependencies": {
    "@eslint/js": "^9.20.0",
    "@types/mocha": "^10.0.10",
    "@types/node": "^24",
    "@types/sinon": "^17.0.3",
    "@vercel/ncc": "^0.38.3",
    "c8": "^10.1.3",
    "eslint": "^9.20.0",
    "eslint-plugin-mocha": "^10.5.0",
    "husky": "^9.1.7",
    "lint-staged": "^15.4.3",
    "mocha": "^11.1.0",
    "prettier": "^3.4.2",
    "rimraf": "^6.0.1",
    "sinon": "^19.0.2",
    "ts-node": "^10.9.2",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/linter.test.ts
Capture the original Undici dispatcher before installing MockAgent and
restore it in afterEach to prevent a closed dispatcher from leaking
into subsequent tests.
Comment thread src/git.test.ts
assert.ok(!result.includes('test.'))
})

it('should exclude dotfiles', async () => {
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.

Are these tests no longer needed? They seem unrelated to the undici change

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They are duplicates. Because of how Claude did the changes internally, it basically split things into multiple histories. This PR was actually not created off the previous one (even though my state locally was to do so.)

If you expand down further, you will see the tests are still there, the corrected forms from #103 .

@Garbee Garbee requested a review from straker March 23, 2026 19:36
@Garbee Garbee merged commit e9ae031 into main Mar 30, 2026
8 checks passed
@Garbee Garbee deleted the garbee/replace/nock branch March 30, 2026 14:25
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.

3 participants