Skip to content

Commit 781710b

Browse files
authored
fix(cli): add migration tsConfig option for ts-jest config options (#2794)
Closes #2764
1 parent 5d6e514 commit 781710b

7 files changed

Lines changed: 54 additions & 12 deletions

File tree

src/config/config-set.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('parsedTsConfig', () => {
5151
})
5252

5353
it('should fallback to ES2015 as default target and CommonJS as default module when no target or module defined in tsconfig', () => {
54-
const compilerOptions = get({ tsconfig: 'tsconfig.spec.json' }).options
54+
const compilerOptions = get({ tsconfig: 'src/__mocks__/tsconfig-mocks.json' }).options
5555

5656
expect(compilerOptions.target).toBe(ts.ScriptTarget.ES2015)
5757
expect(compilerOptions.module).toBe(ts.ModuleKind.CommonJS)

src/utils/__snapshots__/backports.spec.ts.snap

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,35 @@ Array [
233233
]
234234
`;
235235
236+
exports[`backportJestConfig with "globals.ts-jest.tsConfig" set to 'tsconfig.build.json' should have changed the config correctly: before 1`] = `
237+
Object {
238+
"globals": Object {
239+
"ts-jest": Object {
240+
"tsConfig": "tsconfig.build.json",
241+
},
242+
},
243+
}
244+
`;
245+
246+
exports[`backportJestConfig with "globals.ts-jest.tsConfig" set to 'tsconfig.build.json' should have changed the config correctly: migrated 1`] = `
247+
Object {
248+
"globals": Object {
249+
"ts-jest": Object {
250+
"tsconfig": "tsconfig.build.json",
251+
},
252+
},
253+
}
254+
`;
255+
256+
exports[`backportJestConfig with "globals.ts-jest.tsConfig" set to 'tsconfig.build.json' should warn the user 1`] = `
257+
Array [
258+
"[level:40] \\"[jest-config].globals.ts-jest.tsConfig\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsconfig\\" instead.
259+
",
260+
"[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate <config-file>.
261+
",
262+
]
263+
`;
264+
236265
exports[`backportJestConfig with "globals.ts-jest.tsConfigFile" set to 'tsconfig.build.json' should have changed the config correctly: before 1`] = `
237266
Object {
238267
"globals": Object {

src/utils/backports.spec.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { inspect } from 'util'
22

33
import { testing } from 'bs-logger'
4-
import set = require('lodash/set')
4+
import set from 'lodash/set'
55

66
import { backportJestConfig } from './backports'
77

@@ -13,20 +13,23 @@ beforeEach(() => {
1313
})
1414

1515
describe('backportJestConfig', () => {
16-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17-
const makeTestsFor = (oldPath: string, _: string, values: any[]) => {
16+
const makeTestsFor = (oldPath: string, values: unknown[]) => {
1817
values.forEach((val) => {
1918
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2019
let original: any
20+
2121
beforeEach(() => {
2222
original = {}
2323
set(original, oldPath, val)
2424
})
25+
2526
describe(`with "${oldPath}" set to ${inspect(val)}`, () => {
2627
it('should warn the user', () => {
2728
backportJestConfig(logger, original)
29+
2830
expect(logTarget.lines.warn).toMatchSnapshot()
2931
}) // should warn the user
32+
3033
it('should have changed the config correctly', () => {
3134
expect(original).toMatchSnapshot('before')
3235
expect(backportJestConfig(logger, original)).toMatchSnapshot('migrated')
@@ -35,17 +38,19 @@ describe('backportJestConfig', () => {
3538
}) // for
3639
} // makeTestsFor
3740

38-
makeTestsFor('globals.__TS_CONFIG__', 'globals.ts-jest.tsConfig', [{ foo: 'bar' }])
41+
makeTestsFor('globals.__TS_CONFIG__', [{ foo: 'bar' }])
42+
43+
makeTestsFor('globals.__TRANSFORM_HTML__', [true, false])
3944

40-
makeTestsFor('globals.__TRANSFORM_HTML__', 'globals.ts-jest.stringifyContentPathRegex', [true, false])
45+
makeTestsFor('globals.ts-jest.tsConfigFile', ['tsconfig.build.json'])
4146

42-
makeTestsFor('globals.ts-jest.tsConfigFile', 'globals.ts-jest.tsConfig', ['tsconfig.build.json'])
47+
makeTestsFor('globals.ts-jest.tsConfig', ['tsconfig.build.json'])
4348

44-
makeTestsFor('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics', [true, false, '\\.spec\\.ts$'])
49+
makeTestsFor('globals.ts-jest.enableTsDiagnostics', [true, false, '\\.spec\\.ts$'])
4550

46-
makeTestsFor('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', [true, false])
51+
makeTestsFor('globals.ts-jest.useBabelrc', [true, false])
4752

48-
makeTestsFor('globals.ts-jest.typeCheck', 'globals.ts-jest.isolatedModules', [true, false])
53+
makeTestsFor('globals.ts-jest.typeCheck', [true, false])
4954

50-
makeTestsFor('globals.ts-jest.skipBabel', 'globals.ts-jest.babelConfig', [true, false])
55+
makeTestsFor('globals.ts-jest.skipBabel', [true, false])
5156
})

src/utils/backports.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ export const backportJestConfig = <T extends Config.InitialOptions | Config.Proj
6262
delete tsJest.tsConfigFile
6363
}
6464

65+
if ('tsConfig' in tsJest) {
66+
warnConfig('globals.ts-jest.tsConfig', 'globals.ts-jest.tsconfig')
67+
if (tsJest.tsConfig) {
68+
mergeTsJest.tsconfig = tsJest.tsConfig
69+
}
70+
delete tsJest.tsConfig
71+
}
72+
6573
if ('enableTsDiagnostics' in tsJest) {
6674
warnConfig('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics')
6775
if (tsJest.enableTsDiagnostics) {

tsconfig.build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"target": "ES5",
54
"sourceMap": false,
65
"inlineSources": false,
76
"inlineSourceMap": false,

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"module": "CommonJS",
4+
"target": "ES5",
45
"declaration": false,
56
"noEmit": true,
67
"downlevelIteration": true,

0 commit comments

Comments
 (0)