Skip to content

Commit

Permalink
simplify module mapper (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Oct 3, 2022
1 parent df41afb commit 9486cff
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions internal/config/src/jest/get-module-map.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
const getPackages = require('get-monorepo-packages')

const path = require('path')
// 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'

/**
* Create module mapping that resolve packages for ts-jest so typescript compilation happens in-memory
*
*/
const getJestModuleMap = ({ skipPackageMap = doNotMapPackages } = {}) => {
// get listing of packages in the mono repo

/**
* @param location - e.g. "packages/core"
*/

const createPackageMappedPath = (location) => {
// if packageRoot is the global jest file (using projects), our mappers suddenly need
// to be relative to each project -- I have no idea why, seems unintuitive.
// If not root config, equiv to running "yarn test" in an individual package repo (rootDir will be the root package.json)
const moduleBasePath = global.JEST_ROOT_CONFIG
? '<rootDir>/../..'
: '<rootDir>'
return `${moduleBasePath}/${location}/src/$1`
const base = path.basename(location) // get base folder name of a package e.g. "core" or "browser"
return `<rootDir>/../${base}/src/$1`
}

// for the sake of getPackages working correctly during a project-wide test run, the working directory must be hardcoded to the root
const packageRoot = global.JEST_ROOT_CONFIG ? '.' : '../../'
const moduleNameMapper = getPackages(packageRoot).reduce(
const packages = getPackages(packageRoot)
const moduleNameMapper = packages.reduce(
(acc, el) => ({
...acc,
[`${el.package.name}(.*)$`]: createPackageMappedPath(el.location),
Expand Down

0 comments on commit 9486cff

Please sign in to comment.