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
c101a9ac57
commit
50c08def4c
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import nodeEnvInjectionToken from "./node-env-injection-token";
|
||||||
|
|
||||||
|
const nodeEnvFakeInjectable = getInjectable({
|
||||||
|
id: "node-env-fake",
|
||||||
|
instantiate: () => "production",
|
||||||
|
injectionToken: nodeEnvInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default nodeEnvFakeInjectable;
|
||||||
@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { chunk } from "lodash/fp";
|
import { chunk } from "lodash/fp";
|
||||||
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import { isInjectable, getInjectable } from "@ogre-tools/injectable";
|
import { isInjectable } from "@ogre-tools/injectable";
|
||||||
import spawnInjectable from "./child-process/spawn.injectable";
|
import spawnInjectable from "./child-process/spawn.injectable";
|
||||||
import initializeExtensionsInjectable from "./start-main-application/runnables/initialize-extensions.injectable";
|
import initializeExtensionsInjectable from "./start-main-application/runnables/initialize-extensions.injectable";
|
||||||
import setupIpcMainHandlersInjectable from "./electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable";
|
import setupIpcMainHandlersInjectable from "./electron-app/runnables/setup-ipc-main-handlers/setup-ipc-main-handlers.injectable";
|
||||||
@ -27,9 +27,7 @@ import waitUntilBundledExtensionsAreLoadedInjectable from "./start-main-applicat
|
|||||||
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
|
import electronInjectable from "./utils/resolve-system-proxy/electron.injectable";
|
||||||
import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable";
|
import initializeClusterManagerInjectable from "./cluster/initialize-manager.injectable";
|
||||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
|
||||||
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
||||||
import { applicationInformationFakeInjectable } from "../common/vars/application-information-fake-injectable";
|
|
||||||
import { getDi } from "./getDi";
|
import { getDi } from "./getDi";
|
||||||
|
|
||||||
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) {
|
||||||
@ -39,27 +37,17 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
|
|||||||
|
|
||||||
const di = getDi();
|
const di = getDi();
|
||||||
|
|
||||||
di.register(getInjectable({
|
|
||||||
id: "node-env",
|
|
||||||
instantiate: () => "production",
|
|
||||||
injectionToken: nodeEnvInjectionToken,
|
|
||||||
}));
|
|
||||||
|
|
||||||
di.preventSideEffects();
|
di.preventSideEffects();
|
||||||
|
|
||||||
const injectables = (
|
runInAction(() => {
|
||||||
global.injectablePaths.main.paths
|
const injectables = global.injectablePaths.main.paths
|
||||||
.map(path => require(path))
|
.map(path => require(path))
|
||||||
.flatMap(Object.values)
|
.flatMap(Object.values)
|
||||||
.filter(isInjectable)
|
.filter(isInjectable);
|
||||||
) as Injectable<any, any, any>[];
|
|
||||||
|
|
||||||
runInAction(() => {
|
for (const block of chunk(100)(injectables)) {
|
||||||
di.register(applicationInformationFakeInjectable);
|
di.register(...block);
|
||||||
|
}
|
||||||
chunk(100)(injectables).forEach(chunkInjectables => {
|
|
||||||
di.register(...chunkInjectables);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (doGeneralOverrides) {
|
if (doGeneralOverrides) {
|
||||||
|
|||||||
@ -4,8 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { noop, chunk } from "lodash/fp";
|
import { noop, chunk } from "lodash/fp";
|
||||||
import type { Injectable } from "@ogre-tools/injectable";
|
import { isInjectable } from "@ogre-tools/injectable";
|
||||||
import { isInjectable, getInjectable } from "@ogre-tools/injectable";
|
|
||||||
import requestFromChannelInjectable from "./utils/channel/request-from-channel.injectable";
|
import requestFromChannelInjectable from "./utils/channel/request-from-channel.injectable";
|
||||||
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
import { getOverrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
||||||
import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable";
|
import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable";
|
||||||
@ -16,8 +15,6 @@ import startTopbarStateSyncInjectable from "./components/layout/top-bar/start-st
|
|||||||
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
|
import watchHistoryStateInjectable from "./remote-helpers/watch-history-state.injectable";
|
||||||
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
|
import legacyOnChannelListenInjectable from "./ipc/legacy-channel-listen.injectable";
|
||||||
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
import type { GlobalOverride } from "../common/test-utils/get-global-override";
|
||||||
import nodeEnvInjectionToken from "../common/vars/node-env-injection-token";
|
|
||||||
import { applicationInformationFakeInjectable } from "../common/vars/application-information-fake-injectable";
|
|
||||||
import { getDi } from "./getDi";
|
import { getDi } from "./getDi";
|
||||||
|
|
||||||
export const getDiForUnitTesting = (
|
export const getDiForUnitTesting = (
|
||||||
@ -27,27 +24,17 @@ export const getDiForUnitTesting = (
|
|||||||
|
|
||||||
const di = getDi();
|
const di = getDi();
|
||||||
|
|
||||||
di.register(getInjectable({
|
|
||||||
id: "node-env",
|
|
||||||
instantiate: () => "production",
|
|
||||||
injectionToken: nodeEnvInjectionToken,
|
|
||||||
}));
|
|
||||||
|
|
||||||
di.preventSideEffects();
|
di.preventSideEffects();
|
||||||
|
|
||||||
const injectables = (
|
runInAction(() => {
|
||||||
global.injectablePaths.renderer.paths
|
const injectables = global.injectablePaths.renderer.paths
|
||||||
.map(path => require(path))
|
.map(path => require(path))
|
||||||
.flatMap(Object.values)
|
.flatMap(Object.values)
|
||||||
.filter(isInjectable)
|
.filter(isInjectable);
|
||||||
) as Injectable<any, any, any>[];
|
|
||||||
|
|
||||||
runInAction(() => {
|
for (const block of chunk(100)(injectables)) {
|
||||||
di.register(applicationInformationFakeInjectable);
|
di.register(...block);
|
||||||
|
}
|
||||||
chunk(100)(injectables).forEach((chunkInjectables) => {
|
|
||||||
di.register(...chunkInjectables);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (doGeneralOverrides) {
|
if (doGeneralOverrides) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user