Skip to content

Commit

Permalink
use createJestConfig fn
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Sep 3, 2022
1 parent 25bd37a commit 081045b
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 92 deletions.
4 changes: 2 additions & 2 deletions internal/config/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
getJestModuleMap: require("./jest").getJestModuleMap
}
createJestTSConfig: require('./jest/config').createJestTSConfig,
}
34 changes: 34 additions & 0 deletions internal/config/src/jest/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { getJestModuleMap } = require('./get-module-map')

/**
* Create Config
* @param {import('jest').Config} Overrides.
* @param {object} getJestModuleMap options.
* @returns {import('jest').Config}
*/
const createJestTSConfig = (
{ modulePathIgnorePatterns, testMatch, ...overridesToMerge } = {},
{ packageRoot, skipPackageMap } = {}
) => {
return {
moduleNameMapper: getJestModuleMap(packageRoot, skipPackageMap),
preset: 'ts-jest',
modulePathIgnorePatterns: [
'<rootDir>/dist/',
...(modulePathIgnorePatterns || []),
],
testEnvironment: 'node',
testMatch: ['**/?(*.)+(test).[jt]s?(x)', ...(testMatch || [])],
clearMocks: true,
globals: {
'ts-jest': {
isolatedModules: true,
},
},
...(overridesToMerge || {}),
}
}

module.exports = {
createJestTSConfig,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const doNotMapPackages = process.env.JEST_SKIP_PACKAGE_MAP === 'true'
/**
* Allows ts-jest to dynamically resolve packages so "build"
*/
const getJestModuleMap = (packageRoot = '../../', skipPackageMap = doNotMapPackages) => {

const getJestModuleMap = (
packageRoot = '../../',
skipPackageMap = doNotMapPackages
) => {
// get listing of packages in the mono repo
const createLocation = (name) => {
return `<rootDir>/./${name}/src/$1`
Expand All @@ -22,7 +24,7 @@ const getJestModuleMap = (packageRoot = '../../', skipPackageMap = doNotMapPacka

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

Expand Down
27 changes: 5 additions & 22 deletions packages/browser/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
const { getJestModuleMap } = require('@internal/config')
const { createJestTSConfig } = require('@internal/config')

module.exports = {
preset: 'ts-jest',
modulePathIgnorePatterns: [
'<rootDir>/dist/',
'<rootDir>/e2e-tests',
'<rootDir>/qa',
],
testEnvironment: 'jsdom',
testMatch: ["**/?(*.)+(test).[jt]s?(x)"],
clearMocks: true,
testEnvironmentOptions: {
resources: 'usable',
},
moduleNameMapper: getJestModuleMap(),
module.exports = createJestTSConfig({
modulePathIgnorePatterns: ['<rootDir>/e2e-tests', '<rootDir>/qa'],
setupFilesAfterEnv: ['./jest.setup.js'],
globals: {
'ts-jest': {
isolatedModules: true,
},
},
reporters: ['default'],
testEnvironment: 'jsdom',
coverageThreshold: {
global: {
branches: 80.91,
Expand All @@ -29,4 +12,4 @@ module.exports = {
statements: 87.25,
},
},
}
})
16 changes: 2 additions & 14 deletions packages/core-integration-tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
const { getJestModuleMap } = require('@internal/config')
const { createJestTSConfig } = require('@internal/config')

module.exports = {
moduleNameMapper: getJestModuleMap(),
preset: 'ts-jest',
modulePathIgnorePatterns: ['<rootDir>/dist/'],
testEnvironment: 'node',
testMatch: ['**/?(*.)+(test).[jt]s?(x)'],
clearMocks: true,
globals: {
'ts-jest': {
isolatedModules: true,
},
},
}
module.exports = createJestTSConfig()
24 changes: 5 additions & 19 deletions packages/core/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
module.exports = {
preset: 'ts-jest',
modulePathIgnorePatterns: [
'<rootDir>/dist/',
],
testEnvironment: 'node',
testMatch: ["**/?(*.)+(test).[jt]s?(x)"],
clearMocks: true,
setupFilesAfterEnv: ['./jest.setup.js'],
projects: [
"<rootDir>",
"<rootDir>/../core-integration-tests"
],
globals: {
'ts-jest': {
isolatedModules: true,
},
},
}
const { createJestTSConfig } = require('@internal/config')

module.exports = createJestTSConfig({
projects: ['<rootDir>', '<rootDir>/../core-integration-tests'],
})
19 changes: 3 additions & 16 deletions packages/node/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
const { getJestModuleMap } = require("@internal/config")
module.exports = {
preset: 'ts-jest',
modulePathIgnorePatterns: [
'<rootDir>/dist/',
],
testEnvironment: 'node',
testMatch: ["**/?(*.)+(test).[jt]s?(x)"],
clearMocks: true,
moduleNameMapper: getJestModuleMap(),
globals: {
'ts-jest': {
isolatedModules: true,
},
},
}
const { createJestTSConfig } = require('@internal/config')

module.exports = createJestTSConfig()
18 changes: 2 additions & 16 deletions packages/plugin-validation/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
const { getJestModuleMap } = require('@internal/config')
const { createJestTSConfig } = require('@internal/config')

module.exports = {
moduleNameMapper: getJestModuleMap(),
preset: 'ts-jest',
modulePathIgnorePatterns: [
'<rootDir>/dist/',
],
testEnvironment: 'node',
testMatch: ["**/?(*.)+(test).[jt]s?(x)"],
clearMocks: true,
globals: {
'ts-jest': {
isolatedModules: true,
},
},
}
module.exports = createJestTSConfig()

0 comments on commit 081045b

Please sign in to comment.