Skip to content

Commit e7311f7

Browse files
authored
test: ignore unstable snap-test output (#329)
### TL;DR Added support for ignoring "npm notice Access token expired or revoked" warnings in test output. ### What changed? - Added a new regex pattern in `replaceUnstableOutput()` function to filter out "npm notice Access token expired or revoked" warning messages - Added a corresponding test case to verify the new functionality - Updated test snapshots to include the new test case ### How to test? 1. Run the test suite to verify that the new test case passes 2. Verify that when running commands that might produce the "npm notice Access token expired or revoked" warning, these messages are properly filtered out from the output ### Why make this change? These npm access token warnings are non-deterministic and can cause test failures when they appear in output that's being compared against snapshots. By filtering them out, we improve test stability and prevent false negatives in test runs.
1 parent 5577e9f commit e7311f7

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/tools/src/__tests__/__snapshots__/utils.spec.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ added 3 packages in <variable>ms
2020
Done in <variable>ms"
2121
`;
2222
23+
exports[`replaceUnstableOutput() > replace ignore npm notice access token expired or revoked warning log 1`] = `
24+
"line 1
25+
line 2
26+
line 3"
27+
`;
28+
2329
exports[`replaceUnstableOutput() > replace ignore npm registry domain 1`] = `
2430
"https://registry.<domain>/testnpm2
2531
https://registry.<domain>/debug

packages/tools/src/__tests__/utils.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ npm notice integrity: sha512-qugLL42iCblSD[...]Gfk6HJodp2ZOQ==
170170
`;
171171
expect(replaceUnstableOutput(output.trim())).toMatchSnapshot();
172172
});
173+
174+
test('replace ignore npm notice access token expired or revoked warning log', () => {
175+
const output = `
176+
line 1
177+
npm notice Access token expired or revoked. Please try logging in again.
178+
npm notice Access token expired or revoked. Please try logging in again.
179+
line 2
180+
npm notice Access token expired or revoked. Please try logging in again.
181+
line 3
182+
`;
183+
expect(replaceUnstableOutput(output.trim())).toMatchSnapshot();
184+
});
173185
});
174186

175187
describe('isPassThroughEnv()', () => {

packages/tools/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ export function replaceUnstableOutput(output: string, cwd?: string) {
9595
.replaceAll(`Checking formatting...\n`, 'Checking formatting...')
9696
// remove warning <name>@<semver>: No license field
9797
.replaceAll(/warning .+?: No license field\n/g, '')
98+
// remove "npm notice Access token expired or revoked..."
99+
.replaceAll(/npm notice Access token expired or revoked.+?\n/g, '')
98100
);
99101
}
100102

0 commit comments

Comments
 (0)