Skip to content

feat(vitest): add argosSnapshot for value snapshots anywhere - #339

Merged
gregberge merged 1 commit into
mainfrom
feat/vitest-argos-snapshot
Jul 9, 2026
Merged

gregberge merged 1 commit into
mainfrom
feat/vitest-argos-snapshot

Conversation

@gregberge

Copy link
Copy Markdown
Member

What

Adds an argosSnapshot(name, content, options?) API to @argos-ci/vitest that captures a snapshot of any value (not just a screenshot) and uploads it to Argos to diff across builds — mimicking Vitest snapshots.

Unlike argosScreenshot, it does not need a browser and works in both Vitest browser tests and plain Node tests.

import { test } from "vitest";
import { argosSnapshot } from "@argos-ci/vitest";

test("API response", async () => {
  const user = await fetchUser();
  await argosSnapshot("user", user); // serialized with @vitest/pretty-format
});

// custom extension + tags
await argosSnapshot("config", JSON.stringify(config, null, 2), {
  extension: ".json",
  tag: "config",
});

How it works

  • Serialization runs on the test side (strings verbatim, everything else via @vitest/pretty-format, or a custom serialize fn) so browser-only values (DOM nodes, class instances) are serialized before crossing the RPC boundary.
  • Dispatch: browser mode delegates to a new argosSnapshot browser command; Node writes directly to disk. Browser mode is detected via the __vitest_browser__ global.
  • Snapshots are written as <name>.snapshot.<ext> (+ a .argos.json metadata sidecar attributing them to the @argos-ci/vitest SDK and vitest). Supports root, extension, and tag.

Reporter

Updated to push snapshots: glob ["**/*.png", "**/*.aria.yml", "**/*.snapshot.*"] with ignore: ["**/*.argos.json"] so metadata sidecars aren't uploaded as snapshots.

Other changes

  • Export getSnapshotMimeType from @argos-ci/core.
  • Bundle @vitest/pretty-format into the dist — keeping it external made its transitive tinyrainbow dep unresolvable when Vitest pre-bundles the package for the browser.

Tests

  • Unit (29 passing): serialize, snapshot-file (writes real files to a temp dir — effectively a Node integration test), snapshot-command, updated reporter + index.
  • E2E (8 passing): two new browser tests exercising the full browser→node RPC + real file write for a value snapshot and a custom-extension snapshot.

Build, typecheck, lint, and format all pass. README documents the feature.

🤖 Generated with Claude Code

Add an `argosSnapshot(name, content, options?)` API that captures a snapshot
of any value (not just a screenshot) and uploads it to Argos to diff across
builds, mimicking Vitest snapshots (https://vitest.dev/guide/snapshot).

Unlike `argosScreenshot`, it does not need a browser and works in both
Vitest browser tests and plain Node tests:
- Serialization runs on the test side (strings verbatim, everything else via
  `@vitest/pretty-format`, or a custom `serialize` fn) so browser-only values
  are serialized before crossing the RPC boundary.
- In browser mode it delegates to a new `argosSnapshot` browser command; in
  Node it writes directly to disk. Browser mode is detected via the
  `__vitest_browser__` global.
- Snapshots are written as `<name>.snapshot.<ext>` (+ `.argos.json` metadata)
  and support `root`, `extension` and `tag` options.

Also:
- Update the reporter to upload snapshots (glob `**/*.snapshot.*`, ignoring
  `**/*.argos.json` sidecars).
- Export `getSnapshotMimeType` from `@argos-ci/core`.
- Bundle `@vitest/pretty-format` into the dist so its transitive `tinyrainbow`
  dep resolves when Vitest pre-bundles the package for the browser.
- Add unit tests (serialize, snapshot-file, command) and E2E coverage.

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

vercel Bot commented Jul 9, 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 7:37pm

Request Review

@gregberge
gregberge requested a review from jsfez July 9, 2026 19:39
@gregberge
gregberge merged commit 238e93c into main Jul 9, 2026
70 checks passed
@gregberge
gregberge deleted the feat/vitest-argos-snapshot branch July 9, 2026 19: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 — 0a6201f7 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