diff --git a/internal/config/src/index.js b/internal/config/src/index.js index 6c2956e1d..4bb061c44 100644 --- a/internal/config/src/index.js +++ b/internal/config/src/index.js @@ -1,3 +1,3 @@ module.exports = { - getJestModuleMap: require("./jest").getJestModuleMap -} \ No newline at end of file + createJestConfig: require('./jest/config').createJestConfig, +} diff --git a/internal/config/src/jest/config.js b/internal/config/src/jest/config.js new file mode 100644 index 000000000..35d9a78f9 --- /dev/null +++ b/internal/config/src/jest/config.js @@ -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 createJestConfig = ( + { modulePathIgnorePatterns, testMatch, ...overridesToMerge } = {}, + { packageRoot, skipPackageMap } = {} +) => { + return { + moduleNameMapper: getJestModuleMap(packageRoot, skipPackageMap), + preset: 'ts-jest', + modulePathIgnorePatterns: [ + '/dist/', + ...(modulePathIgnorePatterns || []), + ], + testEnvironment: 'node', + testMatch: ['**/?(*.)+(test).[jt]s?(x)', ...(testMatch || [])], + clearMocks: true, + globals: { + 'ts-jest': { + isolatedModules: true, + }, + }, + ...(overridesToMerge || {}), + } +} + +module.exports = { + createJestConfig, +} diff --git a/internal/config/src/jest/index.js b/internal/config/src/jest/get-module-map.js similarity index 82% rename from internal/config/src/jest/index.js rename to internal/config/src/jest/get-module-map.js index a3a36a19d..68eeb4feb 100644 --- a/internal/config/src/jest/index.js +++ b/internal/config/src/jest/get-module-map.js @@ -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 `/./${name}/src/$1` @@ -22,7 +24,7 @@ const getJestModuleMap = (packageRoot = '../../', skipPackageMap = doNotMapPacka return { '@/(.+)': '/../../src/$1', - ...(skipPackageMap ? {}: moduleNameMapper) + ...(skipPackageMap ? {} : moduleNameMapper), } } diff --git a/packages/browser/jest.config.js b/packages/browser/jest.config.js index 2febbde05..a722334c6 100644 --- a/packages/browser/jest.config.js +++ b/packages/browser/jest.config.js @@ -1,26 +1,9 @@ -const { getJestModuleMap } = require('@internal/config') +const { createJestConfig } = require('@internal/config') -module.exports = { - preset: 'ts-jest', - modulePathIgnorePatterns: [ - '/dist/', - '/e2e-tests', - '/qa', - ], - testEnvironment: 'jsdom', - testMatch: ["**/?(*.)+(test).[jt]s?(x)"], - clearMocks: true, - testEnvironmentOptions: { - resources: 'usable', - }, - moduleNameMapper: getJestModuleMap(), +module.exports = createJestConfig({ + modulePathIgnorePatterns: ['/e2e-tests', '/qa'], setupFilesAfterEnv: ['./jest.setup.js'], - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, - reporters: ['default'], + testEnvironment: 'jsdom', coverageThreshold: { global: { branches: 80.91, @@ -29,4 +12,4 @@ module.exports = { statements: 87.25, }, }, -} +}) diff --git a/packages/core-integration-tests/jest.config.js b/packages/core-integration-tests/jest.config.js index 003230b98..a3d00f10d 100644 --- a/packages/core-integration-tests/jest.config.js +++ b/packages/core-integration-tests/jest.config.js @@ -1,15 +1,3 @@ -const { getJestModuleMap } = require('@internal/config') +const { createJestConfig } = require('@internal/config') -module.exports = { - moduleNameMapper: getJestModuleMap(), - preset: 'ts-jest', - modulePathIgnorePatterns: ['/dist/'], - testEnvironment: 'node', - testMatch: ['**/?(*.)+(test).[jt]s?(x)'], - clearMocks: true, - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, -} +module.exports = createJestConfig() diff --git a/packages/core/jest.config.js b/packages/core/jest.config.js index 4269edca0..46f464e25 100644 --- a/packages/core/jest.config.js +++ b/packages/core/jest.config.js @@ -1,19 +1,5 @@ -module.exports = { - preset: 'ts-jest', - modulePathIgnorePatterns: [ - '/dist/', - ], - testEnvironment: 'node', - testMatch: ["**/?(*.)+(test).[jt]s?(x)"], - clearMocks: true, - setupFilesAfterEnv: ['./jest.setup.js'], - projects: [ - "", - "/../core-integration-tests" - ], - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, -} +const { createJestConfig } = require('@internal/config') + +module.exports = createJestConfig({ + projects: ['', '/../core-integration-tests'], +}) diff --git a/packages/node/jest.config.js b/packages/node/jest.config.js index 0355ec10b..a3d00f10d 100644 --- a/packages/node/jest.config.js +++ b/packages/node/jest.config.js @@ -1,16 +1,3 @@ -const { getJestModuleMap } = require("@internal/config") -module.exports = { - preset: 'ts-jest', - modulePathIgnorePatterns: [ - '/dist/', - ], - testEnvironment: 'node', - testMatch: ["**/?(*.)+(test).[jt]s?(x)"], - clearMocks: true, - moduleNameMapper: getJestModuleMap(), - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, -} +const { createJestConfig } = require('@internal/config') + +module.exports = createJestConfig() diff --git a/packages/plugin-validation/jest.config.js b/packages/plugin-validation/jest.config.js index de97b86e0..a3d00f10d 100644 --- a/packages/plugin-validation/jest.config.js +++ b/packages/plugin-validation/jest.config.js @@ -1,17 +1,3 @@ -const { getJestModuleMap } = require('@internal/config') +const { createJestConfig } = require('@internal/config') -module.exports = { - moduleNameMapper: getJestModuleMap(), - preset: 'ts-jest', - modulePathIgnorePatterns: [ - '/dist/', - ], - testEnvironment: 'node', - testMatch: ["**/?(*.)+(test).[jt]s?(x)"], - clearMocks: true, - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, -} +module.exports = createJestConfig()