mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix unit tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ebd918fcf7
commit
938f44fd80
@ -68,10 +68,12 @@ function embed(clusterId: ClusterId, contents: any): string {
|
|||||||
return absPath;
|
return absPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
jest.mock("electron", () => {
|
jest.mock("electron", () => ({
|
||||||
return {
|
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en",
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: jest.fn(),
|
setLoginItemSettings: jest.fn(),
|
||||||
@ -83,8 +85,7 @@ jest.mock("electron", () => {
|
|||||||
off: jest.fn(),
|
off: jest.fn(),
|
||||||
send: jest.fn(),
|
send: jest.fn(),
|
||||||
}
|
}
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
AppPaths.init();
|
AppPaths.init();
|
||||||
|
|
||||||
|
|||||||
@ -117,20 +117,21 @@ const awsCluster = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock("electron", () => {
|
jest.mock("electron", () => ({
|
||||||
return {
|
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en",
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: (): void => void 0,
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
},
|
},
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
AppPaths.init();
|
AppPaths.init();
|
||||||
|
|
||||||
|
|||||||
@ -21,20 +21,21 @@
|
|||||||
|
|
||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
|
|
||||||
jest.mock("electron", () => {
|
jest.mock("electron", () => ({
|
||||||
return {
|
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en",
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: (): void => void 0,
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
},
|
},
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
import { UserStore } from "../user-store";
|
import { UserStore } from "../user-store";
|
||||||
import { Console } from "console";
|
import { Console } from "console";
|
||||||
|
|||||||
@ -42,7 +42,12 @@ jest.mock("../extension-installer", () => ({
|
|||||||
}));
|
}));
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: jest.fn(),
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
@ -51,11 +56,11 @@ jest.mock("electron", () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
AppPaths.init();
|
||||||
|
|
||||||
console = new Console(process.stdout, process.stderr); // fix mockFS
|
console = new Console(process.stdout, process.stderr); // fix mockFS
|
||||||
const mockedWatch = watch as jest.MockedFunction<typeof watch>;
|
const mockedWatch = watch as jest.MockedFunction<typeof watch>;
|
||||||
|
|
||||||
AppPaths.init();
|
|
||||||
|
|
||||||
describe("ExtensionDiscovery", () => {
|
describe("ExtensionDiscovery", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ExtensionDiscovery.resetInstance();
|
ExtensionDiscovery.resetInstance();
|
||||||
|
|||||||
@ -34,7 +34,13 @@ jest.mock("react-monaco-editor", () => null);
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
|
|||||||
@ -27,7 +27,12 @@ import { AppPaths } from "../../common/app-paths";
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: jest.fn(),
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
|
|||||||
@ -44,13 +44,6 @@ jest.mock("winston", () => ({
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
|
||||||
app: {
|
|
||||||
getPath: () => "tmp",
|
|
||||||
setLoginItemSettings: jest.fn(),
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock("../../common/ipc");
|
jest.mock("../../common/ipc");
|
||||||
jest.mock("child_process");
|
jest.mock("child_process");
|
||||||
jest.mock("tcp-port-used");
|
jest.mock("tcp-port-used");
|
||||||
@ -75,21 +68,21 @@ const mockBroadcastIpc = broadcastMessage as jest.MockedFunction<typeof broadcas
|
|||||||
const mockSpawn = spawn as jest.MockedFunction<typeof spawn>;
|
const mockSpawn = spawn as jest.MockedFunction<typeof spawn>;
|
||||||
const mockWaitUntilUsed = waitUntilUsed as jest.MockedFunction<typeof waitUntilUsed>;
|
const mockWaitUntilUsed = waitUntilUsed as jest.MockedFunction<typeof waitUntilUsed>;
|
||||||
|
|
||||||
jest.mock("electron", () => {
|
jest.mock("electron", () => ({
|
||||||
return {
|
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en",
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: (): void => void 0,
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
},
|
},
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
AppPaths.init();
|
AppPaths.init();
|
||||||
|
|
||||||
describe("kube auth proxy tests", () => {
|
describe("kube auth proxy tests", () => {
|
||||||
|
|||||||
@ -28,12 +28,6 @@ const logger = {
|
|||||||
crit: jest.fn(),
|
crit: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
|
||||||
app: {
|
|
||||||
getPath: () => `/tmp`,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock("winston", () => ({
|
jest.mock("winston", () => ({
|
||||||
format: {
|
format: {
|
||||||
colorize: jest.fn(),
|
colorize: jest.fn(),
|
||||||
@ -41,7 +35,9 @@ jest.mock("winston", () => ({
|
|||||||
simple: jest.fn(),
|
simple: jest.fn(),
|
||||||
label: jest.fn(),
|
label: jest.fn(),
|
||||||
timestamp: jest.fn(),
|
timestamp: jest.fn(),
|
||||||
printf: jest.fn()
|
padLevels: jest.fn(),
|
||||||
|
ms: jest.fn(),
|
||||||
|
printf: jest.fn(),
|
||||||
},
|
},
|
||||||
createLogger: jest.fn().mockReturnValue(logger),
|
createLogger: jest.fn().mockReturnValue(logger),
|
||||||
transports: {
|
transports: {
|
||||||
@ -58,6 +54,25 @@ import fse from "fs-extra";
|
|||||||
import { loadYaml } from "@kubernetes/client-node";
|
import { loadYaml } from "@kubernetes/client-node";
|
||||||
import { Console } from "console";
|
import { Console } from "console";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import { AppPaths } from "../../common/app-paths";
|
||||||
|
|
||||||
|
jest.mock("electron", () => ({
|
||||||
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
|
},
|
||||||
|
ipcMain: {
|
||||||
|
on: jest.fn(),
|
||||||
|
handle: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
AppPaths.init();
|
||||||
|
|
||||||
console = new Console(process.stdout, process.stderr); // fix mockFS
|
console = new Console(process.stdout, process.stderr); // fix mockFS
|
||||||
|
|
||||||
@ -111,7 +126,7 @@ describe("kubeconfig manager tests", () => {
|
|||||||
const kubeConfManager = new KubeconfigManager(cluster, contextHandler);
|
const kubeConfManager = new KubeconfigManager(cluster, contextHandler);
|
||||||
|
|
||||||
expect(logger.error).not.toBeCalled();
|
expect(logger.error).not.toBeCalled();
|
||||||
expect(await kubeConfManager.getPath()).toBe(`${path.sep}tmp${path.sep}kubeconfig-foo`);
|
expect(await kubeConfManager.getPath()).toBe(`tmp${path.sep}kubeconfig-foo`);
|
||||||
// this causes an intermittent "ENXIO: no such device or address, read" error
|
// this causes an intermittent "ENXIO: no such device or address, read" error
|
||||||
// const file = await fse.readFile(await kubeConfManager.getPath());
|
// const file = await fse.readFile(await kubeConfManager.getPath());
|
||||||
const file = fse.readFileSync(await kubeConfManager.getPath());
|
const file = fse.readFileSync(await kubeConfManager.getPath());
|
||||||
|
|||||||
@ -24,7 +24,12 @@ import { Router } from "../router";
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: jest.fn(),
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
|
|||||||
@ -32,7 +32,13 @@ import { AppPaths } from "../../../common/app-paths";
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getPath: () => "/foo",
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
|
|||||||
@ -35,7 +35,12 @@ jest.mock("../../../common/ipc");
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: jest.fn(),
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
|
|||||||
@ -31,26 +31,30 @@ import { CatalogEntityRegistry } from "../../../renderer/api/catalog-entity-regi
|
|||||||
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
import { CatalogEntityDetailRegistry } from "../../../extensions/registries";
|
||||||
import { CatalogEntityItem } from "./catalog-entity-item";
|
import { CatalogEntityItem } from "./catalog-entity-item";
|
||||||
import { CatalogEntityStore } from "./catalog-entity.store";
|
import { CatalogEntityStore } from "./catalog-entity.store";
|
||||||
|
import { AppPaths } from "../../../common/app-paths";
|
||||||
|
|
||||||
mockWindow();
|
mockWindow();
|
||||||
|
jest.mock("electron", () => ({
|
||||||
// avoid TypeError: Cannot read property 'getPath' of undefined
|
|
||||||
jest.mock("@electron/remote", () => {
|
|
||||||
return {
|
|
||||||
app: {
|
app: {
|
||||||
getPath: () => {
|
getVersion: () => "99.99.99",
|
||||||
// avoid TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
|
getName: () => "lens",
|
||||||
return "";
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
|
ipcMain: {
|
||||||
|
on: jest.fn(),
|
||||||
|
handle: jest.fn(),
|
||||||
},
|
},
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
jest.mock("./hotbar-toggle-menu-item", () => {
|
AppPaths.init();
|
||||||
return {
|
|
||||||
|
jest.mock("./hotbar-toggle-menu-item", () => ({
|
||||||
HotbarToggleMenuItem: () => <div>menu item</div>
|
HotbarToggleMenuItem: () => <div>menu item</div>
|
||||||
};
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
class MockCatalogEntity extends CatalogEntity {
|
class MockCatalogEntity extends CatalogEntity {
|
||||||
public apiVersion = "api";
|
public apiVersion = "api";
|
||||||
|
|||||||
@ -57,9 +57,12 @@ jest.mock("../../../../common/utils/tar");
|
|||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en",
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: (): void => void 0,
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
|
|||||||
@ -31,7 +31,13 @@ import { AppPaths } from "../../../../common/app-paths";
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
|
|||||||
@ -42,14 +42,19 @@ jest.mock("react-monaco-editor", () => ({
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
AppPaths.init();
|
AppPaths.init();
|
||||||
|
|
||||||
const initialTabs: DockTab[] = [
|
const initialTabs: DockTab[] = [
|
||||||
|
|||||||
@ -37,7 +37,13 @@ jest.mock("react-monaco-editor", () => null);
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
|
|||||||
@ -36,7 +36,13 @@ jest.mock("react-monaco-editor", () => null);
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
on: jest.fn(),
|
on: jest.fn(),
|
||||||
|
|||||||
@ -31,7 +31,12 @@ import { AppPaths } from "../../../../common/app-paths";
|
|||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
|
getVersion: () => "99.99.99",
|
||||||
|
getName: () => "lens",
|
||||||
|
setName: jest.fn(),
|
||||||
|
setPath: jest.fn(),
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
|
getLocale: () => "en",
|
||||||
setLoginItemSettings: jest.fn(),
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user