Skip to content

Commit 0badbb3

Browse files
committed
Revert "fix(config/jest): set ts-jest transform unconditionally"
This reverts commit 2e9b18f.
1 parent 2e9b18f commit 0badbb3

File tree

3 files changed

+850
-144
lines changed

3 files changed

+850
-144
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
"@babel/core": "^7.16.0",
126126
"@babel/preset-env": "^7.16.11",
127127
"@types/cross-spawn": "^6.0.2",
128+
"babel-jest": "^27.2.4",
128129
"eslint-config-kentcdodds": "^20.0.1",
129130
"husky": "^7.0.4",
130131
"jest-in-case": "^1.0.2",

src/config/jest.config.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

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

77
const {
88
testMatch,
@@ -29,14 +29,6 @@ const jestConfig = {
2929
testMatch,
3030
testPathIgnorePatterns: [...ignores, '<rootDir>/dist'],
3131
testLocationInResults: true,
32-
transform: Object.fromEntries(
33-
// Ensure we can resolve the preset even when
34-
// it's in a nested `node_modules` installation
35-
Object.entries(preset.transform).map(([key, value]) => [
36-
key,
37-
require.resolve(value),
38-
]),
39-
),
4032
coveragePathIgnorePatterns: [
4133
...ignores,
4234
'src/(umd|cjs|esm)-entry.js$',
@@ -59,13 +51,24 @@ const jestConfig = {
5951
require.resolve('jest-watch-typeahead/filename'),
6052
require.resolve('jest-watch-typeahead/testname'),
6153
],
62-
globals: {
63-
'ts-jest': {
64-
diagnostics: {
65-
warnOnly: true,
66-
},
54+
globals: {},
55+
}
56+
57+
if (hasAnyDep('ts-jest') || hasFile('tsconfig.json')) {
58+
jestConfig.transform = Object.fromEntries(
59+
// Ensure we can resolve the preset even when
60+
// it's in a nested `node_modules` installation
61+
Object.entries(preset.transform).map(([key, value]) => [
62+
key,
63+
require.resolve(value),
64+
]),
65+
)
66+
67+
jestConfig.globals['ts-jest'] = {
68+
diagnostics: {
69+
warnOnly: true,
6770
},
68-
},
71+
}
6972
}
7073

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

0 commit comments

Comments
 (0)