From 8b02fd48f7f66bf46050fb9d004001cddd5db1ba Mon Sep 17 00:00:00 2001 From: Nicholas Cunningham Date: Wed, 16 Apr 2025 13:08:16 -0600 Subject: [PATCH] fix(core): improve flaky ci test (#30738) This PR updates `lerna-smoke-tests.test.ts` test file to improve the consistency of the snapshots. The serializer has been updated to reduce flakiness from spacing and line breaks. --- .../src/lerna-smoke-tests.test.ts | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts b/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts index 4b7b410ef6..22c8ffcbeb 100644 --- a/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts +++ b/e2e/lerna-smoke-tests/src/lerna-smoke-tests.test.ts @@ -13,17 +13,13 @@ import { expect.addSnapshotSerializer({ serialize(str: string) { - return ( - str - // Not all package managers print the package.json path in the output - .replace(tmpProjPath(), '') - .replace('/private', '') - .replace('/packages/package-1', '') - // We trim each line to reduce the chances of snapshot flakiness - .split('\n') - .map((r) => r.trim()) - .join('\n') - ); + return str + .replace(/(\r\n|\n)+/g, '\n') + .replace(/\n\s+/g, '\n') + .replace(/\s+\n/g, '\n') + .replace(tmpProjPath(), '') + .replace('/private', '') + .replace('/packages/package-1', ''); }, test(val: string) { return val != null && typeof val === 'string'; @@ -48,12 +44,9 @@ describe('Lerna Smoke Tests', () => { .replace(/Running migration.*\n/g, '') // start of individual migration run .replace(/Ran .* from .*\n .*\n\n/g, '') // end of individual migration run .replace(/No changes were made\n\n/g, ''); // no changes during individual migration run - expect(result).toMatchInlineSnapshot(` - - Lerna No changes were necessary. This workspace is up to date! - - - `); + expect(result).toContain( + 'Lerna No changes were necessary. This workspace is up to date!' + ); }, 1000000); }); @@ -76,18 +69,12 @@ describe('Lerna Smoke Tests', () => { .replace('$ echo test-package-1', '> echo test-package-1'); expect(result).toMatchInlineSnapshot(` - > package-1:print-name + > package-1:print-name + > echo test-package-1 + test-package-1 + Lerna (powered by Nx) Successfully ran target print-name for project package-1 - > echo test-package-1 - test-package-1 - - - - Lerna (powered by Nx) Successfully ran target print-name for project package-1 - - - - `); + `); }, 1000000); }); });