Skip to content

feat(vitest): add standalone @argos-ci/vitest package - #337

Merged
gregberge merged 2 commits into
mainfrom
feat/vitest-package
Jul 9, 2026
Merged

gregberge merged 2 commits into
mainfrom
feat/vitest-package

Conversation

@gregberge

Copy link
Copy Markdown
Member

Summary

Extracts the generic Vitest browser-mode screenshot machinery out of @argos-ci/storybook into a new @argos-ci/vitest package that works standalone and is reused by the storybook package. The goal: take Argos screenshots while Vitest runs browser tests.

// vitest.config.ts
import { argosVitestPlugin } from "@argos-ci/vitest/plugin";
plugins: [argosVitestPlugin({ uploadToArgos: process.env.CI === "true" })]

// my.test.tsx (browser mode)
import { argosScreenshot } from "@argos-ci/vitest";
test("Button", async () => {
  render(<Button>Click me</Button>);
  await argosScreenshot("button");
});

What's in the package

  • . (browser): argosScreenshot(name, options?) + the vitest/browser command augmentation. Node-free (only import type + a lazy import("vitest/browser")).
  • ./plugin (node): argosVitestPlugin — registers the browser command and the upload reporter.
  • ./internal (node, unstable): shared iframe utils + screenshotFrame primitive consumed by storybook.

The ArgosReporter and the iframe DOM ops (tester-scale reset, iframe viewport resize, grow-to-fit) were moved verbatim; storybook now imports them instead of inlining copies.

Design notes

  • RPC-safe boundary: per-call options are JSON-serializable; functions/Locators go on the plugin (node side) and are merged in the command closure.
  • Backward compatible: every @argos-ci/storybook published export is unchanged. Its internal browser command key was renamed argosScreenshot → argosStorybookScreenshot to avoid a vitest/browser BrowserCommands augmentation clash. The public argosScreenshot(story, name) function name is kept.
  • Single vitest peer instance: storybook declared no @types/node, so its vitest peer resolved to v26 while the catalog pins v22 — two vitest/node instances meant the @vitest/browser-playwright ctx.page/frame augmentation didn't apply cross-package. Aligned storybook to the catalog @types/node.

Tests

  • Unit (node project): reporter (upload / watch-skip / failure / log), command (merge precedence, node-hook preservation, viewport naming, SDK metadata), env detection.
  • Browser e2e (real Chromium): reads written files back via server.commands.readFile to assert metadata (sdk=@argos-ci/vitest, automationLibrary=@vitest/browser-playwright, per-viewport viewport), ariaSnapshot forwarding, and the horizontal fitWidth path via PNG-width decode.
  • Added an e2e-vitest CI job; .prettierignore scoped to /packages/*/{test-results,screenshots}.

Verification

  • Whole-repo turbo run check-types lint check-format test → 53/53 tasks green.
  • Standalone e2e (6) + storybook Vitest e2e (15) pass; screenshots write to disk with correct metadata.

🤖 Generated with Claude Code

Extract the generic Vitest browser-mode screenshot machinery out of
@argos-ci/storybook into a new @argos-ci/vitest package that works
standalone and is reused by the storybook package.

- New package @argos-ci/vitest with:
  - browser API `argosScreenshot(name, options?)` (entry `.`)
  - `argosVitestPlugin` (entry `./plugin`) registering the browser
    command and the upload reporter
  - shared iframe utils + `screenshotFrame` primitive (entry
    `./internal`) consumed by storybook
- Move ArgosReporter and the iframe DOM ops (tester-scale reset,
  iframe viewport resize, grow-to-fit) verbatim; storybook now imports
  them instead of inlining copies.
- Keep every storybook published export byte-for-byte compatible;
  rename its internal browser command key to `argosStorybookScreenshot`
  to avoid the `vitest/browser` BrowserCommands augmentation clash.
- Align storybook to the catalog `@types/node` so a single vitest
  peer instance is resolved across packages.
- Add unit + browser e2e tests, docs, and an e2e-vitest CI job.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
argos-js-sdk-reference Ready Ready Preview, Comment Jul 9, 2026 6:36pm

Request Review

The Vitest reporter called `upload()` without a `files` glob, so it fell
back to the default `**/*.{png,jpg,jpeg}` and never uploaded the
`.aria.yml` files produced by `ariaSnapshot: true`. Default the glob to
`["**/*.png", "**/*.aria.yml"]` (matching the Playwright reporter) while
still letting the config override it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gregberge
gregberge merged commit c7e5b08 into main Jul 9, 2026
70 checks passed
@gregberge
gregberge deleted the feat/vitest-package branch July 9, 2026 18:40
@linear-code

linear-code Bot commented Jul 9, 2026

Copy link
Copy Markdown

ARG-321

This branch was successfully deployed

1 active deployment
Preview — 8b4c5637 Deployed Jul 9, 2026 by vercel[bot]
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.

1 participant