1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

try and get jest to not core dump

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-04-26 15:51:17 -04:00
parent c3dcf0e838
commit 109551950a
6 changed files with 32 additions and 21 deletions

View File

@ -43,13 +43,17 @@ jest.mock("electron", () => {
},
ipcMain: {
handle: jest.fn(),
on: jest.fn()
on: jest.fn(),
removeAllListeners: jest.fn(),
off: jest.fn(),
send: jest.fn(),
}
};
});
describe("empty config", () => {
beforeEach(async () => {
ClusterStore.getInstance(false)?.unregisterIpcListener();
ClusterStore.resetInstance();
const mockOpts = {
"tmp": {

View File

@ -124,8 +124,8 @@ export abstract class BaseStore<T = any> extends Singleton {
}
unregisterIpcListener() {
ipcRenderer.removeAllListeners(this.syncMainChannel);
ipcRenderer.removeAllListeners(this.syncRendererChannel);
ipcRenderer?.removeAllListeners(this.syncMainChannel);
ipcRenderer?.removeAllListeners(this.syncRendererChannel);
}
disableSync() {
@ -167,7 +167,7 @@ export abstract class BaseStore<T = any> extends Singleton {
/**
* toJSON is called when syncing the store to the filesystem. It should
* produce a JSON serializable object representaion of the current state.
* produce a JSON serializable object representation of the current state.
*
* It is recommended that a round trip is valid. Namely, calling
* `this.fromStore(this.toJSON())` shouldn't change the state.

View File

@ -1,5 +1,5 @@
import path from "path";
import { app, ipcRenderer, remote, webFrame } from "electron";
import { app, ipcMain, ipcRenderer, remote, webFrame } from "electron";
import { unlink } from "fs-extra";
import { action, comparer, computed, observable, reaction, toJS } from "mobx";
import { BaseStore } from "./base-store";
@ -12,6 +12,7 @@ import { saveToAppFiles } from "./utils/saveToAppFiles";
import { KubeConfig } from "@kubernetes/client-node";
import { handleRequest, requestMain, subscribeToBroadcast, unsubscribeAllFromBroadcast } from "./ipc";
import { ResourceType } from "../renderer/components/cluster-settings/components/cluster-metrics-setting";
import { disposer, noop } from "./utils";
export interface ClusterIconUpload {
clusterId: string;
@ -111,6 +112,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
@observable clusters = observable.map<ClusterId, Cluster>();
private static stateRequestChannel = "cluster:states";
protected disposer = disposer();
constructor() {
super({
@ -143,7 +145,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
cluster.setState(clusterState.state);
}
});
} else {
} else if (ipcMain) {
handleRequest(ClusterStore.stateRequestChannel, (): clusterStateSync[] => {
const states: clusterStateSync[] = [];
@ -160,13 +162,16 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
}
protected pushStateToViewsAutomatically() {
if (!ipcRenderer) {
reaction(() => this.enabledClustersList, () => {
this.pushState();
});
reaction(() => this.connectedClustersList, () => {
this.pushState();
});
if (ipcMain) {
this.disposer.push(
reaction(() => this.enabledClustersList, () => {
this.pushState();
}),
reaction(() => this.connectedClustersList, () => {
this.pushState();
}),
() => unsubscribeAllFromBroadcast("cluster:state"),
);
}
}
@ -180,7 +185,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
unregisterIpcListener() {
super.unregisterIpcListener();
unsubscribeAllFromBroadcast("cluster:state");
this.disposer();
}
pushState() {
@ -288,7 +293,7 @@ export class ClusterStore extends BaseStore<ClusterStoreModel> {
// remove only custom kubeconfigs (pasted as text)
if (cluster.kubeConfigPath == ClusterStore.getCustomKubeConfigPath(clusterId)) {
unlink(cluster.kubeConfigPath).catch(() => null);
await unlink(cluster.kubeConfigPath).catch(noop);
}
}
}

View File

@ -28,7 +28,7 @@ export async function broadcastMessage(channel: string, ...args: any[]) {
if (ipcRenderer) {
ipcRenderer.send(channel, ...args);
} else {
} else if (ipcMain) {
ipcMain.emit(channel, ...args);
}
@ -55,7 +55,7 @@ export async function broadcastMessage(channel: string, ...args: any[]) {
export function subscribeToBroadcast(channel: string, listener: (...args: any[]) => any) {
if (ipcRenderer) {
ipcRenderer.on(channel, listener);
} else {
} else if (ipcMain) {
ipcMain.on(channel, listener);
}
@ -65,7 +65,7 @@ export function subscribeToBroadcast(channel: string, listener: (...args: any[])
export function unsubscribeFromBroadcast(channel: string, listener: (...args: any[]) => any) {
if (ipcRenderer) {
ipcRenderer.off(channel, listener);
} else {
} else if (ipcMain) {
ipcMain.off(channel, listener);
}
}
@ -73,7 +73,7 @@ export function unsubscribeFromBroadcast(channel: string, listener: (...args: an
export function unsubscribeAllFromBroadcast(channel: string) {
if (ipcRenderer) {
ipcRenderer.removeAllListeners(channel);
} else {
} else if (ipcMain) {
ipcMain.removeAllListeners(channel);
}
}

View File

@ -6,6 +6,8 @@ import { ExtensionDiscovery } from "../extension-discovery";
import os from "os";
import { Console } from "console";
jest.setTimeout(60_000);
jest.mock("../../common/ipc");
jest.mock("chokidar", () => ({
watch: jest.fn()

View File

@ -1,6 +1,6 @@
import { app, remote } from "electron";
import winston from "winston";
import { isDebugging } from "../common/vars";
import { isDebugging, isTestEnv } from "../common/vars";
const logLevel = process.env.LOG_LEVEL ? process.env.LOG_LEVEL : isDebugging ? "debug" : "info";
const consoleOptions: winston.transports.ConsoleTransportOptions = {
@ -23,7 +23,7 @@ const logger = winston.createLogger({
),
transports: [
new winston.transports.Console(consoleOptions),
new winston.transports.File(fileOptions),
...(isTestEnv ? [] : [new winston.transports.File(fileOptions)]),
],
});