Skip to content

Commit 4b0af9e

Browse files
wan9chicodex
andcommitted
test(e2e): clarify vite env cache fixture
Co-authored-by: GPT-5 Codex <codex@openai.com>
1 parent 6ab86c3 commit 4b0af9e

3 files changed

Lines changed: 41 additions & 48 deletions

File tree

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[e2e]]
22
name = "vite_prefix_env_change_invalidates_cache"
33
comment = """
4-
`VITE_MODE` is picked up by Vite's patched `loadEnv`, which asks the runner for every `VITE_*` env via `getEnvs(pattern, { tracked: true })`. Flipping its value between runs must invalidate the cache AND change the build output Vite's `define` plugin substitutes `import.meta.env.VITE_MODE` at build time, so dead-code elimination leaves only the branch matching the value.
4+
`VITE_CACHE_LABEL` is picked up by Vite's patched `loadEnv`, which asks the runner for every `VITE_*` env via `getEnvs(pattern, { tracked: true })`. Flipping its value between runs must invalidate the cache AND change the build output because Vite substitutes `import.meta.env.VITE_CACHE_LABEL` at build time.
55
"""
66
ignore = true
77
steps = [
@@ -12,56 +12,56 @@ steps = [
1212
"build",
1313
], envs = [
1414
[
15-
"VITE_MODE",
16-
"production",
15+
"VITE_CACHE_LABEL",
16+
"cache-alpha",
1717
],
18-
], comment = "first run: production build" },
18+
], comment = "first run: cache-alpha label" },
1919
{ argv = [
2020
"vtt",
2121
"grep-file",
2222
"dist/assets/main.js",
23-
"BUILD_MODE_PROD",
24-
], comment = "production build: PROD marker survived DCE" },
23+
"cache-alpha",
24+
], comment = "cache-alpha label is in the bundle" },
2525
{ argv = [
2626
"vtt",
2727
"grep-file",
2828
"dist/assets/main.js",
29-
"BUILD_MODE_DEV",
30-
], comment = "dev branch is gone" },
29+
"cache-bravo",
30+
], comment = "cache-bravo label is not in the bundle yet" },
3131
{ argv = [
3232
"vt",
3333
"run",
3434
"--cache",
3535
"build",
3636
], envs = [
3737
[
38-
"VITE_MODE",
39-
"production",
38+
"VITE_CACHE_LABEL",
39+
"cache-alpha",
4040
],
41-
], comment = "cache hit: VITE_MODE unchanged" },
41+
], comment = "cache hit: VITE_CACHE_LABEL unchanged" },
4242
{ argv = [
4343
"vt",
4444
"run",
4545
"--cache",
4646
"build",
4747
], envs = [
4848
[
49-
"VITE_MODE",
50-
"development",
49+
"VITE_CACHE_LABEL",
50+
"cache-bravo",
5151
],
52-
], comment = "cache miss: envs changed — VITE_MODE value changed" },
52+
], comment = "cache miss: envs changed — VITE_CACHE_LABEL value changed" },
5353
{ argv = [
5454
"vtt",
5555
"grep-file",
5656
"dist/assets/main.js",
57-
"BUILD_MODE_PROD",
58-
], comment = "PROD marker gone after the dev rebuild" },
57+
"cache-alpha",
58+
], comment = "cache-alpha label is gone after the rebuild" },
5959
{ argv = [
6060
"vtt",
6161
"grep-file",
6262
"dist/assets/main.js",
63-
"BUILD_MODE_DEV",
64-
], comment = "DEV marker now in the bundle" },
63+
"cache-bravo",
64+
], comment = "cache-bravo label is now in the bundle" },
6565
]
6666

6767
[[e2e]]
@@ -105,4 +105,3 @@ steps = [
105105
],
106106
], comment = "cache miss: envs changed (NODE_ENV changed)" },
107107
]
108-
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
# vite_prefix_env_change_invalidates_cache
22

