Skip to content

Commit 278bfa0

Browse files
committed
test(@angular-devkit/build-angular): add test to validate vite cache re-usage
This commit adds a test to verify that vite uses the dep optimization cache (cherry picked from commit 955d433)
1 parent a8f041f commit 278bfa0

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/legacy-cli/e2e.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ESBUILD_TESTS = [
3434
"tests/commands/add/**",
3535
"tests/commands/e2e/**",
3636
"tests/i18n/**",
37+
"tests/vite/**",
3738
"tests/test/**",
3839
]
3940

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import assert from 'node:assert';
2+
import { findFreePort } from '../../utils/network';
3+
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
4+
import { getGlobalVariable } from '../../utils/env';
5+
6+
export default async function () {
7+
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
8+
if (useWebpackBuilder) {
9+
return;
10+
}
11+
12+
await ng('cache', 'clean');
13+
await ng('cache', 'on');
14+
15+
try {
16+
const port = await findFreePort();
17+
18+
// Make sure serve is consistent with build
19+
await execAndWaitForOutputToMatch(
20+
'ng',
21+
['serve', '--port', `${port}`],
22+
/vite:deps Dependencies bundled/,
23+
// Use CI:0 to force caching
24+
{ DEBUG: 'vite:deps', CI: '0' },
25+
);
26+
27+
// Make request so that vite writes the cache.
28+
const response = await fetch(`http://localhost:${port}/@vite/client`);
29+
assert(response.ok, `Expected 'response.ok' to be 'true'.`);
30+
31+
// Terminate the dev-server
32+
await killAllProcesses();
33+
34+
// The Node.js specific module should not be found
35+
await execAndWaitForOutputToMatch(
36+
'ng',
37+
['serve', '--port=0'],
38+
/vite:deps Hash is consistent\. Skipping/,
39+
// Use CI:0 to force caching
40+
{ DEBUG: 'vite:deps', CI: '0' },
41+
);
42+
} finally {
43+
await killAllProcesses();
44+
}
45+
}

0 commit comments

Comments
 (0)