From 3880fa0e4ca27455b1fb27aadf8e72436a507787 Mon Sep 17 00:00:00 2001 From: Seth Silesky Date: Fri, 2 Sep 2022 17:36:55 -0500 Subject: [PATCH] add jest module map --- internal/config/src/jest/index.js | 17 ++++++++++++++--- packages/browser/jest.config.js | 6 +++--- packages/browser/package.json | 1 + packages/core-integration-tests/jest.config.js | 2 +- packages/node/jest.config.js | 2 +- turbo.json | 2 -- yarn.lock | 1 + 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/internal/config/src/jest/index.js b/internal/config/src/jest/index.js index 3e8707a1b..a3a36a19d 100644 --- a/internal/config/src/jest/index.js +++ b/internal/config/src/jest/index.js @@ -1,6 +1,13 @@ const getPackages = require('get-monorepo-packages') -const getJestModuleMap = (packageRoot) => { +// do not map modules in CI to catch any package install bugs (slower)... not in use ATM +const doNotMapPackages = process.env.JEST_SKIP_PACKAGE_MAP === 'true' + +/** + * Allows ts-jest to dynamically resolve packages so "build" + */ +const getJestModuleMap = (packageRoot = '../../', skipPackageMap = doNotMapPackages) => { + // get listing of packages in the mono repo const createLocation = (name) => { return `/./${name}/src/$1` @@ -12,7 +19,11 @@ const getJestModuleMap = (packageRoot) => { }), {} ) - return moduleNameMapper + + return { + '@/(.+)': '/../../src/$1', + ...(skipPackageMap ? {}: moduleNameMapper) + } } -module.exports = { getJestModuleMap } \ No newline at end of file +module.exports = { getJestModuleMap } diff --git a/packages/browser/jest.config.js b/packages/browser/jest.config.js index 8baecf944..2febbde05 100644 --- a/packages/browser/jest.config.js +++ b/packages/browser/jest.config.js @@ -1,3 +1,5 @@ +const { getJestModuleMap } = require('@internal/config') + module.exports = { preset: 'ts-jest', modulePathIgnorePatterns: [ @@ -11,9 +13,7 @@ module.exports = { testEnvironmentOptions: { resources: 'usable', }, - moduleNameMapper: { - '@/(.+)': '/../../src/$1', - }, + moduleNameMapper: getJestModuleMap(), setupFilesAfterEnv: ['./jest.setup.js'], globals: { 'ts-jest': { diff --git a/packages/browser/package.json b/packages/browser/package.json index 3fdb3083c..fc26947dd 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -60,6 +60,7 @@ "unfetch": "^4.1.0" }, "devDependencies": { + "@internal/config": "0.0.0", "@segment/inspector-webext": "^1.1.0", "@size-limit/preset-big-lib": "^7.0.8", "@types/flat": "^5.0.1", diff --git a/packages/core-integration-tests/jest.config.js b/packages/core-integration-tests/jest.config.js index a87c131f1..003230b98 100644 --- a/packages/core-integration-tests/jest.config.js +++ b/packages/core-integration-tests/jest.config.js @@ -1,7 +1,7 @@ const { getJestModuleMap } = require('@internal/config') module.exports = { - moduleNameMapper: getJestModuleMap("../../"), + moduleNameMapper: getJestModuleMap(), preset: 'ts-jest', modulePathIgnorePatterns: ['/dist/'], testEnvironment: 'node', diff --git a/packages/node/jest.config.js b/packages/node/jest.config.js index f3f0606c9..0355ec10b 100644 --- a/packages/node/jest.config.js +++ b/packages/node/jest.config.js @@ -7,7 +7,7 @@ module.exports = { testEnvironment: 'node', testMatch: ["**/?(*.)+(test).[jt]s?(x)"], clearMocks: true, - moduleNameMapper: getJestModuleMap("../../"), + moduleNameMapper: getJestModuleMap(), globals: { 'ts-jest': { isolatedModules: true, diff --git a/turbo.json b/turbo.json index 4b93374f4..35ad31a22 100644 --- a/turbo.json +++ b/turbo.json @@ -7,8 +7,6 @@ "outputs": ["dist/**", ".next/**"] }, "test": { - "dependsOn": ["build"], - "outputs": [], "inputs": ["src/**", "test*/**"] }, "watch": { diff --git a/yarn.lock b/yarn.lock index 5700b7677..da4c30b62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1523,6 +1523,7 @@ __metadata: version: 0.0.0-use.local resolution: "@segment/analytics-next@workspace:packages/browser" dependencies: + "@internal/config": 0.0.0 "@lukeed/uuid": ^2.0.0 "@segment/analytics-core": 1.0.1 "@segment/analytics.js-video-plugins": ^0.2.1