Skip to content

test: Mock spinner#1418

Open
snocorp wants to merge 3 commits into
mainfrom
mock-spinner
Open

test: Mock spinner#1418
snocorp wants to merge 3 commits into
mainfrom
mock-spinner

Conversation

@snocorp

@snocorp snocorp commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

Mock spinner allows tests to avoid sending output to stderr.

Testing

Fixed the bootstrapLocalTemplate tests and added some assertions as an example.


Note

Low Risk
Test-only and test-helper changes with no production runtime behavior.

Overview
Adds createMockSpinner to @sanity/cli-test: a Vitest mock factory for @sanity/cli-core/ux’s spinner that returns a full SpinnerInstance stub (with optional overrides) so CLI tests avoid real terminal output.

bootstrapLocalTemplate integration tests now mock spinner from @sanity/cli-core/ux via that helper, dynamically import the module under test after mocks are registered, and drop the old output.spinner / print / clear stubs on the fake Output. Tests assert spinner usage (e.g. initial message, three start/succeed cycles per bootstrap).

@sanity/cli-test tsconfig gains a @sanity/cli-core/* path alias so the new helper can import SpinnerInstance from the ux subpath.

Reviewed by Cursor Bugbot for commit 064a258. Bugbot is set up for automated code reviews on this repo. Configure here.

@snocorp snocorp requested a review from filmaj July 1, 2026 21:04
@snocorp snocorp self-assigned this Jul 1, 2026
@snocorp snocorp requested a review from a team as a code owner July 1, 2026 21:04
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against main (01d2f80d)

@sanity/cli

Metric Value vs main (01d2f80)
Internal (raw) 2.7 KB -
Internal (gzip) 1.0 KB -
Bundled (raw) 11.16 MB -
Bundled (gzip) 2.10 MB -
Import time 868ms +5ms, +0.6%

bin:sanity

Metric Value vs main (01d2f80)
Internal (raw) 782 B -
Internal (gzip) 423 B -
Bundled (raw) 9.87 MB -
Bundled (gzip) 1.78 MB -
Import time 2.21s +4ms, +0.2%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (01d2f80d)

Metric Value vs main (01d2f80)
Internal (raw) 106.7 KB -
Internal (gzip) 26.7 KB -
Bundled (raw) 21.72 MB -
Bundled (gzip) 3.46 MB -
Import time 765ms -7ms, -0.9%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against main (01d2f80d)

Metric Value vs main (01d2f80)
Internal (raw) 908 B -
Internal (gzip) 483 B -
Bundled (raw) 931 B -
Bundled (gzip) 491 B -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Coverage Delta

No covered files changed in this PR.

Overall Coverage

Metric Coverage
Statements 74.5% (±0%)
Branches 64.3% (±0%)
Functions 69.0% (±0%)
Lines 75.1% (±0%)

@runeb runeb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@snocorp Looks good, just a question. I see this is in integration tests. We do want to catch issues with spinners and for example non-interactive users like agents. Will we still be able to ensure progress indication doesnt break any of the flows we care about?

@snocorp

snocorp commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@snocorp Looks good, just a question. I see this is in integration tests. We do want to catch issues with spinners and for example non-interactive users like agents. Will we still be able to ensure progress indication doesnt break any of the flows we care about?

Good question. I think this generally makes it easier to verify the spinner is used as expected. I suppose it's possible that a new version of the spinner could break something so we shouldn't mock all the places we use it. In many existing test cases the output would get swallowed by the output capture that happens when you use testCommand and we can assert the output there so that should cover enough to be safe.

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