Skip to content

Commit 7b30725

Browse files
committed
test: attempt to reduce flakiness of Vite cache reuse test
The test is changed to now wait for Vite to output that it has optimized the dependencies after a request to the main application chunk. This removes the need to wait a specific amount of time between steps. The final `killAllProcesses` is also removed since the test runner will always run that function at the end of every test. (cherry picked from commit 7ac6da5)
1 parent ef3e3ab commit 7b30725

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
import { setTimeout } from 'node:timers/promises';
21
import assert from 'node:assert';
32
import { findFreePort } from '../../utils/network';
4-
import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process';
3+
import {
4+
execAndWaitForOutputToMatch,
5+
killAllProcesses,
6+
ng,
7+
waitForAnyProcessOutputToMatch,
8+
} from '../../utils/process';
59

610
export default async function () {
711
await ng('cache', 'clean');
812
await ng('cache', 'on');
913

10-
try {
11-
const port = await findFreePort();
14+
const port = await findFreePort();
1215

13-
// Make sure serve is consistent with build
14-
await execAndWaitForOutputToMatch(
15-
'ng',
16-
['serve', '--port', `${port}`],
17-
/vite:deps Dependencies bundled/,
18-
// Use CI:0 to force caching
19-
{ DEBUG: 'vite:deps', CI: '0' },
20-
);
16+
// Make sure serve is consistent with build
17+
await execAndWaitForOutputToMatch(
18+
'ng',
19+
['serve', '--port', `${port}`],
20+
/Dependencies bundled/,
21+
// Use CI:0 to force caching
22+
{ DEBUG: 'vite:deps', CI: '0' },
23+
);
2124

22-
// Make request so that vite writes the cache.
23-
const response = await fetch(`http://localhost:${port}/@vite/client`);
24-
assert(response.ok, `Expected 'response.ok' to be 'true'.`);
25+
// Make request so that vite writes the cache.
26+
const response = await fetch(`http://localhost:${port}/main.js`);
27+
assert(response.ok, `Expected 'response.ok' to be 'true'.`);
2528

26-
// Wait for vite to write to FS and stablize.
27-
await setTimeout(2_000);
29+
// Wait for vite to write to FS and stablize.
30+
await waitForAnyProcessOutputToMatch(/dependencies optimized/, 5000);
2831

29-
// Terminate the dev-server
30-
await killAllProcesses();
32+
// Terminate the dev-server
33+
await killAllProcesses();
3134

32-
// The Node.js specific module should not be found
33-
await execAndWaitForOutputToMatch(
34-
'ng',
35-
['serve', '--port=0'],
36-
/vite:deps Hash is consistent\. Skipping/,
37-
// Use CI:0 to force caching
38-
{ DEBUG: 'vite:deps', CI: '0' },
39-
);
40-
} finally {
41-
await killAllProcesses();
42-
}
35+
// The Node.js specific module should not be found
36+
await execAndWaitForOutputToMatch(
37+
'ng',
38+
['serve', '--port=0'],
39+
/Hash is consistent\. Skipping/,
40+
// Use CI:0 to force caching
41+
{ DEBUG: 'vite:deps', CI: '0' },
42+
);
4343
}

0 commit comments

Comments
 (0)