mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Introduce abstraction for joining paths
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
911481ea0f
commit
c5b14c48d8
18
src/common/path/join-paths.injectable.ts
Normal file
18
src/common/path/join-paths.injectable.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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 path from "path";
|
||||
|
||||
export type JoinPaths = (...args: string[]) => string;
|
||||
|
||||
const joinPathsInjectable = getInjectable({
|
||||
id: "join-paths",
|
||||
instantiate: (): JoinPaths => path.join,
|
||||
|
||||
// This causes side effect e.g. Windows uses different separator than e.g. linux
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default joinPathsInjectable;
|
||||
8
src/common/test-utils/join-paths-fake.ts
Normal file
8
src/common/test-utils/join-paths-fake.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { join } from "lodash/fp";
|
||||
import type { JoinPaths } from "../path/join-paths.injectable";
|
||||
|
||||
export const joinPathsFake: JoinPaths = join("/");
|
||||
@ -32,6 +32,8 @@ import isWindowsInjectable from "../common/vars/is-windows.injectable";
|
||||
import isLinuxInjectable from "../common/vars/is-linux.injectable";
|
||||
import getAbsolutePathInjectable from "../common/path/get-absolute-path.injectable";
|
||||
import { getAbsolutePathFake } from "../common/test-utils/get-absolute-path-fake";
|
||||
import joinPathsInjectable from "../common/path/join-paths.injectable";
|
||||
import { joinPathsFake } from "../common/test-utils/join-paths-fake";
|
||||
|
||||
export const getDiForUnitTesting = (
|
||||
{ doGeneralOverrides } = { doGeneralOverrides: false },
|
||||
@ -58,6 +60,7 @@ export const getDiForUnitTesting = (
|
||||
di.override(isLinuxInjectable, () => false);
|
||||
|
||||
di.override(getAbsolutePathInjectable, () => getAbsolutePathFake);
|
||||
di.override(joinPathsInjectable, () => joinPathsFake);
|
||||
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||
di.override(extensionsStoreInjectable, () => ({ isEnabled: ({ id, isBundled }) => false }) as ExtensionsStore);
|
||||
|
||||
@ -30,6 +30,8 @@ import isWindowsInjectable from "../common/vars/is-windows.injectable";
|
||||
import isLinuxInjectable from "../common/vars/is-linux.injectable";
|
||||
import getAbsolutePathInjectable from "../common/path/get-absolute-path.injectable";
|
||||
import { getAbsolutePathFake } from "../common/test-utils/get-absolute-path-fake";
|
||||
import joinPathsInjectable from "../common/path/join-paths.injectable";
|
||||
import { joinPathsFake } from "../common/test-utils/join-paths-fake";
|
||||
|
||||
export const getDiForUnitTesting = (
|
||||
{ doGeneralOverrides } = { doGeneralOverrides: false },
|
||||
@ -55,6 +57,7 @@ export const getDiForUnitTesting = (
|
||||
di.override(isLinuxInjectable, () => false);
|
||||
|
||||
di.override(getAbsolutePathInjectable, () => getAbsolutePathFake);
|
||||
di.override(joinPathsInjectable, () => joinPathsFake);
|
||||
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||
di.override(extensionsStoreInjectable, () => ({ isEnabled: ({ id, isBundled }) => false }) as ExtensionsStore);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user