Skip to content

Commit 9486cff

Browse files
authored
simplify module mapper (#610)
1 parent df41afb commit 9486cff

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

internal/config/src/jest/get-module-map.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
const getPackages = require('get-monorepo-packages')
2-
2+
const path = require('path')
33
// do not map modules in CI to catch any package install bugs (slower)... not in use ATM
44
const doNotMapPackages = process.env.JEST_SKIP_PACKAGE_MAP === 'true'
55

66
/**
77
* Create module mapping that resolve packages for ts-jest so typescript compilation happens in-memory
8-
*
98
*/
109
const getJestModuleMap = ({ skipPackageMap = doNotMapPackages } = {}) => {
11-
// get listing of packages in the mono repo
12-
1310
/**
1411
* @param location - e.g. "packages/core"
1512
*/
16-
1713
const createPackageMappedPath = (location) => {
18-
// if packageRoot is the global jest file (using projects), our mappers suddenly need
19-
// to be relative to each project -- I have no idea why, seems unintuitive.
20-
// If not root config, equiv to running "yarn test" in an individual package repo (rootDir will be the root package.json)
21-
const moduleBasePath = global.JEST_ROOT_CONFIG
22-
? '<rootDir>/../..'
23-
: '<rootDir>'
24-
return `${moduleBasePath}/${location}/src/$1`
14+
const base = path.basename(location) // get base folder name of a package e.g. "core" or "browser"
15+
return `<rootDir>/../${base}/src/$1`
2516
}
17+
2618
// for the sake of getPackages working correctly during a project-wide test run, the working directory must be hardcoded to the root
2719
const packageRoot = global.JEST_ROOT_CONFIG ? '.' : '../../'
28-
const moduleNameMapper = getPackages(packageRoot).reduce(
20+
const packages = getPackages(packageRoot)
21+
const moduleNameMapper = packages.reduce(
2922
(acc, el) => ({
3023
...acc,
3124
[`${el.package.name}(.*)$`]: createPackageMappedPath(el.location),

0 commit comments

Comments
 (0)