Skip to content

feat(vitest): add TurboSnap support#404

Draft
AriPerkkio wants to merge 2 commits into
mainfrom
feat/vitest-turbosnap
Draft

feat(vitest): add TurboSnap support#404
AriPerkkio wants to merge 2 commits into
mainfrom
feat/vitest-turbosnap

Conversation

@AriPerkkio

@AriPerkkio AriPerkkio commented Jun 16, 2026

Copy link
Copy Markdown
Member

Issue: None, research issue at the moment.

What Changed

Adds chromaticPlugin({ turboSnap: boolean }) option for enabling TurboSnap. When true a .vitest/chromatic/preview-stats.json is generated. When (build-)archive-storybook is run, a custom webpack plugin appends stats.modules to contain the generated module graph.

image
Example preview-stats.json from separate project
{
  "modules": [
    {
      "id": "test/Accordion.test.tsx",
      "name": "test/Accordion.test.tsx",
      "reasons": [
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-accordion-9.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-accordion-14.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-accordion-17.stories.json"
        }
      ]
    },
    {
      "id": "vite.config.ts",
      "name": "vite.config.ts",
      "reasons": [
        {
          "moduleName": "test/Accordion.test.tsx"
        },
        {
          "moduleName": "test/Avatar.test.tsx"
        },
        {
          "moduleName": "test/Button.test.tsx"
        },
        {
          "moduleName": "test/Example.test.tsx"
        },
        {
          "moduleName": "test/sign-in/Page.test.tsx"
        },
        {
          "moduleName": "test/sign-out/Page.test.tsx"
        }
      ]
    },
    {
      "id": "src/lib/utils.ts",
      "name": "src/lib/utils.ts",
      "reasons": [
        {
          "moduleName": "src/components/retroui/Accordion.tsx"
        },
        {
          "moduleName": "src/components/retroui/Avatar.tsx"
        },
        {
          "moduleName": "src/components/retroui/Button.tsx"
        }
      ]
    },
    {
      "id": "src/components/retroui/Accordion.tsx",
      "name": "src/components/retroui/Accordion.tsx",
      "reasons": [
        {
          "moduleName": "test/Accordion.test.tsx"
        }
      ]
    },
    {
      "id": "test/Avatar.test.tsx",
      "name": "test/Avatar.test.tsx",
      "reasons": [
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-avatar-12.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-avatar-15.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-avatar-16.stories.json"
        }
      ]
    },
    {
      "id": "src/components/retroui/Avatar.tsx",
      "name": "src/components/retroui/Avatar.tsx",
      "reasons": [
        {
          "moduleName": "test/Avatar.test.tsx"
        }
      ]
    },
    {
      "id": "test/Button.test.tsx",
      "name": "test/Button.test.tsx",
      "reasons": [
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-button-8.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-button-11.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-button-13.stories.json"
        }
      ]
    },
    {
      "id": "src/components/retroui/Button.tsx",
      "name": "src/components/retroui/Button.tsx",
      "reasons": [
        {
          "moduleName": "test/Button.test.tsx"
        }
      ]
    },
    {
      "id": "test/Example.test.tsx",
      "name": "test/Example.test.tsx",
      "reasons": [
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-example-1.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-example-2.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-example-3.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/test-example-10.stories.json"
        }
      ]
    },
    {
      "id": "src/components/example/content.html",
      "name": "src/components/example/content.html",
      "reasons": [
        {
          "moduleName": "src/components/example/content.html"
        },
        {
          "moduleName": "test/Example.test.tsx"
        }
      ]
    },
    {
      "id": "src/components/example/styles.css",
      "name": "src/components/example/styles.css",
      "reasons": [
        {
          "moduleName": "test/Example.test.tsx"
        }
      ]
    },
    {
      "id": "test/sign-in/Page.test.tsx",
      "name": "test/sign-in/Page.test.tsx",
      "reasons": [
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/pages-sign-in-4.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/pages-sign-in-7.stories.json"
        }
      ]
    },
    {
      "id": "test/sign-out/Page.test.tsx",
      "name": "test/sign-out/Page.test.tsx",
      "reasons": [
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/pages-sign-out-5.stories.json"
        },
        {
          "moduleName": ".vitest/chromatic/chromatic-archives/pages-sign-out-6.stories.json"
        }
      ]
    }
  ]
}

How to test

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ae8cf21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@chromatic-com/vitest Patch

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@chromatic-com/cypress@ae8cf21 -D
npm i https://pkg.pr.new/@chromatic-com/playwright@ae8cf21 -D
npm i https://pkg.pr.new/@chromatic-com/vitest@ae8cf21 -D

commit: ae8cf21

@AriPerkkio AriPerkkio force-pushed the feat/vitest-turbosnap branch 6 times, most recently from ea68826 to 4257786 Compare June 18, 2026 08:06
@AriPerkkio AriPerkkio force-pushed the feat/vitest-turbosnap branch 3 times, most recently from 5b6d249 to 5353c6a Compare June 25, 2026 06:14
@AriPerkkio AriPerkkio requested a review from JReinhold June 25, 2026 06:14
@AriPerkkio AriPerkkio force-pushed the feat/vitest-turbosnap branch from 5353c6a to cc9ed34 Compare June 25, 2026 06:16

@JReinhold JReinhold left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Comment thread packages/vitest/src/node/webpack-stats-reporter.test.ts Outdated
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