mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix unit tests falling over
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
af46ca76fd
commit
09892781f7
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
import { disposer, isPromiseLike } from "@k8slens/utilities";
|
import { disposer, isPromiseLike } from "@k8slens/utilities";
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import type Conf from "conf/dist/source";
|
|
||||||
import type { Options } from "conf/dist/source";
|
import type { Options } from "conf/dist/source";
|
||||||
import { isEqual, kebabCase } from "lodash";
|
import { isEqual, kebabCase } from "lodash";
|
||||||
import type { IEqualsComparer } from "mobx";
|
import type { IEqualsComparer } from "mobx";
|
||||||
@ -13,13 +12,13 @@ import directoryForUserDataInjectable from "../app-paths/directory-for-user-data
|
|||||||
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
import getConfigurationFileModelInjectable from "../get-configuration-file-model/get-configuration-file-model.injectable";
|
||||||
import loggerInjectable from "../logger.injectable";
|
import loggerInjectable from "../logger.injectable";
|
||||||
import getBasenameOfPathInjectable from "../path/get-basename.injectable";
|
import getBasenameOfPathInjectable from "../path/get-basename.injectable";
|
||||||
import { toJS } from "../utils";
|
|
||||||
import { enlistMessageChannelListenerInjectionToken, sendMessageToChannelInjectionToken } from "@k8slens/messaging";
|
import { enlistMessageChannelListenerInjectionToken, sendMessageToChannelInjectionToken } from "@k8slens/messaging";
|
||||||
import type { MessageChannel } from "@k8slens/messaging";
|
import type { MessageChannel } from "@k8slens/messaging";
|
||||||
import { persistentStorageIpcChannelPrefixesInjectionToken } from "./channel-prefix";
|
import { persistentStorageIpcChannelPrefixesInjectionToken } from "./channel-prefix";
|
||||||
import { shouldPersistentStorageDisableSyncInIpcListenerInjectionToken } from "./disable-sync";
|
import { shouldPersistentStorageDisableSyncInIpcListenerInjectionToken } from "./disable-sync";
|
||||||
import { persistStateToConfigInjectionToken } from "./save-to-file";
|
import { persistStateToConfigInjectionToken } from "./save-to-file";
|
||||||
import type { Migrations } from "./migrations.injectable";
|
import type { Migrations } from "./migrations.injectable";
|
||||||
|
import { nextTick } from "process";
|
||||||
|
|
||||||
export interface PersistentStorage {
|
export interface PersistentStorage {
|
||||||
/**
|
/**
|
||||||
@ -82,7 +81,6 @@ const createPersistentStorageInjectable = getInjectable({
|
|||||||
...params
|
...params
|
||||||
} = rawParams;
|
} = rawParams;
|
||||||
const displayName = kebabCase(params.configName).toUpperCase();
|
const displayName = kebabCase(params.configName).toUpperCase();
|
||||||
const syncDisposers = disposer();
|
|
||||||
|
|
||||||
const loadAndStartSyncing = () => {
|
const loadAndStartSyncing = () => {
|
||||||
logger.info(`[${displayName}]: LOADING ...`);
|
logger.info(`[${displayName}]: LOADING ...`);
|
||||||
@ -100,11 +98,9 @@ const createPersistentStorageInjectable = getInjectable({
|
|||||||
logger.error(`${displayName} extends BaseStore<T>'s fromStore method returns a Promise or promise-like object. This is an error and must be fixed.`);
|
logger.error(`${displayName} extends BaseStore<T>'s fromStore method returns a Promise or promise-like object. This is an error and must be fixed.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
startSyncing(config);
|
|
||||||
logger.info(`[${displayName}]: LOADED from ${config.path}`);
|
logger.info(`[${displayName}]: LOADED from ${config.path}`);
|
||||||
};
|
|
||||||
|
|
||||||
const startSyncing = (config: Conf<T>) => {
|
const syncDisposers = disposer();
|
||||||
const sendChannel: MessageChannel<T> = {
|
const sendChannel: MessageChannel<T> = {
|
||||||
id: `${ipcChannelPrefixes.remote}:${config.path}`,
|
id: `${ipcChannelPrefixes.remote}:${config.path}`,
|
||||||
};
|
};
|
||||||
@ -117,8 +113,9 @@ const createPersistentStorageInjectable = getInjectable({
|
|||||||
const enableSync = () => {
|
const enableSync = () => {
|
||||||
syncDisposers.push(
|
syncDisposers.push(
|
||||||
reaction(
|
reaction(
|
||||||
() => toJS(toJSON()), // unwrap possible observables and react to everything
|
() => toJSON(),
|
||||||
model => {
|
model => {
|
||||||
|
console.log("here2", { sendChannel });
|
||||||
persistStateToConfig(config, model);
|
persistStateToConfig(config, model);
|
||||||
sendMessageToChannel(sendChannel, model);
|
sendMessageToChannel(sendChannel, model);
|
||||||
},
|
},
|
||||||
@ -140,7 +137,9 @@ const createPersistentStorageInjectable = getInjectable({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldDisableSyncInListener) {
|
if (shouldDisableSyncInListener) {
|
||||||
|
nextTick(() => {
|
||||||
enableSync();
|
enableSync();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -19,7 +19,11 @@ export const advanceFakeTime = (milliseconds: number) => {
|
|||||||
export const testUsingFakeTime = (dateTime = "2015-10-21T07:28:00Z") => {
|
export const testUsingFakeTime = (dateTime = "2015-10-21T07:28:00Z") => {
|
||||||
usingFakeTime = true;
|
usingFakeTime = true;
|
||||||
|
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers({
|
||||||
|
doNotFake: [
|
||||||
|
"nextTick",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
jest.setSystemTime(new Date(dateTime));
|
jest.setSystemTime(new Date(dateTime));
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user