Skip to content

Add inline snapshots (insta-style)#450

Merged
MatthewMckee4 merged 3 commits intomainfrom
add-inline-snapshots
Feb 10, 2026
Merged

Add inline snapshots (insta-style)#450
MatthewMckee4 merged 3 commits intomainfrom
add-inline-snapshots

Conversation

@MatthewMckee4
Copy link
Member

Summary

  • Add inline snapshot support via karva.assert_snapshot(value, inline="") where expected values live directly in test source files
  • Source files are rewritten in-place with --snapshot-update, or .snap.new files with inline metadata are created for karva snapshot accept
  • New karva_snapshot::inline module handles dedenting, string literal generation, source scanning, and file rewriting

Test plan

  • Unit tests for dedent, generate_inline_literal, find_inline_argument, apply_edit
  • Integration tests for inline snapshot creation, matching, mismatch, update, multiline, multiple per test, accept, reject, and pending flows
  • just test passes (521 tests)
  • prek run -a passes

🤖 Generated with Claude Code

Inline snapshots let users embed expected values directly in test source
files via `karva.assert_snapshot(value, inline="")`. On first run or
mismatch with `--snapshot-update`, the source file is rewritten in-place.
Without `--snapshot-update`, a `.snap.new` file with inline metadata is
created so `karva snapshot accept` can rewrite the source later.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MatthewMckee4 MatthewMckee4 added the snapshot-testing Related to snapshot testing label Feb 10, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 10, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing add-inline-snapshots (1d3fabc) with main (fc76cea)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 1 untouched benchmark

Rewrite find_inline_argument to bound search within the assert_snapshot()
call using paren-depth tracking, preventing false matches on later calls.
Add find_keyword_in_call to skip string literals/comments. Remove dead
code, fix O(n²) dedent, refactor duplicated frame logic, add roundtrip test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MatthewMckee4 MatthewMckee4 merged commit 6add357 into main Feb 10, 2026
9 checks passed
@MatthewMckee4 MatthewMckee4 deleted the add-inline-snapshots branch February 10, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot-testing Related to snapshot testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant