Skip to content

test: replace sinon with node:test mocks - #707

Open
zimeg wants to merge 2 commits into
mainfrom
test-node-mocks
Open

zimeg wants to merge 2 commits into
mainfrom
test-node-mocks

Conversation

@zimeg

@zimeg zimeg commented Nov 3, 2026

Copy link
Copy Markdown
Member

Summary

This pull request replaces sinon with the mocks built into node:test. Tests already run on node --test and Node 24 is the minimum version, so sinon was one more dependency to keep updated for features the test runner already has.

  • Converts the shared Mock helper in test/index.spec.js first. reset() now calls mock.reset() and builds new mocks, instead of resetting each sinon stub one at a time.
  • Since node:test has no withArgs, the helper gives core.getInput, core.getBooleanInput, and fs.readFileSync implementations that check their arguments against the inputs, booleanInputs, and files maps. Specs change getInput.withArgs(k).returns(v) into mocks.inputs.set(k, v).
  • Replaces sandbox.stub(fs), which stubbed every fs function, with mock.method on readFileSync only. It is the only fs function the source calls, and the mock still checks for the "utf-8" encoding.
  • Converts the rest of the sinon API to node:test:
    • getCall(i).firstArg/lastArg → mock.calls[i].arguments[n]
    • resolves/rejects/returns → mock.mockImplementation
    • called/calledOnce → mock.callCount()
    • calledWith → assert.deepEqual on mock.calls[i].arguments
    • calledWithNew → mock.calls[i].target
  • Removes sinon and @types/sinon from devDependencies, so Dependabot stops opening bumps for them (e.g. build(deps-dev): bump @types/sinon from 22.0.0 to 22.0.2 #699).

Testing

  • npm test reports 85 tests in 28 suites, all passing, both on main and on this branch.
  • I broke the helper's argument checks on purpose to confirm the specs depend on them. Expecting "utf8" instead of "utf-8" fails 7 content tests, and making getInput always return undefined fails 13 config tests.

Requirements

🤖 Generated with Claude Code

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg zimeg added this to the 4.1 milestone Nov 3, 2026
@zimeg zimeg added dependencies Pull requests that update a dependency file semver:patch tests labels Nov 3, 2026
@zimeg zimeg self-assigned this Nov 3, 2026
@changeset-bot

changeset-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5fb1647

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.86%. Comparing base (83ebce6) to head (5fb1647).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #707   +/-   ##
=======================================
  Coverage   99.86%   99.86%           
=======================================
  Files           8        8           
  Lines         732      732           
=======================================
  Hits          731      731           
  Misses          1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zimeg zimeg left a comment

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.

🧪 Comments before requesting review!

Comment thread package.json
"@types/node": "^24.19.2",
"@types/sinon": "^22.0.2",
"@vercel/ncc": "^0.45.0",
"sinon": "^22.1.0",

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.

🫡 praise: Thanks for kindest stubs and such more in testing.

Comment thread test/index.spec.js
};
this.core.getInput.withArgs("errors").returns("false");
this.core.getInput.withArgs("retries").returns("5");
this.reset();

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.

👁️‍🗨️ note: This reduces duplication but I found confusing at first glance. Wont change it for now though since I think the setup and reset pattern is nice.

@zimeg
zimeg marked this pull request as ready for review November 4, 2026 07:06
@zimeg
zimeg requested a review from a team as a code owner November 4, 2026 07:06

This branch was successfully deployed

1 active deployment
staging — 5fb1647e Deployed Nov 4, 2026 by zimeg via Run API tests #368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file semver:patch tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant