Skip to content

Commit 64f1651

Browse files
branchseerclaude
andcommitted
test(e2e): assert output existence, not content, in vite_build_cache
The previous snapshot embedded Vite's minified JS output, which would churn on every Vite version bump. Add a tiny `vtt stat-file` helper that reports `exists` / `missing` and use that instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 92339ae commit 64f1651

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

crates/vite_task_bin/src/vtt/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mod print_file;
2020
mod read_stdin;
2121
mod replace_file_content;
2222
mod rm;
23+
mod stat_file;
2324
mod touch_file;
2425
mod write_file;
2526

@@ -28,7 +29,7 @@ fn main() {
2829
if args.len() < 2 {
2930
eprintln!("Usage: vtt <subcommand> [args...]");
3031
eprintln!(
31-
"Subcommands: barrier, check-tty, cp, exit, exit-on-ctrlc, mkdir, pipe-stdin, print, print-cwd, print-env, print-file, read-stdin, replace-file-content, rm, touch-file, write-file"
32+
"Subcommands: barrier, check-tty, cp, exit, exit-on-ctrlc, mkdir, pipe-stdin, print, print-cwd, print-env, print-file, read-stdin, replace-file-content, rm, stat-file, touch-file, write-file"
3233
);
3334
std::process::exit(1);
3435
}
@@ -54,6 +55,10 @@ fn main() {
5455
"read-stdin" => read_stdin::run(),
5556
"replace-file-content" => replace_file_content::run(&args[2..]),
5657
"rm" => rm::run(&args[2..]),
58+
"stat-file" => {
59+
stat_file::run(&args[2..]);
60+
Ok(())
61+
}
5762
"touch-file" => touch_file::run(&args[2..]),
5863
"write-file" => write_file::run(&args[2..]),
5964
other => {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub fn run(args: &[String]) {
2+
for file in args {
3+
if std::fs::metadata(file).is_ok() {
4+
println!("{file}: exists");
5+
} else {
6+
println!("{file}: missing");
7+
}
8+
}
9+
}

crates/vite_task_bin/tests/e2e_snapshots/fixtures/vite_build_cache/snapshots.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ name = "vite_build_caches_and_restores_outputs"
99
ignore = true
1010
steps = [
1111
["vt", "run", "--cache", "build"],
12-
# Verify the build emitted output.
13-
["vtt", "print-file", "dist/assets/main.js"],
12+
# Verify the build emitted output (existence check; content is Vite's
13+
# minified JS and would make the snapshot brittle across Vite versions).
14+
["vtt", "stat-file", "dist/assets/main.js"],
1415
# Delete the output artefact and re-run — the cache hit should restore it.
1516
["vtt", "rm", "dist/assets/main.js"],
1617
{ argv = ["vt", "run", "--cache", "build"], comment = "cache hit: outputs restored without manual config" },
17-
["vtt", "print-file", "dist/assets/main.js"],
18+
["vtt", "stat-file", "dist/assets/main.js"],
1819
]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/vite_build_cache/snapshots/vite_build_caches_and_restores_outputs.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
$ vite build
77
```
88

9-
## `vtt print-file dist/assets/main.js`
9+
## `vtt stat-file dist/assets/main.js`
1010

1111
```
12-
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})(),document.body.append((e=>`hello, ${e}`)(`vite`));
12+
dist/assets/main.js: exists
1313
```
1414

1515
## `vtt rm dist/assets/main.js`
@@ -28,8 +28,8 @@ $ vite build ◉ cache hit, replaying
2828
vt run: cache hit.
2929
```
3030

31-
## `vtt print-file dist/assets/main.js`
31+
## `vtt stat-file dist/assets/main.js`
3232

3333
```
34-
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})(),document.body.append((e=>`hello, ${e}`)(`vite`));
34+
dist/assets/main.js: exists
3535
```

0 commit comments

Comments
 (0)