Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<title>vp-run-vite-cache</title>
</head>
<body>
<script type="module" src="/src/main.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "vite-build-cache-fixture",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
[[e2e]]
name = "vite_build_caches_and_restores_outputs"
comment = """
`vt run --cache build` must produce a cache hit on the second run without any manual input/output configuration. Vite reports `ignoreInput(outDir)` + `ignoreInput/Output(cacheDir)` via `@voidzero-dev/vite-task-client`, so fspy-detected reads of `dist/` and writes to `node_modules/.vite/` don't poison the cache.
"""
ignore = true
steps = [
{ argv = [
"vt",
"run",
"--cache",
"build",
], comment = "first run: cache miss, emits dist/" },
{ argv = [
"vtt",
"stat-file",
"dist/assets/main.js",
], comment = "existence check — content would drift across Vite versions" },
{ argv = [
"vtt",
"rm",
"dist/assets/main.js",
], comment = "remove the artefact so the cache-hit restore is observable" },
{ argv = [
"vt",
"run",
"--cache",
"build",
], comment = "cache hit: outputs restored without manual config" },
{ argv = [
"vtt",
"stat-file",
"dist/assets/main.js",
], comment = "restored from the cache archive" },
]

[[e2e]]
name = "vite_prefix_env_change_invalidates_cache"
comment = """
`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.
"""
ignore = true
steps = [
{ argv = [
"vt",
"run",
"--cache",
"build",
], envs = [
[
"VITE_MODE",
"production",
],
], comment = "first run: production build" },
{ argv = [
"vtt",
"grep-file",
"dist/assets/main.js",
"BUILD_MODE_PROD",
], comment = "production build: PROD marker survived DCE" },
{ argv = [
"vtt",
"grep-file",
"dist/assets/main.js",
"BUILD_MODE_DEV",
], comment = "dev branch is gone" },
{ argv = [
"vt",
"run",
"--cache",
"build",
], envs = [
[
"VITE_MODE",
"production",
],
], comment = "cache hit: VITE_MODE unchanged" },
{ argv = [
"vt",
"run",
"--cache",
"build",
], envs = [
[
"VITE_MODE",
"development",
],
], comment = "cache miss: tracked env glob `VITE_*` — VITE_MODE value changed" },
{ argv = [
"vtt",
"grep-file",
"dist/assets/main.js",
"BUILD_MODE_PROD",
], comment = "PROD marker gone after the dev rebuild" },
{ argv = [
"vtt",
"grep-file",
"dist/assets/main.js",
"BUILD_MODE_DEV",
], comment = "DEV marker now in the bundle" },
]

[[e2e]]
name = "vite_node_env_change_invalidates_cache"
comment = """
`NODE_ENV` enters the build's cache fingerprint via Vite's `getEnv('NODE_ENV')` call in `resolveConfig`. Same value → cache hit; different value → cache miss with `tracked env 'NODE_ENV' changed`.
"""
ignore = true
steps = [
{ argv = [
"vt",
"run",
"--cache",
"build",
], envs = [
[
"NODE_ENV",
"production",
],
], comment = "first run: NODE_ENV=production" },
{ argv = [
"vt",
"run",
"--cache",
"build",
], envs = [
[
"NODE_ENV",
"production",
],
], comment = "cache hit: NODE_ENV unchanged" },
{ argv = [
"vt",
"run",
"--cache",
"build",
], envs = [
[
"NODE_ENV",
"development",
],
], comment = "cache miss: tracked env 'NODE_ENV' changed" },
]

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# vite_build_caches_and_restores_outputs

`vt run --cache build` must produce a cache hit on the second run without any manual input/output configuration. Vite reports `ignoreInput(outDir)` + `ignoreInput/Output(cacheDir)` via `@voidzero-dev/vite-task-client`, so fspy-detected reads of `dist/` and writes to `node_modules/.vite/` don't poison the cache.

## `vt run --cache build`

first run: cache miss, emits dist/

```
$ vite build
```

## `vtt stat-file dist/assets/main.js`

existence check — content would drift across Vite versions

```
dist/assets/main.js: exists
```

## `vtt rm dist/assets/main.js`

remove the artefact so the cache-hit restore is observable

```
```

## `vt run --cache build`

cache hit: outputs restored without manual config

```
$ vite build ◉ cache hit, replaying

---
vt run: cache hit.
```

