test: reduce flakiness of reuse-dep-optimization-cache e2e test

This commit reduces test flakiness by modifying the logic to perform the fetch only after the app is bundled.
This commit is contained in:
Alan Agius 2025-02-14 12:01:05 +00:00
parent 04f331a534
commit 87b310a13f

View File

@ -1,23 +1,28 @@
import assert from 'node:assert';
import { setTimeout } from 'node:timers/promises';
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');
const port = await findFreePort();
await execAndWaitForOutputToMatch(
'ng',
['serve', '--port', `${port}`],
/Application bundle generation complete/,
// Use CI:0 to force caching
{ DEBUG: 'vite:deps', CI: '0', NO_COLOR: 'true' },
);
const [, response] = await Promise.all([
execAndWaitForOutputToMatch(
'ng',
['serve', '--port', `${port}`],
/dependencies optimized/,
// Use CI:0 to force caching
{ DEBUG: 'vite:deps', CI: '0', NO_COLOR: 'true' },
),
setTimeout(4_000).then(() => fetch(`http://localhost:${port}/main.js`)),
waitForAnyProcessOutputToMatch(/dependencies optimized/, 10_000),
fetch(`http://localhost:${port}/main.js`),
]);
assert(response.ok, `Expected 'response.ok' to be 'true'.`);