Skip to content

fix(vitest-plugin-vis): show snapshot paths relative to the project root - #851

Merged
unional merged 1 commit into
mainfrom
cyberlegion/unit-d28d302b870e6699
Aug 21, 2026
Merged

fix(vitest-plugin-vis): show snapshot paths relative to the project root#851
unional merged 1 commit into
mainfrom
cyberlegion/unit-d28d302b870e6699

Conversation

@unional

@unional unional commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Closes #93.

The ask

use relative path to project root for failed snapshots — instead of abs path.

Two motivations, pointing the same way: terminals and editors linkify a project-relative path fine, and an absolute path leaks /home/<someone>/... into any failure output pasted into an issue.

The 2024 blocker is gone

The issue was parked on microsoft/vscode#237086 ("gitignored relative file link in Terminal not clickable"), with a note to fix it "once that is fixed and released". That issue closed verified in the November 2025 milestone and has long since shipped stable, so the premise holds and the reason to wait is gone.

The change

compare_image_snapshot.ts builds three failure messages — no baseline, matched-but-expected-to-fail, and mismatched. Every path in them was resolve(info.projectRoot, info.<baseline|result|diff>Path). info.*Path is already project-relative; the resolve() was what made it absolute.

Those Expected: / Actual: / Difference: lines now go through a new formatSnapshotPath helper in compare_image_snapshot.logic.ts:

Expected:   ./__vis__/local/HD/__baselines__/client/expect/to_match_image_snapshot.spec.tsx/case-1.png

Only the human-facing message strings changed. The ~20 other resolve(projectRoot, ...) call sites are filesystem I/O — writeSnapshot, tryReadFile, playwright's screenshot path, snapshot_path_limits.ts, the globs in vis_server_context.logic.ts — and all stay absolute. The three writeSnapshot calls in this same file still use resolve().

Judgment calls

  • ./ prefix. Both bare and ./-prefixed paths linkify, but the prefix marks the path unambiguously as relative rather than a bare package-ish name, and it survives copy-paste into a shell.
  • Outside the project root — reachable in a monorepo via a custom snapshotRootDir — falls back to absolute rather than emitting ../../../.. noise, which is neither shorter nor clearer.
  • Filenames beginning with .. (e.g. ..vis/) are not mistaken for an escape; the check is === '..' or startsWith('../'), not a bare startsWith('..').

Tests

  • Five unit tests for formatSnapshotPath in compare_image_snapshot.unit.ts: relative-within-root, absolute-within-root (the leak case), outside-root fallback, the root itself, and the ..-prefixed-filename edge case.
  • to_match_image_snapshot.spec.tsx now asserts the actual Expected: / Actual: / Difference: lines are ./__vis__/…-relative, on both the mismatch and the matched-but-expected-to-fail message. These assertions were confirmed to be genuinely exercised (deliberately breaking one fails the suite), not silently skipped by the specs' hasImageSnapshot() early return.

storybook-addon-vis surfaces no paths of its own — it renders these same messages from vitest-plugin-vis — so it is untouched. Its suite passes unchanged.

Verification

  • pnpm build — 7/7 tasks ✅
  • vitest-plugin-vis: 182 passed | 4 skipped (playwright), 87 passed | 1 skipped (node), tsc --noEmit clean
  • storybook-addon-vis: 83 passed
  • biome check clean on all changed files

Changeset: patch for vitest-plugin-vis.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J1RSK6XtmajN5fASgJHqVb

The `Expected:` / `Actual:` / `Difference:` lines in image snapshot failures
resolved `info.*Path` against `projectRoot`, printing an absolute path. Editors
and terminals resolve the project-relative path just as well, and the absolute
one leaks the local home directory into any failure output pasted into a bug
report.

The three message strings now go through `formatSnapshotPath`, which prints
`./`-prefixed project-relative paths and falls back to absolute for anything
outside the project root — possible in a monorepo via a custom
`snapshotRootDir` — where a `../../..` chain would be neither shorter nor
clearer. Filesystem operations are untouched and still resolve to absolute
paths.

Closes #93

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J1RSK6XtmajN5fASgJHqVb
@changeset-bot

changeset-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5364614

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

This PR includes changesets to release 2 packages
Name Type
vitest-plugin-vis Patch
storybook-addon-vis 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

@unional
unional enabled auto-merge August 21, 2026 06:03
@unional
unional merged commit aa4bf5d into main Aug 21, 2026
10 checks passed
@unional
unional deleted the cyberlegion/unit-d28d302b870e6699 branch August 21, 2026 06:06
@github-actions github-actions Bot mentioned this pull request Aug 21, 2026
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.

use relative path to project root for failed snapshots

1 participant