| 
2 | 2 | 
 
  | 
3 | 3 | import * as exec from "@actions/exec";  | 
4 | 4 | import * as tc from "@actions/tool-cache";  | 
 | 5 | +import * as io from "@actions/io";  | 
5 | 6 | import * as path from "path";  | 
6 | 7 | import * as mpm from "./mpm";  | 
7 | 8 | import * as script from "./script";  | 
8 | 9 | 
 
  | 
9 | 10 | jest.mock("@actions/core");  | 
10 | 11 | jest.mock("@actions/exec");  | 
11 | 12 | jest.mock("@actions/tool-cache");  | 
 | 13 | +jest.mock("@actions/io");  | 
12 | 14 | jest.mock("./script");  | 
13 | 15 | 
 
  | 
14 | 16 | afterEach(() => {  | 
@@ -101,11 +103,13 @@ describe("setup mpm", () => {  | 
101 | 103 | 
 
  | 
102 | 104 | describe("mpm install", () => {  | 
103 | 105 |     let execMock: jest.Mock;  | 
 | 106 | +    let rmRFMock: jest.Mock;  | 
104 | 107 |     const mpmPath = "mpm";  | 
105 | 108 |     const releaseInfo = {name: "r2022b", version: "9.13.0", update: "", isPrerelease: false};  | 
106 | 109 |     const mpmRelease = "r2022b";  | 
107 | 110 |     beforeEach(() => {  | 
108 | 111 |         execMock = exec.exec as jest.Mock;  | 
 | 112 | +        rmRFMock = io.rmRF as jest.Mock;  | 
109 | 113 |     });  | 
110 | 114 | 
 
  | 
111 | 115 |     it("works with multiline products list", async () => {  | 
@@ -161,10 +165,19 @@ describe("mpm install", () => {  | 
161 | 165 |         expect(execMock.mock.calls[0][1]).toMatchObject(expectedMpmArgs);  | 
162 | 166 |     });  | 
163 | 167 | 
 
  | 
164 |  | -    it("rejects on failed install", async () => {  | 
 | 168 | +    it("rejects and cleans on mpm rejection", async () => {  | 
 | 169 | +        const destination = "/opt/matlab";  | 
 | 170 | +        const products = ["MATLAB", "Compiler"];  | 
 | 171 | +        execMock.mockRejectedValue(1);  | 
 | 172 | +        await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toBeDefined();  | 
 | 173 | +        expect(rmRFMock).toHaveBeenCalledWith(destination);  | 
 | 174 | +    });  | 
 | 175 | + | 
 | 176 | +    it("rejects and cleans on failed install", async () => {  | 
165 | 177 |         const destination = "/opt/matlab";  | 
166 | 178 |         const products = ["MATLAB", "Compiler"];  | 
167 | 179 |         execMock.mockResolvedValue(1);  | 
168 | 180 |         await expect(mpm.install(mpmPath, releaseInfo, products, destination)).rejects.toBeDefined();  | 
 | 181 | +        expect(rmRFMock).toHaveBeenCalledWith(destination);  | 
169 | 182 |     });  | 
170 | 183 | });  | 
0 commit comments