|
1 | | -import { setTimeout } from 'node:timers/promises'; |
2 | 1 | import assert from 'node:assert'; |
3 | 2 | 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'; |
5 | 9 |
|
6 | 10 | export default async function () { |
7 | 11 | await ng('cache', 'clean'); |
8 | 12 | await ng('cache', 'on'); |
9 | 13 |
|
10 | | - try { |
11 | | - const port = await findFreePort(); |
| 14 | + const port = await findFreePort(); |
12 | 15 |
|
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 | + ); |
21 | 24 |
|
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'.`); |
25 | 28 |
|
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); |
28 | 31 |
|
29 | | - // Terminate the dev-server |
30 | | - await killAllProcesses(); |
| 32 | + // Terminate the dev-server |
| 33 | + await killAllProcesses(); |
31 | 34 |
|
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 | + ); |
43 | 43 | } |
0 commit comments