1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Switch to using deterministic fake for path.join in unit test

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2023-02-23 10:02:00 +02:00
parent 99c70c62ce
commit 5d21353493
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
2 changed files with 16 additions and 6 deletions

View File

@ -14,7 +14,7 @@ const {
} = require("lodash/fp"); } = require("lodash/fp");
const { pipeline } = require("@ogre-tools/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) { if (!packageJson.lensMultiExportConfig) {
throw new Error( throw new Error(
`Tried to get multi export config for package "${packageJson.name}" but configuration is missing.` `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( const expectedExports = pipeline(
packageJson.lensMultiExportConfig, packageJson.lensMultiExportConfig,
keys, keys,
map(toExpectedExport), map(toExpectedExportFor(dependencies)),
fromPairs fromPairs
); );
@ -79,8 +79,8 @@ module.exports = (packageJson, dependencies = { nodeConfig, reactConfig }) => {
); );
}; };
const toExpectedExport = (externalImportPath) => { const toExpectedExportFor = (dependencies) => (externalImportPath) => {
const entrypointPath = `./${path.join( const entrypointPath = `./${dependencies.joinPath(
"./dist", "./dist",
externalImportPath, externalImportPath,
"index.js" "index.js"
@ -89,7 +89,7 @@ const toExpectedExport = (externalImportPath) => {
return [ return [
externalImportPath, externalImportPath,
{ {
types: `./${path.join("./dist", externalImportPath, "index.d.ts")}`, types: `./${dependencies.joinPath("./dist", externalImportPath, "index.d.ts")}`,
default: entrypointPath, default: entrypointPath,
import: entrypointPath, import: entrypointPath,
@ -114,7 +114,7 @@ const toExportSpecificWebpackConfigFor =
output: { output: {
...baseConfig.output, ...baseConfig.output,
path: path.join(baseConfig.output.path, externalImportPath), path: dependencies.joinPath(baseConfig.output.path, externalImportPath),
}, },
}; };
}; };

View File

@ -1,4 +1,7 @@
import getMultiExportConfig from "./get-multi-export-config"; import getMultiExportConfig from "./get-multi-export-config";
import path from 'path';
const joinPathFake = path.posix.join;
describe("get-multi-export-config", () => { describe("get-multi-export-config", () => {
let actual; let actual;
@ -52,6 +55,7 @@ describe("get-multi-export-config", () => {
actual = getMultiExportConfig(maximalPackageJson, { actual = getMultiExportConfig(maximalPackageJson, {
nodeConfig: nodeConfigStub, nodeConfig: nodeConfigStub,
reactConfig: reactConfigStub, reactConfig: reactConfigStub,
joinPath: joinPathFake,
}); });
expect(actual).toEqual([ expect(actual).toEqual([
@ -93,6 +97,7 @@ describe("get-multi-export-config", () => {
getMultiExportConfig(maximalPackageJson, { getMultiExportConfig(maximalPackageJson, {
nodeConfig: nodeConfigStub, nodeConfig: nodeConfigStub,
reactConfig: reactConfigStub, reactConfig: reactConfigStub,
joinPath: joinPathFake,
}); });
}).toThrow( }).toThrow(
'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' '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, { getMultiExportConfig(maximalPackageJson, {
nodeConfig: nodeConfigStub, nodeConfig: nodeConfigStub,
reactConfig: reactConfigStub, reactConfig: reactConfigStub,
joinPath: joinPathFake,
}); });
}).toThrow( }).toThrow(
'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' '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, { getMultiExportConfig(maximalPackageJson, {
nodeConfig: nodeConfigStub, nodeConfig: nodeConfigStub,
reactConfig: reactConfigStub, reactConfig: reactConfigStub,
joinPath: joinPathFake,
}); });
}).toThrow( }).toThrow(
'Tried to get multi export config but exports of package.json for "some-name" did not match exactly:' '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, { getMultiExportConfig(maximalPackageJson, {
nodeConfig: nodeConfigStub, nodeConfig: nodeConfigStub,
reactConfig: reactConfigStub, reactConfig: reactConfigStub,
joinPath: joinPathFake,
}); });
}).toThrow( }).toThrow(
'Tried to get multi export config for package "some-name" but configuration is missing.' '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, { getMultiExportConfig(maximalPackageJson, {
nodeConfig: nodeConfigStub, nodeConfig: nodeConfigStub,
reactConfig: reactConfigStub, reactConfig: reactConfigStub,
joinPath: joinPathFake,
}); });
}).toThrow( }).toThrow(
'Tried to get multi export config for package "some-name" but build types "some-invalid" were not any of "node", "react".' '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, { getMultiExportConfig(maximalPackageJson, {
nodeConfig: nodeConfigStub, nodeConfig: nodeConfigStub,
reactConfig: reactConfigStub, reactConfig: reactConfigStub,
joinPath: joinPathFake,
}); });
}).toThrow( }).toThrow(
'Tried to get multi export config for package "some-name" but entrypoint was missing for "./some-entrypoint".' 'Tried to get multi export config for package "some-name" but entrypoint was missing for "./some-entrypoint".'