Skip to content

Commit 1538fa6

Browse files
authored
refactor(config): deprecate packageJson option (#2034)
The option `packageJson` is not used in internal `ts-jest` so it makes sense to remove it.
1 parent 2bb4430 commit 1538fa6

6 files changed

Lines changed: 30 additions & 59 deletions

File tree

src/__helpers__/fakers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export function tsJestConfig(options?: Partial<TsJestConfig>): TsJestConfig {
1919
transformers: options?.transformers ?? Object.create(null),
2020
babelConfig: undefined,
2121
tsConfig: undefined,
22-
packageJson: undefined,
2322
stringifyContentPathRegex: undefined,
2423
diagnostics: { ignoreCodes: [], pretty: false, throws: true },
2524
...options,

src/config/__snapshots__/config-set.spec.ts.snap

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,6 @@ Object {
214214
"throws": true,
215215
},
216216
"isolatedModules": false,
217-
"packageJson": Object {
218-
"kind": "file",
219-
"value": undefined,
220-
},
221217
"stringifyContentPathRegex": undefined,
222218
"transformers": Object {},
223219
"tsConfig": Object {
@@ -241,10 +237,6 @@ Object {
241237
"throws": true,
242238
},
243239
"isolatedModules": false,
244-
"packageJson": Object {
245-
"kind": "file",
246-
"value": undefined,
247-
},
248240
"stringifyContentPathRegex": undefined,
249241
"transformers": Object {},
250242
"tsConfig": Object {
@@ -268,10 +260,6 @@ Object {
268260
"throws": true,
269261
},
270262
"isolatedModules": false,
271-
"packageJson": Object {
272-
"kind": "file",
273-
"value": undefined,
274-
},
275263
"stringifyContentPathRegex": undefined,
276264
"transformers": Object {},
277265
"tsConfig": Object {

src/config/config-set.spec.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-disable jest/no-mocks-import */
22
import type { Transformer } from '@jest/transform'
3-
import { testing } from 'bs-logger'
3+
import { LogLevels, testing } from 'bs-logger'
44
import { join, resolve } from 'path'
55
import ts from 'typescript'
66

77
import { logTargetMock } from '../__helpers__/mocks'
8-
import { createConfigSet, defaultResolve } from '../__helpers__/fakers'
9-
import type { TsJestGlobalOptions } from '../types'
8+
import { createConfigSet } from '../__helpers__/fakers'
9+
import type { TsJestGlobalOptions, TsJestConfig } from '../types'
1010
import * as _backports from '../utils/backports'
1111
import { getPackageVersion } from '../utils/get-package-version'
1212
import { normalizeSlashes } from '../utils/normalize-slashes'
@@ -151,40 +151,33 @@ describe('tsJest', () => {
151151
})
152152

153153
describe('packageJson', () => {
154-
it('should be correct when packageJson is true', () => {
155-
const EXPECTED = {
156-
kind: 'file',
157-
value: undefined,
158-
}
159-
expect(getTsJest().packageJson).toEqual(EXPECTED)
160-
expect(getTsJest({ packageJson: true }).packageJson).toEqual(EXPECTED)
161-
})
154+
const logger = testing.createLoggerMock()
155+
let tsJestCfg: TsJestConfig
162156

163-
it('should be correct for given file as string', () => {
164-
const FILE = 'bar/tsconfig.foo.json'
165-
const EXPECTED = {
166-
kind: 'file',
167-
value: defaultResolve(FILE),
168-
}
169-
expect(getTsJest({ packageJson: FILE }).packageJson).toEqual(EXPECTED)
157+
beforeEach(() => {
158+
logger.target.clear()
159+
tsJestCfg = createConfigSet({
160+
jestConfig: {
161+
globals: {
162+
'ts-jest': {
163+
packageJson: true,
164+
},
165+
},
166+
} as any,
167+
logger,
168+
resolve: null,
169+
}).tsJest
170170
})
171171

172-
it('should be correct for given file as an object', () => {
173-
const packageJsonStub = require('../__mocks__/package-foo.json')
174-
const EXPECTED = {
175-
kind: 'inline',
176-
value: packageJsonStub,
177-
}
178-
expect(getTsJest({ packageJson: packageJsonStub }).packageJson).toEqual(EXPECTED)
172+
it('should not contain packageJson in final tsJest config', () => {
173+
expect(Object.keys(tsJestCfg)).not.toContain('packageJson')
179174
})
180175

181-
it('should be correct for inline config', () => {
182-
const CONFIG = { foo: 'bar' }
183-
const EXPECTED = {
184-
kind: 'inline',
185-
value: CONFIG,
186-
}
187-
expect(getTsJest({ packageJson: CONFIG as any }).packageJson).toEqual(EXPECTED)
176+
it('should show warning message when packageJson is provided', () => {
177+
expect(logger.target.filteredLines(LogLevels.warn)[0]).toMatchInlineSnapshot(`
178+
"[level:40] The option \`packageJson\` is deprecated and will be removed in ts-jest 27. This option is not used by internal \`ts-jest\`
179+
"
180+
`)
188181
})
189182
})
190183

src/config/config-set.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ export class ConfigSet {
197197
options.tsConfig ?? options.tsconfig ?? true,
198198
)
199199

200-
// packageJson
201-
const packageJson: TsJestConfig['packageJson'] = this.getInlineOrFileConfigOpt(options.packageJson ?? true)
202-
203200
// transformers
204201
let transformers: ConfigCustomTransformer = Object.create(null)
205202
const { astTransformers } = options
@@ -260,6 +257,10 @@ export class ConfigSet {
260257
}
261258
}
262259

260+
if (options.packageJson) {
261+
this.logger.warn(Deprecations.PackageJson)
262+
}
263+
263264
// babel config (for babel-jest) default is undefined so we don't need to have fallback like tsConfig or packageJson
264265
const babelConfig: TsJestConfig['babelConfig'] = this.getInlineOrFileConfigOpt(options.babelConfig)
265266

@@ -290,7 +291,6 @@ export class ConfigSet {
290291
// parsed options
291292
const res: TsJestConfig = {
292293
tsConfig,
293-
packageJson,
294294
babelConfig,
295295
diagnostics,
296296
isolatedModules: !!options.isolatedModules,

src/types.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,12 @@ interface TsJestConfig$babelConfig$inline {
172172
value: BabelConfig
173173
}
174174
type TsJestConfig$babelConfig = TsJestConfig$babelConfig$file | TsJestConfig$babelConfig$inline | undefined
175-
interface TsJestConfig$packageJson$file {
176-
kind: 'file'
177-
value: string | undefined
178-
}
179-
interface TsJestConfig$packageJson$inline {
180-
kind: 'inline'
181-
value: any
182-
}
183-
type TsJestConfig$packageJson = TsJestConfig$packageJson$file | TsJestConfig$packageJson$inline | undefined
184175
type TsJestConfig$stringifyContentPathRegex = string | undefined
185176
/**
186177
* @internal
187178
*/
188179
export interface TsJestConfig {
189180
tsConfig: TsJestConfig$tsConfig
190-
packageJson: TsJestConfig$packageJson
191181
isolatedModules: boolean
192182
compiler: string
193183
diagnostics: TsJestConfig$diagnostics

src/utils/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const enum Deprecations {
3939
HelperMovedToUtils = "The `{{helper}}` helper has been moved to `ts-jest/utils`. Use `import { {{helper}} } from 'ts-jest/utils'` instead.",
4040
AstTransformerArrayConfig = 'The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers',
4141
TsConfig = 'The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead',
42+
PackageJson = 'The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`',
4243
}
4344

4445
/**

0 commit comments

Comments
 (0)