Skip to content

Commit 4a5c9bc

Browse files
authored
fix: make e2e tests resilient to version manager shims (#271)
1 parent caf3241 commit 4a5c9bc

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"scripts": {
3-
"task": "print foo && print bar"
4-
}
5-
}
1+
{}

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-command-change/snapshots.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
name = "cache miss command change"
55
steps = [
66
"vt run task # cache miss",
7-
"json-edit package.json '_.scripts.task = \"print baz && print bar\"' # change first subtask",
7+
"json-edit vite-task.json '_.tasks.task.command = \"print baz && print bar\"' # change first subtask",
88
"vt run task # first: cache miss, second: cache hit",
9-
"json-edit package.json '_.scripts.task = \"print bar\"' # remove first subtask",
9+
"json-edit vite-task.json '_.tasks.task.command = \"print bar\"' # remove first subtask",
1010
"vt run task # cache hit",
1111
]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/cache-miss-command-change/snapshots/cache miss command change.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bar
1111

1212
---
1313
vt run: 0/2 cache hit (0%). (Run `vt run --last-details` for full details)
14-
> json-edit package.json '_.scripts.task = "print baz && print bar"' # change first subtask
14+
> json-edit vite-task.json '_.tasks.task.command = "print baz && print bar"' # change first subtask
1515

1616
> vt run task # first: cache miss, second: cache hit
1717
$ print bazcache miss: args changed, executing
@@ -22,7 +22,7 @@ bar
2222

2323
---
2424
vt run: 1/2 cache hit (50%), <duration> saved. (Run `vt run --last-details` for full details)
25-
> json-edit package.json '_.scripts.task = "print bar"' # remove first subtask
25+
> json-edit vite-task.json '_.tasks.task.command = "print bar"' # remove first subtask
2626

2727
> vt run task # cache hit
2828
$ print bar ◉ cache hit, replaying
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"cache": true
2+
"tasks": {
3+
"task": {
4+
"command": "print foo && print bar"
5+
}
6+
}
37
}

crates/vite_task_bin/tests/e2e_snapshots/main.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,19 @@ fn main() {
477477
clippy::disallowed_types,
478478
reason = "Path required for CARGO_MANIFEST_DIR path traversal"
479479
)]
480-
let fixtures_dir = std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap())
481-
.join("tests")
482-
.join("e2e_snapshots")
483-
.join("fixtures");
480+
let fixtures_dir = {
481+
let manifest_dir =
482+
std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap());
483+
484+
// Copy .node-version to the tmp dir so version manager shims can resolve the correct
485+
// Node.js binary when running task commands.
486+
let repo_root = manifest_dir.join("../..").canonicalize().unwrap();
487+
std::fs::copy(repo_root.join(".node-version"), tmp_dir.path().join(".node-version"))
488+
.unwrap();
489+
490+
manifest_dir.join("tests/e2e_snapshots/fixtures")
491+
};
492+
484493
let mut fixture_paths = std::fs::read_dir(fixtures_dir)
485494
.unwrap()
486495
.map(|entry| entry.unwrap().path())

0 commit comments

Comments
 (0)