fix(vitest-plugin-vis): show snapshot paths relative to the project root - #851
Merged
Conversation
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 detectedLatest commit: 5364614 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #93.
The ask
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
verifiedin 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.tsbuilds three failure messages — no baseline, matched-but-expected-to-fail, and mismatched. Every path in them wasresolve(info.projectRoot, info.<baseline|result|diff>Path).info.*Pathis already project-relative; theresolve()was what made it absolute.Those
Expected:/Actual:/Difference:lines now go through a newformatSnapshotPathhelper incompare_image_snapshot.logic.ts:Only the human-facing message strings changed. The ~20 other
resolve(projectRoot, ...)call sites are filesystem I/O —writeSnapshot,tryReadFile, playwright's screenshotpath,snapshot_path_limits.ts, the globs invis_server_context.logic.ts— and all stay absolute. The threewriteSnapshotcalls in this same file still useresolve().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.snapshotRootDir— falls back to absolute rather than emitting../../../..noise, which is neither shorter nor clearer...(e.g...vis/) are not mistaken for an escape; the check is=== '..'orstartsWith('../'), not a barestartsWith('..').Tests
formatSnapshotPathincompare_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.tsxnow asserts the actualExpected:/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-vissurfaces no paths of its own — it renders these same messages fromvitest-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 --noEmitcleanstorybook-addon-vis: 83 passedbiome checkclean on all changed filesChangeset: patch for
vitest-plugin-vis.🤖 Generated with Claude Code
https://claude.ai/code/session_01J1RSK6XtmajN5fASgJHqVb