|
1 | 1 | import { vol } from "memfs"; |
2 | 2 | import * as path from "path"; |
| 3 | +import * as fs from "fs"; |
3 | 4 | import { corePkg, dashboardPkg, nodecgIODir, twitchChatPkg, validProdInstall } from "../test.util"; |
4 | 5 | import { diffPackages, installPackages, removePackages, validateInstall } from "../../src/install/production"; |
5 | 6 | import * as installation from "../../src/utils/installation"; |
@@ -56,13 +57,14 @@ describe("diffPackages", () => { |
56 | 57 |
|
57 | 58 | describe("removePackages", () => { |
58 | 59 | test("should rm each package directory", async () => { |
59 | | - const rmMock = jest.spyOn(fsUtils, "removeDirectory").mockClear().mockResolvedValue(); |
| 60 | + const rmMock = jest.spyOn(fs.promises, "rm").mockClear().mockResolvedValue(); |
60 | 61 | const i = { ...validProdInstall, packages: [...packages] }; |
61 | 62 | await removePackages(packages, i, nodecgIODir); |
62 | 63 |
|
63 | 64 | expect(rmMock).toHaveBeenCalledTimes(2); |
64 | | - expect(rmMock).toHaveBeenCalledWith(path.join(nodecgIODir, corePkg.path)); |
65 | | - expect(rmMock).toHaveBeenLastCalledWith(path.join(nodecgIODir, twitchChatPkg.path)); |
| 65 | + const rmOpts = { recursive: true, force: true }; |
| 66 | + expect(rmMock).toHaveBeenCalledWith(path.join(nodecgIODir, corePkg.path), rmOpts); |
| 67 | + expect(rmMock).toHaveBeenLastCalledWith(path.join(nodecgIODir, twitchChatPkg.path), rmOpts); |
66 | 68 | expect(i.packages.length).toBe(0); |
67 | 69 | }); |
68 | 70 |
|
@@ -106,7 +108,7 @@ describe("installPackages", () => { |
106 | 108 |
|
107 | 109 | test("should revert changes if npm install fails", async () => { |
108 | 110 | npmInstallMock.mockRejectedValue(new Error("random error")); |
109 | | - const rmMock = jest.spyOn(fsUtils, "removeDirectory").mockClear().mockResolvedValue(); |
| 111 | + const rmMock = jest.spyOn(fs.promises, "rm").mockClear().mockResolvedValue(); |
110 | 112 |
|
111 | 113 | // should return the error |
112 | 114 | await expect(installPackages(packages, createInstall(), nodecgIODir)).rejects.toThrow("random error"); |
|
0 commit comments