Skip to content

Commit f9d1ab5

Browse files
branchseerclaude
andcommitted
Support cross-platform e2e snapshot testing via cargo-xtest
Use staged temp dir for insta snapshot paths so writes work on read-only filesystems (e.g. WebDAV mount during cargo-xtest). Skip INSTA_REQUIRE_FULL_MATCH when INSTA_UPDATE is set, allowing cross-platform runs to accept metadata-only snapshot changes. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 8d3e9df commit f9d1ab5

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • crates/vite_task_bin/tests/e2e_snapshots

crates/vite_task_bin/tests/e2e_snapshots/main.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ fn run_case(tmpdir: &AbsolutePath, fixture_path: &std::path::Path, filter: Optio
190190
{
191191
println!("{fixture_name}");
192192
}
193-
// Configure insta to write snapshots to fixture directory
194193
let mut settings = insta::Settings::clone_current();
195-
settings.set_snapshot_path(fixture_path.join("snapshots"));
196194
settings.set_prepend_module_to_snapshot(false);
197195
settings.remove_snapshot_suffix();
198196

@@ -217,6 +215,13 @@ fn run_case_inner(tmpdir: &AbsolutePath, fixture_path: &std::path::Path, fixture
217215
let stage_path = tmpdir.join(fixture_name);
218216
CopyOptions::new().copy_tree(fixture_path, stage_path.as_path()).unwrap();
219217

218+
// Point insta at the staged copy's snapshot dir (which is writable). The
219+
// original fixture_path may be on a read-only filesystem (e.g. WebDAV mount
220+
// during cross-platform testing via cargo-xtest).
221+
let mut settings = insta::Settings::clone_current();
222+
settings.set_snapshot_path(stage_path.as_path().join("snapshots"));
223+
let _guard = settings.bind_to_scope();
224+
220225
let (workspace_root, _cwd) = find_workspace_root(&stage_path).unwrap();
221226

222227
assert_eq!(
@@ -418,7 +423,13 @@ fn run_case_inner(tmpdir: &AbsolutePath, fixture_path: &std::path::Path, fixture
418423

419424
fn main() {
420425
// SAFETY: Called before any threads are spawned; insta reads this lazily on first assertion.
421-
unsafe { std::env::set_var("INSTA_REQUIRE_FULL_MATCH", "1") };
426+
// Skip INSTA_REQUIRE_FULL_MATCH when running cross-platform (via cargo-xtest): the snapshot
427+
// source metadata changes when the test binary runs on a remote machine, causing insta to
428+
// write .snap.new even when content matches. INSTA_UPDATE=always in this mode accepts
429+
// metadata-only changes.
430+
if std::env::var_os("INSTA_UPDATE").is_none() {
431+
unsafe { std::env::set_var("INSTA_REQUIRE_FULL_MATCH", "1") };
432+
}
422433

423434
let filter = std::env::args().nth(1);
424435

0 commit comments

Comments
 (0)