Skip to content

Commit e42932c

Browse files
douglowderfacebook-github-bot
authored andcommittedJul 22, 2024·
fix: Remove setting of process.exitCode that breaks Jest tests (#45562)
Summary: In Node 20, the script to run unit tests in CI (`scripts/run-ci-javascript-tests.js`) will fail, even when all the Jest tests pass. This happens because one of the JS modules being tested is setting `process.exitCode` (see jestjs/jest#9324 (comment)). Changes: - Modified the affected module to throw an exception when failing, instead of setting the exit code - Adjusted the unit test for that module ## Changelog: [General] [Fixed] - Remove setting of process.exitCode that breaks Jest tests Pull Request resolved: #45562 Test Plan: Before this change, running `node scripts/run-ci-javascript-tests.js` would fail with Node 20. After this change, it succeeds. Reviewed By: blakef Differential Revision: D60033582 Pulled By: cipolleschi fbshipit-source-id: 71b7f4495d414e719a9bd2d892bd1bc3045ddd5d
1 parent aa4f802 commit e42932c

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed
 

‎scripts/releases-ci/__tests__/publish-updated-packages-test.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ describe('publishUpdatedPackages', () => {
4747
.spyOn(console, 'error')
4848
.mockImplementation(() => {});
4949

50-
await publishUpdatedPackages();
51-
52-
expect(consoleError.mock.calls).toMatchInlineSnapshot(`
53-
Array [
54-
Array [
55-
"Failed to read Git commit message, exiting.",
56-
],
57-
]
58-
`);
50+
let message = '';
51+
try {
52+
await publishUpdatedPackages();
53+
} catch (e) {
54+
message = e.message;
55+
}
56+
expect(message).toEqual('Failed to read Git commit message, exiting.');
5957
});
6058

6159
test("should exit when commit message does not include '#publish-packages-to-npm'", async () => {
@@ -246,7 +244,6 @@ describe('publishUpdatedPackages', () => {
246244
]
247245
`);
248246
});
249-
250247
test('should exit with error if one or more packages fail after retry', async () => {
251248
execMock.mockImplementationOnce(() => ({code: 0}));
252249
execMock.mockImplementation(() => ({
@@ -258,10 +255,15 @@ describe('publishUpdatedPackages', () => {
258255
.spyOn(console, 'log')
259256
.mockImplementation(() => {});
260257

261-
await publishUpdatedPackages();
258+
let message = '';
259+
try {
260+
await publishUpdatedPackages();
261+
} catch (e) {
262+
message = e.message;
263+
}
262264

263265
expect(consoleLog).toHaveBeenLastCalledWith('--- Retrying once! ---');
264-
expect(process.exitCode).toBe(1);
266+
expect(message).toEqual('Failed packages count = 1');
265267
});
266268
});
267269
});

‎scripts/releases-ci/publish-updated-packages.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ async function publishUpdatedPackages() {
4747
try {
4848
commitMessage = execSync('git log -1 --pretty=%B').toString();
4949
} catch {
50-
console.error('Failed to read Git commit message, exiting.');
51-
process.exitCode = 1;
52-
return;
50+
throw new Error('Failed to read Git commit message, exiting.');
5351
}
5452

5553
if (!commitMessage.includes(PUBLISH_PACKAGES_TAG)) {
@@ -117,8 +115,7 @@ async function publishUpdatedPackages() {
117115
}
118116

119117
if (failedPackages.length) {
120-
process.exitCode = 1;
121-
return;
118+
throw new Error(`Failed packages count = ${failedPackages.length}`);
122119
}
123120

124121
console.log('Done ✅');

0 commit comments

Comments
 (0)
Please sign in to comment.