diff --git a/internal/config/src/jest/index.js b/internal/config/src/jest/index.js index 3e8707a1b..69e5cf5fd 100644 --- a/internal/config/src/jest/index.js +++ b/internal/config/src/jest/index.js @@ -1,6 +1,12 @@ const getPackages = require('get-monorepo-packages') -const getJestModuleMap = (packageRoot) => { +const doNotMapPackages = process.env.CI === 'true' // do not map modules in CI to catch any package install bugs (slower) + +/** + * Allows ts-jest to dynamically resolve packages so "build" + */ +const getJestModuleMap = (packageRoot = '../../') => { + // get listing of packages in the mono repo const createLocation = (name) => { return `/./${name}/src/$1` @@ -12,7 +18,11 @@ const getJestModuleMap = (packageRoot) => { }), {} ) - return moduleNameMapper + + return { + '@/(.+)': '/../../src/$1', + ...(doNotMapPackages ? 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