Skip to content

Commit 7173fb7

Browse files
author
David Buzinski
committed
initial upgrade
1 parent f8b5ee1 commit 7173fb7

21 files changed

Lines changed: 1502 additions & 1817 deletions
File renamed without changes.

.keep

Whitespace-only changes.

jest.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

jest.config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default {
2+
clearMocks: true,
3+
testEnvironment: "node",
4+
collectCoverage: true,
5+
testMatch: ["**/*.test.ts"],
6+
transform: {
7+
"^.+\\.[jt]s$": [
8+
"ts-jest",
9+
{
10+
useESM: true,
11+
diagnostics: {
12+
ignoreCodes: [1378, 151002],
13+
},
14+
},
15+
],
16+
},
17+
extensionsToTreatAsEsm: ['.ts'],
18+
transformIgnorePatterns: ["node_modules/(?!(@actions)/)"],
19+
moduleNameMapper: {
20+
"^(\\.{1,2}/.*)\\.js$": "$1",
21+
},
22+
};

package-lock.json

Lines changed: 1179 additions & 1622 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@
33
"author": "The MathWorks, Inc.",
44
"version": "2.7.0",
55
"description": "",
6+
"type": "module",
67
"main": "lib/index.js",
78
"scripts": {
89
"clean": "rm -rf dist lib",
910
"format": "prettier --write .",
1011
"format-check": "prettier --check .",
1112
"lint": "eslint \"**/*.ts\" --fix",
13+
"build": "tsc",
1214
"package": "ncc build src/index.ts -o dist/setup --minify && ncc build src/post.ts -o dist/cache-save --minify",
13-
"test": "jest",
14-
"all": "npm run lint && npm test && npm run package",
15+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest",
16+
"all": "npm run lint && npm test && npm run build && npm run package",
1517
"ci": "npm run clean && npm ci && npm run all"
1618
},
1719
"files": [
1820
"lib/"
1921
],
2022
"dependencies": {
21-
"@actions/cache": "^4.0.5",
22-
"@actions/core": "^1.11.1",
23-
"@actions/exec": "^1.1.1",
24-
"@actions/http-client": "^2.2.3",
25-
"@actions/io": "^1.1.3",
26-
"@actions/tool-cache": "^2.0.2"
23+
"@actions/cache": "^6.0.0",
24+
"@actions/core": "^3.0.0",
25+
"@actions/exec": "^3.0.0",
26+
"@actions/http-client": "^4.0.0",
27+
"@actions/io": "^3.0.2",
28+
"@actions/tool-cache": "^4.0.0"
2729
},
2830
"devDependencies": {
2931
"@types/jest": "^30.0.0",
@@ -36,6 +38,7 @@
3638
"jest-circus": "^30.0.5",
3739
"prettier": "3.6.2",
3840
"ts-jest": "^29.4.1",
41+
"ts-node": "^10.9.2",
3942
"typescript": "^5.9.2"
4043
}
4144
}

src/cache-restore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import * as cache from "@actions/cache";
44
import * as core from "@actions/core";
55
import * as crypto from "crypto";
6-
import { State } from "./cache-state";
7-
import { Release } from "./matlab";
6+
import { State } from "./cache-state.js";
7+
import { Release } from "./matlab.js";
88

99
export async function restoreMATLAB(
1010
release: Release,

src/cache-restore.unit.test.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

3-
import * as cache from "@actions/cache";
4-
import * as core from "@actions/core";
5-
import { restoreMATLAB } from "./cache-restore";
3+
import { jest, describe, it, expect, beforeEach, afterEach } from "@jest/globals";
64

7-
jest.mock("@actions/cache");
8-
jest.mock("@actions/core");
5+
jest.unstable_mockModule("@actions/cache", () => ({
6+
restoreCache: jest.fn(),
7+
}));
8+
jest.unstable_mockModule("@actions/core", () => ({
9+
saveState: jest.fn(),
10+
info: jest.fn(),
11+
}));
12+
13+
const cache = await import("@actions/cache");
14+
const core = await import("@actions/core");
15+
const { restoreMATLAB } = await import("./cache-restore.js");
916

1017
afterEach(() => {
1118
jest.resetAllMocks();
1219
});
1320

1421
describe("cache-restore", () => {
15-
let restoreCacheMock: jest.Mock;
16-
let saveStateMock: jest.Mock;
22+
let restoreCacheMock: jest.Mock<typeof cache.restoreCache>;
23+
let saveStateMock: jest.Mock<typeof core.saveState>;
1724

1825
const platform = "linux";
1926
const arch = "x64";
@@ -27,12 +34,12 @@ describe("cache-restore", () => {
2734
const location = "/path/to/matlab";
2835

2936
beforeEach(() => {
30-
restoreCacheMock = cache.restoreCache as jest.Mock;
31-
saveStateMock = core.saveState as jest.Mock;
37+
restoreCacheMock = cache.restoreCache as jest.Mock<typeof cache.restoreCache>;
38+
saveStateMock = core.saveState as jest.Mock<typeof core.saveState>;
3239
});
3340

3441
it("returns true if cache is found", async () => {
35-
restoreCacheMock.mockReturnValue("matched-cache-key");
42+
restoreCacheMock.mockResolvedValue("matched-cache-key");
3643
await expect(restoreMATLAB(release, platform, arch, products, location)).resolves.toBe(
3744
true,
3845
);

src/cache-save.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as core from "@actions/core";
44
import * as cache from "@actions/cache";
5-
import { State } from "./cache-state";
5+
import { State } from "./cache-state.js";
66

77
export async function cacheMATLAB() {
88
const matchedKey = core.getState(State.CacheMatchedKey);

src/cache-save.unit.test.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

3-
import * as core from "@actions/core";
4-
import * as cache from "@actions/cache";
5-
import { cacheMATLAB } from "./cache-save";
3+
import { jest, describe, it, expect, beforeEach, afterEach } from "@jest/globals";
64

7-
jest.mock("@actions/cache");
8-
jest.mock("@actions/core");
5+
jest.unstable_mockModule("@actions/cache", () => ({
6+
saveCache: jest.fn(),
7+
}));
8+
jest.unstable_mockModule("@actions/core", () => ({
9+
getState: jest.fn(),
10+
info: jest.fn(),
11+
warning: jest.fn(),
12+
}));
13+
14+
const cache = await import("@actions/cache");
15+
const core = await import("@actions/core");
16+
const { cacheMATLAB } = await import("./cache-save.js");
917

1018
afterEach(() => {
1119
jest.resetAllMocks();
1220
});
1321

1422
describe("cache-save", () => {
15-
let saveCacheMock: jest.Mock;
16-
let getStateMock: jest.Mock;
23+
let saveCacheMock: jest.Mock<typeof cache.saveCache>;
24+
let getStateMock: jest.Mock<typeof core.getState>;
1725

1826
beforeEach(() => {
19-
saveCacheMock = cache.saveCache as jest.Mock;
20-
getStateMock = core.getState as jest.Mock;
27+
saveCacheMock = cache.saveCache as jest.Mock<typeof cache.saveCache>;
28+
getStateMock = core.getState as jest.Mock<typeof core.getState>;
2129
});
2230

2331
it("saves cache if key does not equal matched key", async () => {

0 commit comments

Comments
 (0)