From 7b30725f4c00461f482422e6c6c368550083d0e1 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 17 Nov 2023 14:16:52 -0500 Subject: [PATCH] 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 7ac6da56f48153200f0bb9dcdbc5dedc807f5702) --- .../vite/reuse-dep-optimization-cache.ts | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/legacy-cli/e2e/tests/vite/reuse-dep-optimization-cache.ts b/tests/legacy-cli/e2e/tests/vite/reuse-dep-optimization-cache.ts index d88ed3ffcae5..f4b93ccfcd2f 100644 --- a/tests/legacy-cli/e2e/tests/vite/reuse-dep-optimization-cache.ts +++ b/tests/legacy-cli/e2e/tests/vite/reuse-dep-optimization-cache.ts @@ -1,43 +1,43 @@ -import { setTimeout } from 'node:timers/promises'; import assert from 'node:assert'; import { findFreePort } from '../../utils/network'; -import { execAndWaitForOutputToMatch, killAllProcesses, ng } from '../../utils/process'; +import { + execAndWaitForOutputToMatch, + killAllProcesses, + ng, + waitForAnyProcessOutputToMatch, +} from '../../utils/process'; export default async function () { await ng('cache', 'clean'); await ng('cache', 'on'); - try { - const port = await findFreePort(); + const port = await findFreePort(); - // Make sure serve is consistent with build - await execAndWaitForOutputToMatch( - 'ng', - ['serve', '--port', `${port}`], - /vite:deps Dependencies bundled/, - // Use CI:0 to force caching - { DEBUG: 'vite:deps', CI: '0' }, - ); + // Make sure serve is consistent with build + await execAndWaitForOutputToMatch( + 'ng', + ['serve', '--port', `${port}`], + /Dependencies bundled/, + // Use CI:0 to force caching + { DEBUG: 'vite:deps', CI: '0' }, + ); - // Make request so that vite writes the cache. - const response = await fetch(`http://localhost:${port}/@vite/client`); - assert(response.ok, `Expected 'response.ok' to be 'true'.`); + // Make request so that vite writes the cache. + const response = await fetch(`http://localhost:${port}/main.js`); + assert(response.ok, `Expected 'response.ok' to be 'true'.`); - // Wait for vite to write to FS and stablize. - await setTimeout(2_000); + // Wait for vite to write to FS and stablize. + await waitForAnyProcessOutputToMatch(/dependencies optimized/, 5000); - // Terminate the dev-server - await killAllProcesses(); + // Terminate the dev-server + await killAllProcesses(); - // The Node.js specific module should not be found - await execAndWaitForOutputToMatch( - 'ng', - ['serve', '--port=0'], - /vite:deps Hash is consistent\. Skipping/, - // Use CI:0 to force caching - { DEBUG: 'vite:deps', CI: '0' }, - ); - } finally { - await killAllProcesses(); - } + // The Node.js specific module should not be found + await execAndWaitForOutputToMatch( + 'ng', + ['serve', '--port=0'], + /Hash is consistent\. Skipping/, + // Use CI:0 to force caching + { DEBUG: 'vite:deps', CI: '0' }, + ); }