Stop using @electron/remote to obtain app.getPath() (#4078)

* Stop using remote to obtain app.getPath()

- Initialize entire map in bootstrap()

- Updated unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Resolve PR comments

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix test

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Ensure that init can only be called once and catch errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Replace basically all uses of app.getPath() with AppPaths.get()

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-10-27 21:07:41 -04:00
1 parent 65b6908bf1
commit f297407156
45 files changed
+521 -200

No files matched your search

@@ -31,6 +31,7 @@ import { ExtensionInstallationStateStore } from "../extension-install.store";
import { Extensions } from "../extensions";
import mockFs from "mock-fs";
import { mockWindow } from "../../../../../__mocks__/windowMock";
import { AppPaths } from "../../../../common/app-paths";
mockWindow();
@@ -38,23 +39,39 @@ jest.setTimeout(30000);
jest.mock("fs-extra");
jest.mock("../../notifications");
jest.mock("../../../../common/utils", () => ({
...jest.requireActual<any>("../../../../common/utils"),
downloadFile: jest.fn(() => ({
promise: Promise.resolve()
jest.mock("../../../../common/utils/downloadFile", () => ({
downloadFile: jest.fn(({ url }) => ({
promise: Promise.resolve(),
url,
cancel: () => {},
})),
downloadJson: jest.fn(({ url }) => ({
promise: Promise.resolve({}),
url,
cancel: () => { },
})),
extractTar: jest.fn(() => Promise.resolve())
}));
jest.mock("../../../../common/utils/tar");
jest.mock("electron", () => ({
app: {
getVersion: () => "99.99.99",
getName: () => "lens",
setName: jest.fn(),
setPath: jest.fn(),
getPath: () => "tmp",
getLocale: () => "en",
setLoginItemSettings: (): void => void 0,
}
setLoginItemSettings: jest.fn(),
},
ipcMain: {
on: jest.fn(),
handle: jest.fn(),
},
}));
AppPaths.init();
describe("Extensions", () => {
beforeEach(async () => {
mockFs({
@@ -47,7 +47,7 @@ import { Notice } from "./notice";
import { SettingLayout } from "../layout/setting-layout";
import { docsUrl } from "../../../common/vars";
import { dialog } from "../../remote-helpers";
import { getPath } from "../../../common/utils/getPath";
import { AppPaths } from "../../../common/app-paths";
function getMessageFromError(error: any): string {
if (!error || typeof error !== "object") {
@@ -469,7 +469,7 @@ const supportedFormats = ["tar", "tgz"];
async function installFromSelectFileDialog() {
const { canceled, filePaths } = await dialog.showOpenDialog({
defaultPath: getPath("downloads"),
defaultPath: AppPaths.get("downloads"),
properties: ["openFile", "multiSelections"],
message: `Select extensions to install (formats: ${supportedFormats.join(", ")}), `,
buttonLabel: "Use configuration",