3-
`VITE_MODE` is picked up by Vite's patched `loadEnv`, which asks the runner for every `VITE_*` env via `getEnvs(pattern, { tracked: true })`. Flipping its value between runs must invalidate the cache AND change the build output Vite's `define` plugin substitutes `import.meta.env.VITE_MODE` at build time, so dead-code elimination leaves only the branch matching the value.
3+
`VITE_CACHE_LABEL` is picked up by Vite's patched `loadEnv`, which asks the runner for every `VITE_*` env via `getEnvs(pattern, { tracked: true })`. Flipping its value between runs must invalidate the cache AND change the build output because Vite substitutes `import.meta.env.VITE_CACHE_LABEL` at build time.
44

5-
## `VITE_MODE=production vt run --cache build`
5+
## `VITE_CACHE_LABEL=cache-alpha vt run --cache build`
66

7-
first run: production build
7+
first run: cache-alpha label
88

99
```
1010
$ vite build
1111
```
1212

13-
## `vtt grep-file dist/assets/main.js BUILD_MODE_PROD`
13+
## `vtt grep-file dist/assets/main.js cache-alpha`
1414

15-
production build: PROD marker survived DCE
15+
cache-alpha label is in the bundle
1616

1717
```
18-
dist/assets/main.js: found "BUILD_MODE_PROD"
18+
dist/assets/main.js: found "cache-alpha"
1919
```
2020

21-
## `vtt grep-file dist/assets/main.js BUILD_MODE_DEV`
21+
## `vtt grep-file dist/assets/main.js cache-bravo`
2222

23-
dev branch is gone
23+
cache-bravo label is not in the bundle yet
2424

2525
```
26-
dist/assets/main.js: missing "BUILD_MODE_DEV"
26+
dist/assets/main.js: missing "cache-bravo"
2727
```
2828

29-
## `VITE_MODE=production vt run --cache build`
29+
## `VITE_CACHE_LABEL=cache-alpha vt run --cache build`
3030

31-
cache hit: VITE_MODE unchanged
31+
cache hit: VITE_CACHE_LABEL unchanged
3232

3333
```
3434
$ vite build ◉ cache hit, replaying
@@ -37,26 +37,26 @@ $ vite build ◉ cache hit, replaying
3737
vt run: cache hit.
3838
```
3939

40-
## `VITE_MODE=development vt run --cache build`
40+
## `VITE_CACHE_LABEL=cache-bravo vt run --cache build`
4141

42-
cache miss: envs changed — VITE_MODE value changed
42+
cache miss: envs changed — VITE_CACHE_LABEL value changed
4343

4444
```
45-
$ vite build ○ cache miss: env 'VITE_MODE' changed, executing
45+
$ vite build ○ cache miss: env 'VITE_CACHE_LABEL' changed, executing
4646
```
4747

48-
## `vtt grep-file dist/assets/main.js BUILD_MODE_PROD`
48+
## `vtt grep-file dist/assets/main.js cache-alpha`
4949

50-
PROD marker gone after the dev rebuild
50+
cache-alpha label is gone after the rebuild
5151

5252
```
53-
dist/assets/main.js: missing "BUILD_MODE_PROD"
53+
dist/assets/main.js: missing "cache-alpha"
5454
```
5555

56-
## `vtt grep-file dist/assets/main.js BUILD_MODE_DEV`
56+
## `vtt grep-file dist/assets/main.js cache-bravo`
5757

58-
DEV marker now in the bundle
58+
cache-bravo label is now in the bundle
5959

6060
```
61-
dist/assets/main.js: found "BUILD_MODE_DEV"
61+
dist/assets/main.js: found "cache-bravo"
6262
```
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// `import.meta.env.VITE_MODE` is replaced at build time from the value vite
2-
// picks up for keys matching `envPrefix` (`VITE_` by default). The markers
3-
// let the e2e test assert that flipping VITE_MODE actually changed what was
4-
// built and that glob-tracking invalidates the cache.
5-
if (import.meta.env.VITE_MODE === 'production') {
6-
document.body.append('BUILD_MODE_PROD');
7-
} else {
8-
document.body.append('BUILD_MODE_DEV');
9-
}
1+
// Vite replaces this at build time from keys matching `envPrefix` (`VITE_` by
2+
// default), so the e2e can verify that glob-tracked env changes rebuild output.
3+
console.log(import.meta.env.VITE_CACHE_LABEL);

0 commit comments

Comments
 (0)