|
1 | 1 | const getPackages = require('get-monorepo-packages')
|
2 |
| - |
| 2 | +const path = require('path') |
3 | 3 | // do not map modules in CI to catch any package install bugs (slower)... not in use ATM
|
4 | 4 | const doNotMapPackages = process.env.JEST_SKIP_PACKAGE_MAP === 'true'
|
5 | 5 |
|
6 | 6 | /**
|
7 | 7 | * Create module mapping that resolve packages for ts-jest so typescript compilation happens in-memory
|
8 |
| - * |
9 | 8 | */
|
10 | 9 | const getJestModuleMap = ({ skipPackageMap = doNotMapPackages } = {}) => {
|
11 |
| - // get listing of packages in the mono repo |
12 |
| - |
13 | 10 | /**
|
14 | 11 | * @param location - e.g. "packages/core"
|
15 | 12 | */
|
16 |
| - |
17 | 13 | 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` |
25 | 16 | }
|
| 17 | + |
26 | 18 | // for the sake of getPackages working correctly during a project-wide test run, the working directory must be hardcoded to the root
|
27 | 19 | const packageRoot = global.JEST_ROOT_CONFIG ? '.' : '../../'
|
28 |
| - const moduleNameMapper = getPackages(packageRoot).reduce( |
| 20 | + const packages = getPackages(packageRoot) |
| 21 | + const moduleNameMapper = packages.reduce( |
29 | 22 | (acc, el) => ({
|
30 | 23 | ...acc,
|
31 | 24 | [`${el.package.name}(.*)$`]: createPackageMappedPath(el.location),
|
|
0 commit comments