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.
This commit is contained in:
Nicholas Cunningham 2025-04-16 13:08:16 -06:00 committed by GitHub
parent 4b4226d2e0
commit 8b02fd48f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,17 +13,13 @@ import {
expect.addSnapshotSerializer({ expect.addSnapshotSerializer({
serialize(str: string) { serialize(str: string) {
return ( return str
str .replace(/(\r\n|\n)+/g, '\n')
// Not all package managers print the package.json path in the output .replace(/\n\s+/g, '\n')
.replace(/\s+\n/g, '\n')
.replace(tmpProjPath(), '') .replace(tmpProjPath(), '')
.replace('/private', '') .replace('/private', '')
.replace('/packages/package-1', '') .replace('/packages/package-1', '');
// We trim each line to reduce the chances of snapshot flakiness
.split('\n')
.map((r) => r.trim())
.join('\n')
);
}, },
test(val: string) { test(val: string) {
return val != null && typeof 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(/Running migration.*\n/g, '') // start of individual migration run
.replace(/Ran .* from .*\n .*\n\n/g, '') // end 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 .replace(/No changes were made\n\n/g, ''); // no changes during individual migration run
expect(result).toMatchInlineSnapshot(` expect(result).toContain(
'Lerna No changes were necessary. This workspace is up to date!'
Lerna No changes were necessary. This workspace is up to date! );
`);
}, 1000000); }, 1000000);
}); });
@ -77,16 +70,10 @@ describe('Lerna Smoke Tests', () => {
expect(result).toMatchInlineSnapshot(` expect(result).toMatchInlineSnapshot(`
> package-1:print-name > package-1:print-name
> echo test-package-1 > echo test-package-1
test-package-1 test-package-1
Lerna (powered by Nx) Successfully ran target print-name for project package-1 Lerna (powered by Nx) Successfully ran target print-name for project package-1
`); `);
}, 1000000); }, 1000000);
}); });