Skip to content

Commit f7ebb81

Browse files
authored
Consume latest toolkit and fix dangling promise bug (#1217)
* Consume latest toolkit and fix dangling promise bug * Pass earlyExit parameter to run method so tests don't hang * Pass earlyExit parameter to run method so tests don't hang * Refactor restore files to have better patterns for testing * style
1 parent 67b839e commit f7ebb81

File tree

14 files changed

+922
-239
lines changed

14 files changed

+922
-239
lines changed

.licenses/npm/@actions/cache.dep.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/npm/@actions/http-client.dep.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__tests__/restore.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
22
import * as core from "@actions/core";
33

44
import { Events, RefKey } from "../src/constants";
5-
import run from "../src/restore";
5+
import { restoreRun } from "../src/restoreImpl";
66
import * as actionUtils from "../src/utils/actionUtils";
77
import * as testUtils from "../src/utils/testUtils";
88

@@ -71,7 +71,7 @@ test("restore with no cache found", async () => {
7171
return Promise.resolve(undefined);
7272
});
7373

74-
await run();
74+
await restoreRun();
7575

7676
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
7777
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -114,7 +114,7 @@ test("restore with restore keys and no cache found", async () => {
114114
return Promise.resolve(undefined);
115115
});
116116

117-
await run();
117+
await restoreRun();
118118

119119
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
120120
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -156,7 +156,7 @@ test("restore with cache found for key", async () => {
156156
return Promise.resolve(key);
157157
});
158158

159-
await run();
159+
await restoreRun();
160160

161161
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
162162
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -201,7 +201,7 @@ test("restore with cache found for restore key", async () => {
201201
return Promise.resolve(restoreKey);
202202
});
203203

204-
await run();
204+
await restoreRun();
205205

206206
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
207207
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -246,7 +246,7 @@ test("Fail restore when fail on cache miss is enabled and primary + restore keys
246246
return Promise.resolve(undefined);
247247
});
248248

249-
await run();
249+
await restoreRun();
250250

251251
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
252252
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -289,7 +289,7 @@ test("restore when fail on cache miss is enabled and primary key doesn't match r
289289
return Promise.resolve(restoreKey);
290290
});
291291

292-
await run();
292+
await restoreRun();
293293

294294
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
295295
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -335,7 +335,7 @@ test("restore with fail on cache miss disabled and no cache found", async () =>
335335
return Promise.resolve(undefined);
336336
});
337337

338-
await run();
338+
await restoreRun();
339339

