Skip to content

Commit

Permalink
fix(config/jest): set ts-jest transform unconditionally
Browse files Browse the repository at this point in the history
No alternative is provided, so this would break things anyways unless
a dependent project provided its own transform. This unambiguously makes
`ts-jest` the default transform and project can always explicitly override
the transform in its `jest.config`
  • Loading branch information
jrolfs committed Feb 2, 2022
1 parent 5c08ac3 commit 2e9b18f
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 850 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -125,7 +125,6 @@
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.11",
"@types/cross-spawn": "^6.0.2",
"babel-jest": "^27.2.4",
"eslint-config-kentcdodds": "^20.0.1",
"husky": "^7.0.4",
"jest-in-case": "^1.0.2",
Expand Down
33 changes: 15 additions & 18 deletions src/config/jest.config.js
Expand Up @@ -2,7 +2,7 @@

const {jsWithTs: preset} = require('ts-jest/presets')

const {ifAnyDep, hasAnyDep, hasFile, fromRoot} = require('../utils')
const {ifAnyDep, hasFile, fromRoot} = require('../utils')

const {
testMatch,
Expand All @@ -29,6 +29,14 @@ const jestConfig = {
testMatch,
testPathIgnorePatterns: [...ignores, '<rootDir>/dist'],
testLocationInResults: true,
transform: Object.fromEntries(
// Ensure we can resolve the preset even when
// it's in a nested `node_modules` installation
Object.entries(preset.transform).map(([key, value]) => [
key,
require.resolve(value),
]),
),
coveragePathIgnorePatterns: [
...ignores,
'src/(umd|cjs|esm)-entry.js$',
Expand All @@ -51,24 +59,13 @@ const jestConfig = {
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
globals: {},
}

if (hasAnyDep('ts-jest') || hasFile('tsconfig.json')) {
jestConfig.transform = Object.fromEntries(
// Ensure we can resolve the preset even when
// it's in a nested `node_modules` installation
Object.entries(preset.transform).map(([key, value]) => [
key,
require.resolve(value),
]),
)

jestConfig.globals['ts-jest'] = {
diagnostics: {
warnOnly: true,
globals: {
'ts-jest': {
diagnostics: {
warnOnly: true,
},
},
}
},
}

if (hasFile('tests/setup-env.js')) {
Expand Down

0 comments on commit 2e9b18f

Please sign in to comment.