Skip to content

fix: fix suite hook throwing errors for unused auto test-scoped fixture#10035

Open
hi-ogawa wants to merge 7 commits intovitest-dev:mainfrom
hi-ogawa:fix-support-test-scoped-auto-fixture-with-beforeall-non-test-scoped-fixture
Open

fix: fix suite hook throwing errors for unused auto test-scoped fixture#10035
hi-ogawa wants to merge 7 commits intovitest-dev:mainfrom
hi-ogawa:fix-support-test-scoped-auto-fixture-with-beforeall-non-test-scoped-fixture

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented Apr 1, 2026

Description

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 1, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9c8741f
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69cc7daa2b90e700088bd1be
😎 Deploy Preview https://deploy-preview-10035--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa marked this pull request as ready for review April 1, 2026 02:31
for (const fixture of registrations.values()) {
if (fixture.auto || usedProps.has(fixture.name)) {
// suite hook shouldn't automatically trigger unused test-scoped fixtures
const auto = fixture.auto && !(options?.suiteHook && fixture.scope === 'test')
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.

Can we make the check simpler? fixture.auto && !(options?.suiteHook && fixture.scope === 'test') is vile

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I also argued so hard with Codex 🤣

I thought of some options and ended up with what I have now.

  • fixture.auto && !(options?.suiteHook && fixture.scope === 'test')
  • fixture.auto && (!options?.suiteHook || fixture.scope !== 'test')
  • fixture.auto && (options?.suiteHook ? fixture.scope !== 'test' : true)
  • options?.suiteHook ? (fixture.auto && fixture.scope !== 'test') : fixture.auto

I might prefer the last one actually.

for (const fixture of registrations.values()) {
if (fixture.auto || usedProps.has(fixture.name)) {
// suite hook shouldn't automatically trigger unused test-scoped fixtures
const auto = fixture.auto && !(options?.suiteHook && fixture.scope === 'test')
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes or no 👀

Suggested change
const auto = fixture.auto && !(options?.suiteHook && fixture.scope === 'test')
const auto = options?.suiteHook ? (fixture.auto && fixture.scope !== 'test') : fixture.auto

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.

@AriPerkkio help us

I think we should do a multi line check

if(!fixture.auto) return false
const isSuiteScope = !!options?.suiteHook
return suiteScope ? fixture.scope !== 'test' : fixture.scope === 'test'

Something like this

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.

fixture.auto && !(options?.suiteHook && fixture.scope === 'test')

😱

I would probably write this into a fully verbose function.

function isAuto(fixture, options) {
  if (!fixture.auto) {
    return false;
  }
  
  if (options.suiteHook && fixture.scope === "test") {
    return false;
  }
  
  return true;
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switched to isAutoFixture 🚘

hi-ogawa and others added 2 commits April 1, 2026 18:16
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Fixture Scope Mismatch Issue

3 participants