From 5d21353493fb1c85f0adc12e7531a56a2a876e3e Mon Sep 17 00:00:00 2001 From: Janne Savolainen Date: Thu, 23 Feb 2023 10:02:00 +0200 Subject: [PATCH] Switch to using deterministic fake for path.join in unit test Signed-off-by: Janne Savolainen --- .../webpack/src/get-multi-export-config.js | 12 ++++++------ .../webpack/src/get-multi-export-config.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/infrastructure/webpack/src/get-multi-export-config.js b/packages/infrastructure/webpack/src/get-multi-export-config.js index 02944c25d3..c784f63d57 100644 --- a/packages/infrastructure/webpack/src/get-multi-export-config.js +++ b/packages/infrastructure/webpack/src/get-multi-export-config.js @@ -14,7 +14,7 @@ const { } = require("lodash/fp"); const { pipeline } = require("@ogre-tools/fp"); -module.exports = (packageJson, dependencies = { nodeConfig, reactConfig }) => { +module.exports = (packageJson, dependencies = { nodeConfig, reactConfig, joinPath: path.join }) => { if (!packageJson.lensMultiExportConfig) { throw new Error( `Tried to get multi export config for package "${packageJson.name}" but configuration is missing.` @@ -60,7 +60,7 @@ module.exports = (packageJson, dependencies = { nodeConfig, reactConfig }) => { const expectedExports = pipeline( packageJson.lensMultiExportConfig, keys, - map(toExpectedExport), + map(toExpectedExportFor(dependencies)), fromPairs ); @@ -79,8 +79,8 @@ module.exports = (packageJson, dependencies = { nodeConfig, reactConfig }) => { ); }; -const toExpectedExport = (externalImportPath) => { - const entrypointPath = `./${path.join( +const toExpectedExportFor = (dependencies) => (externalImportPath) => { + const entrypointPath = `./${dependencies.joinPath( "./dist", externalImportPath, "index.js" @@ -89,7 +89,7 @@ const toExpectedExport = (externalImportPath) => { return [ externalImportPath, { - types: `./${path.join("./dist", externalImportPath, "index.d.ts")}`, + types: `./${dependencies.joinPath("./dist", externalImportPath, "index.d.ts")}`, default: entrypointPath, import: entrypointPath, @@ -114,7 +114,7 @@ const toExportSpecificWebpackConfigFor = output: { ...baseConfig.output, - path: path.join(baseConfig.output.path, externalImportPath), + path: dependencies.joinPath(baseConfig.output.path, externalImportPath), }, }; }; diff --git a/packages/infrastructure/webpack/src/get-multi-export-config.test.js b/packages/infrastructure/webpack/src/get-multi-export-config.test.js index 6cad83919f..b0ce1c2231 100644 --- a/packages/infrastructure/webpack/src/get-multi-export-config.test.js +++ b/packages/infrastructure/webpack/src/get-multi-export-config.test.js @@ -1,4 +1,7 @@ import getMultiExportConfig from "./get-multi-export-config"; +import path from 'path'; + +const joinPathFake = path.posix.join; describe("get-multi-export-config", () => { let actual; @@ -52,6 +55,7 @@ describe("get-multi-export-config", () => { actual = getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); expect(actual).toEqual([ @@ -93,6 +97,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' @@ -106,6 +111,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' @@ -119,6 +125,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' @@ -132,6 +139,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config for package "some-name" but configuration is missing.' @@ -145,6 +153,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config for package "some-name" but build types "some-invalid" were not any of "node", "react".' @@ -159,6 +168,7 @@ describe("get-multi-export-config", () => { getMultiExportConfig(maximalPackageJson, { nodeConfig: nodeConfigStub, reactConfig: reactConfigStub, + joinPath: joinPathFake, }); }).toThrow( 'Tried to get multi export config for package "some-name" but entrypoint was missing for "./some-entrypoint".'