Skip to content

Commit

Permalink
add jest module map
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Sep 2, 2022
1 parent 7e3f3d6 commit 133da09
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
17 changes: 14 additions & 3 deletions internal/config/src/jest/index.js
Original file line number Diff line number Diff line change
@@ -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 = '../../') => {

// get listing of packages in the mono repo
const createLocation = (name) => {
return `<rootDir>/./${name}/src/$1`
Expand All @@ -12,7 +19,11 @@ const getJestModuleMap = (packageRoot) => {
}),
{}
)
return moduleNameMapper

return {
'@/(.+)': '<rootdir>/../../src/$1',
...(doNotMapPackages ? moduleNameMapper : {})
}
}

module.exports = { getJestModuleMap }
module.exports = { getJestModuleMap }
6 changes: 3 additions & 3 deletions packages/browser/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { getJestModuleMap } = require('@internal/config')

module.exports = {
preset: 'ts-jest',
modulePathIgnorePatterns: [
Expand All @@ -11,9 +13,7 @@ module.exports = {
testEnvironmentOptions: {
resources: 'usable',
},
moduleNameMapper: {
'@/(.+)': '<rootdir>/../../src/$1',
},
moduleNameMapper: getJestModuleMap(),
setupFilesAfterEnv: ['./jest.setup.js'],
globals: {
'ts-jest': {
Expand Down
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-integration-tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { getJestModuleMap } = require('@internal/config')

module.exports = {
moduleNameMapper: getJestModuleMap("../../"),
moduleNameMapper: getJestModuleMap(),
preset: 'ts-jest',
modulePathIgnorePatterns: ['<rootDir>/dist/'],
testEnvironment: 'node',
Expand Down
2 changes: 1 addition & 1 deletion packages/node/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
testEnvironment: 'node',
testMatch: ["**/?(*.)+(test).[jt]s?(x)"],
clearMocks: true,
moduleNameMapper: getJestModuleMap("../../"),
moduleNameMapper: getJestModuleMap(),
globals: {
'ts-jest': {
isolatedModules: true,
Expand Down
2 changes: 0 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"outputs": ["dist/**", ".next/**"]
},
"test": {
"dependsOn": ["build"],
"outputs": [],
"inputs": ["src/**", "test*/**"]
},
"watch": {
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 133da09

Please sign in to comment.