340340
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
341341
expect(restoreCacheMock).toHaveBeenCalledWith(

__tests__/restoreImpl.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
22
import * as core from "@actions/core";
33

44
import { Events, Inputs, RefKey } from "../src/constants";
5-
import run from "../src/restoreImpl";
5+
import { restoreImpl } from "../src/restoreImpl";
66
import { StateProvider } from "../src/stateProvider";
77
import * as actionUtils from "../src/utils/actionUtils";
88
import * as testUtils from "../src/utils/testUtils";
@@ -60,7 +60,7 @@ test("restore with invalid event outputs warning", async () => {
6060
const invalidEvent = "commit_comment";
6161
process.env[Events.Key] = invalidEvent;
6262
delete process.env[RefKey];
63-
await run(new StateProvider());
63+
await restoreImpl(new StateProvider());
6464
expect(logWarningMock).toHaveBeenCalledWith(
6565
`Event Validation Error: The event type ${invalidEvent} is not supported because it's not tied to a branch or tag ref.`
6666
);
@@ -76,7 +76,7 @@ test("restore without AC available should no-op", async () => {
7676
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
7777
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
7878

79-
await run(new StateProvider());
79+
await restoreImpl(new StateProvider());
8080

8181
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
8282
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
@@ -92,7 +92,7 @@ test("restore on GHES without AC available should no-op", async () => {
9292
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
9393
const setCacheHitOutputMock = jest.spyOn(core, "setOutput");
9494

95-
await run(new StateProvider());
95+
await restoreImpl(new StateProvider());
9696

9797
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
9898
expect(setCacheHitOutputMock).toHaveBeenCalledTimes(1);
@@ -119,7 +119,7 @@ test("restore on GHES with AC available ", async () => {
119119
return Promise.resolve(key);
120120
});
121121

122-
await run(new StateProvider());
122+
await restoreImpl(new StateProvider());
123123

124124
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
125125
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -143,7 +143,7 @@ test("restore on GHES with AC available ", async () => {
143143
test("restore with no path should fail", async () => {
144144
const failedMock = jest.spyOn(core, "setFailed");
145145
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
146-
await run(new StateProvider());
146+
await restoreImpl(new StateProvider());
147147
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
148148
// this input isn't necessary for restore b/c tarball contains entries relative to workspace
149149
expect(failedMock).not.toHaveBeenCalledWith(
@@ -155,7 +155,7 @@ test("restore with no key", async () => {
155155
testUtils.setInput(Inputs.Path, "node_modules");
156156
const failedMock = jest.spyOn(core, "setFailed");
157157
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
158-
await run(new StateProvider());
158+
await restoreImpl(new StateProvider());
159159
expect(restoreCacheMock).toHaveBeenCalledTimes(0);
160160
expect(failedMock).toHaveBeenCalledWith(
161161
"Input required and not supplied: key"
@@ -174,7 +174,7 @@ test("restore with too many keys should fail", async () => {
174174
});
175175
const failedMock = jest.spyOn(core, "setFailed");
176176
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
177-
await run(new StateProvider());
177+
await restoreImpl(new StateProvider());
178178
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
179179
expect(restoreCacheMock).toHaveBeenCalledWith(
180180
[path],
@@ -200,7 +200,7 @@ test("restore with large key should fail", async () => {
200200
});
201201
const failedMock = jest.spyOn(core, "setFailed");
202202
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
203-
await run(new StateProvider());
203+
await restoreImpl(new StateProvider());
204204
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
205205
expect(restoreCacheMock).toHaveBeenCalledWith(
206206
[path],
@@ -226,7 +226,7 @@ test("restore with invalid key should fail", async () => {
226226
});
227227
const failedMock = jest.spyOn(core, "setFailed");
228228
const restoreCacheMock = jest.spyOn(cache, "restoreCache");
229-
await run(new StateProvider());
229+
await restoreImpl(new StateProvider());
230230
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
231231
expect(restoreCacheMock).toHaveBeenCalledWith(
232232
[path],
@@ -260,7 +260,7 @@ test("restore with no cache found", async () => {
260260
return Promise.resolve(undefined);
261261
});
262262

263-
await run(new StateProvider());
263+
await restoreImpl(new StateProvider());
264264

265265
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
266266
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -301,7 +301,7 @@ test("restore with restore keys and no cache found", async () => {
301301
return Promise.resolve(undefined);
302302
});
303303

304-
await run(new StateProvider());
304+
await restoreImpl(new StateProvider());
305305

306306
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
307307
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -341,7 +341,7 @@ test("restore with cache found for key", async () => {
341341
return Promise.resolve(key);
342342
});
343343

344-
await run(new StateProvider());
344+
await restoreImpl(new StateProvider());
345345

346346
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
347347
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -383,7 +383,7 @@ test("restore with cache found for restore key", async () => {
383383
return Promise.resolve(restoreKey);
384384
});
385385

386-
await run(new StateProvider());
386+
await restoreImpl(new StateProvider());
387387

388388
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
389389
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -424,7 +424,7 @@ test("restore with lookup-only set", async () => {
424424
return Promise.resolve(key);
425425
});
426426

427-
await run(new StateProvider());
427+
await restoreImpl(new StateProvider());
428428

429429
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
430430
expect(restoreCacheMock).toHaveBeenCalledWith(

__tests__/restoreOnly.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as cache from "@actions/cache";
22
import * as core from "@actions/core";
33

44
import { Events, RefKey } from "../src/constants";
5-
import run from "../src/restoreOnly";
5+
import { restoreOnlyRun } from "../src/restoreImpl";
66
import * as actionUtils from "../src/utils/actionUtils";
77
import * as testUtils from "../src/utils/testUtils";
88

@@ -72,7 +72,7 @@ test("restore with no cache found", async () => {
7272
return Promise.resolve(undefined);
7373
});
7474

75-
await run();
75+
await restoreOnlyRun();
7676

7777
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
7878
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -114,7 +114,7 @@ test("restore with restore keys and no cache found", async () => {
114114
return Promise.resolve(undefined);
115115
});
116116

117-
await run();
117+
await restoreOnlyRun();
118118

119119
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
120120
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -153,7 +153,7 @@ test("restore with cache found for key", async () => {
153153
return Promise.resolve(key);
154154
});
155155

156-
await run();
156+
await restoreOnlyRun();
157157

158158
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
159159
expect(restoreCacheMock).toHaveBeenCalledWith(
@@ -196,7 +196,7 @@ test("restore with cache found for restore key", async () => {
196196
return Promise.resolve(restoreKey);
197197
});
198198

199-
await run();
199+
await restoreOnlyRun();
200200

201201
expect(restoreCacheMock).toHaveBeenCalledTimes(1);
202202
expect(restoreCacheMock).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)