Skip to content

Commit 4d55c51

Browse files
committed
Explicitly exit the process to not wait for hanging promises
See actions#878
1 parent 5ef044f commit 4d55c51

7 files changed

+35
-0
lines changed

Diff for: __tests__/canary-installer.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('setup-node', () => {
4646
let isCacheActionAvailable: jest.SpyInstance;
4747
let getExecOutputSpy: jest.SpyInstance;
4848
let getJsonSpy: jest.SpyInstance;
49+
let processExitSpy: jest.SpyInstance;
4950

5051
beforeEach(() => {
5152
// @actions/core
@@ -63,6 +64,9 @@ describe('setup-node', () => {
6364
archSpy = jest.spyOn(osm, 'arch');
6465
archSpy.mockImplementation(() => os['arch']);
6566
execSpy = jest.spyOn(cp, 'execSync');
67+
processExitSpy = jest
68+
.spyOn(process, 'exit')
69+
.mockImplementation((() => {}) as () => never);
6670

6771
// @actions/tool-cache
6872
findSpy = jest.spyOn(tc, 'find');

Diff for: __tests__/main.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ describe('main tests', () => {
3535

3636
let setupNodeJsSpy: jest.SpyInstance;
3737

38+
let processExitSpy: jest.SpyInstance;
39+
3840
beforeEach(() => {
3941
inputs = {};
4042

@@ -72,6 +74,10 @@ describe('main tests', () => {
7274

7375
setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs');
7476
setupNodeJsSpy.mockImplementation(() => {});
77+
78+
processExitSpy = jest
79+
.spyOn(process, 'exit')
80+
.mockImplementation((() => {}) as () => never);
7581
});
7682

7783
afterEach(() => {
@@ -257,6 +263,12 @@ describe('main tests', () => {
257263
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}`
258264
);
259265
});
266+
267+
it('should call process.exit() explicitly after running', async () => {
268+
await main.run();
269+
270+
expect(processExitSpy).toHaveBeenCalled();
271+
});
260272
});
261273

262274
describe('cache on GHES', () => {

Diff for: __tests__/nightly-installer.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('setup-node', () => {
4646
let isCacheActionAvailable: jest.SpyInstance;
4747
let getExecOutputSpy: jest.SpyInstance;
4848
let getJsonSpy: jest.SpyInstance;
49+
let processExitSpy: jest.SpyInstance;
4950

5051
beforeEach(() => {
5152
// @actions/core
@@ -64,6 +65,9 @@ describe('setup-node', () => {
6465
archSpy = jest.spyOn(osm, 'arch');
6566
archSpy.mockImplementation(() => os['arch']);
6667
execSpy = jest.spyOn(cp, 'execSync');
68+
processExitSpy = jest
69+
.spyOn(process, 'exit')
70+
.mockImplementation((() => {}) as () => never);
6771

6872
// @actions/tool-cache
6973
findSpy = jest.spyOn(tc, 'find');

Diff for: __tests__/official-installer.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('setup-node', () => {
4646
let isCacheActionAvailable: jest.SpyInstance;
4747
let getExecOutputSpy: jest.SpyInstance;
4848
let getJsonSpy: jest.SpyInstance;
49+
let processExitSpy: jest.SpyInstance;
4950

5051
beforeEach(() => {
5152
// @actions/core
@@ -63,6 +64,9 @@ describe('setup-node', () => {
6364
archSpy = jest.spyOn(osm, 'arch');
6465
archSpy.mockImplementation(() => os['arch']);
6566
execSpy = jest.spyOn(cp, 'execSync');
67+
processExitSpy = jest
68+
.spyOn(process, 'exit')
69+
.mockImplementation((() => {}) as () => never);
6670

6771
// @actions/tool-cache
6872
findSpy = jest.spyOn(tc, 'find');

Diff for: __tests__/rc-installer.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('setup-node', () => {
4141
let isCacheActionAvailable: jest.SpyInstance;
4242
let getExecOutputSpy: jest.SpyInstance;
4343
let getJsonSpy: jest.SpyInstance;
44+
let processExitSpy: jest.SpyInstance;
4445

4546
beforeEach(() => {
4647
// @actions/core
@@ -58,6 +59,9 @@ describe('setup-node', () => {
5859
archSpy = jest.spyOn(osm, 'arch');
5960
archSpy.mockImplementation(() => os['arch']);
6061
execSpy = jest.spyOn(cp, 'execSync');
62+
processExitSpy = jest
63+
.spyOn(process, 'exit')
64+
.mockImplementation((() => {}) as () => never);
6165

6266
// @actions/tool-cache
6367
findSpy = jest.spyOn(tc, 'find');

Diff for: dist/setup/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -93711,6 +93711,9 @@ function run() {
9371193711
catch (err) {
9371293712
core.setFailed(err.message);
9371393713
}
93714+
// Explicit process.exit() to not wait for hanging promises,
93715+
// see https://github.com/actions/setup-node/issues/878
93716+
process.exit();
9371493717
});
9371593718
}
9371693719
exports.run = run;

Diff for: src/main.ts

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export async function run() {
7777
} catch (err) {
7878
core.setFailed((err as Error).message);
7979
}
80+
81+
// Explicit process.exit() to not wait for hanging promises,
82+
// see https://github.com/actions/setup-node/issues/878
83+
process.exit();
8084
}
8185

8286
function resolveVersionInput(): string {

0 commit comments

Comments
 (0)