From 120e8ba0c1d407f6a42daced6353e62064f00a2d Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 4 Jan 2023 15:44:52 -0500 Subject: [PATCH] Fix app paths tests by making the tests run in "production" mode Signed-off-by: Sebastian Malton --- src/common/app-paths/app-paths.test.ts | 112 +++++++++--------- ...ormation.global-override-for-injectable.ts | 4 +- src/main/getDiForUnitTesting.ts | 2 +- src/renderer/getDiForUnitTesting.tsx | 2 +- ...ormation.global-override-for-injectable.ts | 24 ---- 5 files changed, 60 insertions(+), 84 deletions(-) rename src/{main => common}/vars/application-information.global-override-for-injectable.ts (79%) delete mode 100644 src/renderer/vars/application-information.global-override-for-injectable.ts diff --git a/src/common/app-paths/app-paths.test.ts b/src/common/app-paths/app-paths.test.ts index b26a5aca5d..6e645f96fa 100644 --- a/src/common/app-paths/app-paths.test.ts +++ b/src/common/app-paths/app-paths.test.ts @@ -19,23 +19,23 @@ describe("app-paths", () => { builder = getApplicationBuilder(); const defaultAppPathsStub: AppPaths = { - currentApp: "some-current-app", - appData: "some-app-data", - cache: "some-cache", - crashDumps: "some-crash-dumps", - desktop: "some-desktop", - documents: "some-documents", - downloads: "some-downloads", - exe: "some-exe", - home: "some-home-path", - logs: "some-logs", - module: "some-module", - music: "some-music", - pictures: "some-pictures", - recent: "some-recent", - temp: "some-temp", - videos: "some-videos", - userData: "some-irrelevant-user-data", + currentApp: "/some-current-app", + appData: "/some-app-data", + cache: "/some-cache", + crashDumps: "/some-crash-dumps", + desktop: "/some-desktop", + documents: "/some-documents", + downloads: "/some-downloads", + exe: "/some-exe", + home: "/some-home-path", + logs: "/some-logs", + module: "/some-module", + music: "/some-music", + pictures: "/some-pictures", + recent: "/some-recent", + temp: "/some-temp", + videos: "/some-videos", + userData: "/some-irrelevant-user-data", }; builder.beforeApplicationStart((mainDi) => { @@ -71,23 +71,23 @@ describe("app-paths", () => { const actual = windowDi.inject(appPathsInjectable); expect(actual).toEqual({ - currentApp: "some-current-app", - appData: "some-app-data", - cache: "some-cache", - crashDumps: "some-crash-dumps", - desktop: "some-desktop", - documents: "some-documents", - downloads: "some-downloads", - exe: "some-exe", - home: "some-home-path", - logs: "some-logs", - module: "some-module", - music: "some-music", - pictures: "some-pictures", - recent: "some-recent", - temp: "some-temp", - videos: "some-videos", - userData: "some-app-data/some-product-name", + currentApp: "/some-current-app", + appData: "/some-app-data", + cache: "/some-cache", + crashDumps: "/some-crash-dumps", + desktop: "/some-desktop", + documents: "/some-documents", + downloads: "/some-downloads", + exe: "/some-exe", + home: "/some-home-path", + logs: "/some-logs", + module: "/some-module", + music: "/some-music", + pictures: "/some-pictures", + recent: "/some-recent", + temp: "/some-temp", + videos: "/some-videos", + userData: "/some-app-data/some-product-name", }); }); @@ -95,23 +95,23 @@ describe("app-paths", () => { const actual = mainDi.inject(appPathsInjectable); expect(actual).toEqual({ - currentApp: "some-current-app", - appData: "some-app-data", - cache: "some-cache", - crashDumps: "some-crash-dumps", - desktop: "some-desktop", - documents: "some-documents", - downloads: "some-downloads", - exe: "some-exe", - home: "some-home-path", - logs: "some-logs", - module: "some-module", - music: "some-music", - pictures: "some-pictures", - recent: "some-recent", - temp: "some-temp", - videos: "some-videos", - userData: "some-app-data/some-product-name", + currentApp: "/some-current-app", + appData: "/some-app-data", + cache: "/some-cache", + crashDumps: "/some-crash-dumps", + desktop: "/some-desktop", + documents: "/some-documents", + downloads: "/some-downloads", + exe: "/some-exe", + home: "/some-home-path", + logs: "/some-logs", + module: "/some-module", + music: "/some-music", + pictures: "/some-pictures", + recent: "/some-recent", + temp: "/some-temp", + videos: "/some-videos", + userData: "/some-app-data/some-product-name", }); }); }); @@ -123,7 +123,7 @@ describe("app-paths", () => { builder.beforeApplicationStart((mainDi) => { mainDi.override( directoryForIntegrationTestingInjectable, - () => "some-integration-testing-app-data", + () => "/some-integration-testing-app-data", ); }); @@ -136,8 +136,8 @@ describe("app-paths", () => { const { appData, userData } = windowDi.inject(appPathsInjectable); expect({ appData, userData }).toEqual({ - appData: "some-integration-testing-app-data", - userData: `some-integration-testing-app-data/some-product-name`, + appData: "/some-integration-testing-app-data", + userData: "/some-integration-testing-app-data/some-product-name", }); }); @@ -145,8 +145,8 @@ describe("app-paths", () => { const { appData, userData } = windowDi.inject(appPathsInjectable); expect({ appData, userData }).toEqual({ - appData: "some-integration-testing-app-data", - userData: "some-integration-testing-app-data/some-product-name", + appData: "/some-integration-testing-app-data", + userData: "/some-integration-testing-app-data/some-product-name", }); }); }); diff --git a/src/main/vars/application-information.global-override-for-injectable.ts b/src/common/vars/application-information.global-override-for-injectable.ts similarity index 79% rename from src/main/vars/application-information.global-override-for-injectable.ts rename to src/common/vars/application-information.global-override-for-injectable.ts index acc47ce83d..e0b886fa65 100644 --- a/src/main/vars/application-information.global-override-for-injectable.ts +++ b/src/common/vars/application-information.global-override-for-injectable.ts @@ -3,8 +3,8 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import { getGlobalOverride } from "../../common/test-utils/get-global-override"; -import applicationInformationInjectable from "../../common/vars/application-information-injectable"; +import { getGlobalOverride } from "../test-utils/get-global-override"; +import applicationInformationInjectable from "./application-information-injectable"; export default getGlobalOverride(applicationInformationInjectable, () => ({ name: "some-product-name", diff --git a/src/main/getDiForUnitTesting.ts b/src/main/getDiForUnitTesting.ts index d5479175b4..b3fd0918a1 100644 --- a/src/main/getDiForUnitTesting.ts +++ b/src/main/getDiForUnitTesting.ts @@ -63,7 +63,7 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {}) di.register(getInjectable({ id: "node-env", - instantiate: () => "test", + instantiate: () => "production", injectionToken: nodeEnvInjectionToken, })); diff --git a/src/renderer/getDiForUnitTesting.tsx b/src/renderer/getDiForUnitTesting.tsx index a8e122bcb9..5b47f738a0 100644 --- a/src/renderer/getDiForUnitTesting.tsx +++ b/src/renderer/getDiForUnitTesting.tsx @@ -37,7 +37,7 @@ export const getDiForUnitTesting = ( di.register(getInjectable({ id: "node-env", - instantiate: () => "test", + instantiate: () => "production", injectionToken: nodeEnvInjectionToken, })); diff --git a/src/renderer/vars/application-information.global-override-for-injectable.ts b/src/renderer/vars/application-information.global-override-for-injectable.ts deleted file mode 100644 index acc47ce83d..0000000000 --- a/src/renderer/vars/application-information.global-override-for-injectable.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import { getGlobalOverride } from "../../common/test-utils/get-global-override"; -import applicationInformationInjectable from "../../common/vars/application-information-injectable"; - -export default getGlobalOverride(applicationInformationInjectable, () => ({ - name: "some-product-name", - productName: "some-product-name", - version: "6.0.0", - build: {} as any, - config: { - k8sProxyVersion: "0.2.1", - bundledKubectlVersion: "1.23.3", - bundledHelmVersion: "3.7.2", - sentryDsn: "", - contentSecurityPolicy: "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:", - welcomeRoute: "/welcome", - }, - copyright: "some-copyright-information", - description: "some-descriptive-text", -}));