## `vtt stat-file dist/assets/main.js`

restored from the cache archive

```
dist/assets/main.js: exists
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# vite_node_env_change_invalidates_cache

`NODE_ENV` enters the build's cache fingerprint via Vite's `getEnv('NODE_ENV')` call in `resolveConfig`. Same value → cache hit; different value → cache miss with `tracked env 'NODE_ENV' changed`.

## `NODE_ENV=production vt run --cache build`

first run: NODE_ENV=production

```
$ vite build
```

## `NODE_ENV=production vt run --cache build`

cache hit: NODE_ENV unchanged

```
$ vite build ◉ cache hit, replaying

---
vt run: cache hit.
```

## `NODE_ENV=development vt run --cache build`

cache miss: tracked env 'NODE_ENV' changed

```
$ vite build ○ cache miss: tracked env 'NODE_ENV' changed, executing
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# vite_prefix_env_change_invalidates_cache

`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.

## `VITE_MODE=production vt run --cache build`

first run: production build

```
$ vite build
```

## `vtt grep-file dist/assets/main.js BUILD_MODE_PROD`

production build: PROD marker survived DCE

```
dist/assets/main.js: found "BUILD_MODE_PROD"
```

## `vtt grep-file dist/assets/main.js BUILD_MODE_DEV`

dev branch is gone

```
dist/assets/main.js: missing "BUILD_MODE_DEV"
```

## `VITE_MODE=production vt run --cache build`

cache hit: VITE_MODE unchanged

```
$ vite build ◉ cache hit, replaying

---
vt run: cache hit.
```

## `VITE_MODE=development vt run --cache build`

cache miss: tracked env glob `VITE_*` — VITE_MODE value changed

```
$ vite build ○ cache miss: tracked env glob 'VITE_*' changed, executing
```

## `vtt grep-file dist/assets/main.js BUILD_MODE_PROD`

PROD marker gone after the dev rebuild

```
dist/assets/main.js: missing "BUILD_MODE_PROD"
```

## `vtt grep-file dist/assets/main.js BUILD_MODE_DEV`

DEV marker now in the bundle

```
dist/assets/main.js: found "BUILD_MODE_DEV"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// `import.meta.env.VITE_MODE` is replaced at build time from the value vite
// picks up for keys matching `envPrefix` (`VITE_` by default). The markers
// let the e2e test assert that flipping VITE_MODE actually changed what was
// built and that glob-tracking invalidates the cache.
if (import.meta.env.VITE_MODE === 'production') {
document.body.append('BUILD_MODE_PROD');
} else {
document.body.append('BUILD_MODE_DEV');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"tasks": {
"build": {
"command": "vite build",
// No `"env": [...]` — vite's patched `loadEnv` asks the runner for
// every `VITE_*` env via `getEnvs`, so the glob + match-set are
// fingerprinted automatically.
"cache": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'vite';

export default defineConfig({
logLevel: 'silent',
build: {
rollupOptions: {
output: {
// Stable filenames make cache behaviour deterministic across runs.
entryFileNames: 'assets/main.js',
chunkFileNames: 'assets/chunk.js',
assetFileNames: 'assets/[name][extname]',
},
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Programmatic Vite dev server bring-up: middleware mode skips the HTTP
// listen entirely (Windows runners refuse the 127.0.0.1 bind with
// `listen UNKNOWN`), but `_createServer` still calls `disableCache()`
// via `@voidzero-dev/vite-task-client` on its first line — so even
// though this process exits 0 the runner is told not to store the run
// and the next invocation must miss.
import { createServer } from 'vite';

const server = await createServer({
configFile: false,
logLevel: 'silent',
server: { middlewareMode: true },
});
await server.close();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "vite-dev-disable-cache-fixture",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[e2e]]
name = "vite_dev_disables_cache"
comment = """
`vt run --cache dev` brings up a Vite dev server programmatically on an ephemeral port and closes it immediately. Vite's `_createServer` calls `disableCache()` via `@voidzero-dev/vite-task-client`, so this run is never stored — the next invocation re-executes (cache miss / NotFound).
"""
ignore = true
steps = [
{ argv = [
"vt",
"run",
"--cache",
"dev",
], comment = "first run — Vite dev start calls disableCache" },
{ argv = [
"vt",
"run",
"--cache",
"dev",
], comment = "cache miss (NotFound) because the first run was not stored" },
]
Loading
Loading