From 1538fa68e70192ce7ae57c36d8421394fe08738b Mon Sep 17 00:00:00 2001 From: Ahn Date: Sun, 18 Oct 2020 11:43:34 +0200 Subject: [PATCH] refactor(config): deprecate `packageJson` option (#2034) The option `packageJson` is not used in internal `ts-jest` so it makes sense to remove it. --- src/__helpers__/fakers.ts | 1 - .../__snapshots__/config-set.spec.ts.snap | 12 ---- src/config/config-set.spec.ts | 57 ++++++++----------- src/config/config-set.ts | 8 +-- src/types.ts | 10 ---- src/utils/messages.ts | 1 + 6 files changed, 30 insertions(+), 59 deletions(-) diff --git a/src/__helpers__/fakers.ts b/src/__helpers__/fakers.ts index 4ca88343d5..643b6e3fba 100644 --- a/src/__helpers__/fakers.ts +++ b/src/__helpers__/fakers.ts @@ -19,7 +19,6 @@ export function tsJestConfig(options?: Partial): TsJestConfig { transformers: options?.transformers ?? Object.create(null), babelConfig: undefined, tsConfig: undefined, - packageJson: undefined, stringifyContentPathRegex: undefined, diagnostics: { ignoreCodes: [], pretty: false, throws: true }, ...options, diff --git a/src/config/__snapshots__/config-set.spec.ts.snap b/src/config/__snapshots__/config-set.spec.ts.snap index b0fb0f4a90..52869a2d13 100644 --- a/src/config/__snapshots__/config-set.spec.ts.snap +++ b/src/config/__snapshots__/config-set.spec.ts.snap @@ -214,10 +214,6 @@ Object { "throws": true, }, "isolatedModules": false, - "packageJson": Object { - "kind": "file", - "value": undefined, - }, "stringifyContentPathRegex": undefined, "transformers": Object {}, "tsConfig": Object { @@ -241,10 +237,6 @@ Object { "throws": true, }, "isolatedModules": false, - "packageJson": Object { - "kind": "file", - "value": undefined, - }, "stringifyContentPathRegex": undefined, "transformers": Object {}, "tsConfig": Object { @@ -268,10 +260,6 @@ Object { "throws": true, }, "isolatedModules": false, - "packageJson": Object { - "kind": "file", - "value": undefined, - }, "stringifyContentPathRegex": undefined, "transformers": Object {}, "tsConfig": Object { diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index ede51a28bc..5dcc28ecbb 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -1,12 +1,12 @@ /* eslint-disable jest/no-mocks-import */ import type { Transformer } from '@jest/transform' -import { testing } from 'bs-logger' +import { LogLevels, testing } from 'bs-logger' import { join, resolve } from 'path' import ts from 'typescript' import { logTargetMock } from '../__helpers__/mocks' -import { createConfigSet, defaultResolve } from '../__helpers__/fakers' -import type { TsJestGlobalOptions } from '../types' +import { createConfigSet } from '../__helpers__/fakers' +import type { TsJestGlobalOptions, TsJestConfig } from '../types' import * as _backports from '../utils/backports' import { getPackageVersion } from '../utils/get-package-version' import { normalizeSlashes } from '../utils/normalize-slashes' @@ -151,40 +151,33 @@ describe('tsJest', () => { }) describe('packageJson', () => { - it('should be correct when packageJson is true', () => { - const EXPECTED = { - kind: 'file', - value: undefined, - } - expect(getTsJest().packageJson).toEqual(EXPECTED) - expect(getTsJest({ packageJson: true }).packageJson).toEqual(EXPECTED) - }) + const logger = testing.createLoggerMock() + let tsJestCfg: TsJestConfig - it('should be correct for given file as string', () => { - const FILE = 'bar/tsconfig.foo.json' - const EXPECTED = { - kind: 'file', - value: defaultResolve(FILE), - } - expect(getTsJest({ packageJson: FILE }).packageJson).toEqual(EXPECTED) + beforeEach(() => { + logger.target.clear() + tsJestCfg = createConfigSet({ + jestConfig: { + globals: { + 'ts-jest': { + packageJson: true, + }, + }, + } as any, + logger, + resolve: null, + }).tsJest }) - it('should be correct for given file as an object', () => { - const packageJsonStub = require('../__mocks__/package-foo.json') - const EXPECTED = { - kind: 'inline', - value: packageJsonStub, - } - expect(getTsJest({ packageJson: packageJsonStub }).packageJson).toEqual(EXPECTED) + it('should not contain packageJson in final tsJest config', () => { + expect(Object.keys(tsJestCfg)).not.toContain('packageJson') }) - it('should be correct for inline config', () => { - const CONFIG = { foo: 'bar' } - const EXPECTED = { - kind: 'inline', - value: CONFIG, - } - expect(getTsJest({ packageJson: CONFIG as any }).packageJson).toEqual(EXPECTED) + it('should show warning message when packageJson is provided', () => { + expect(logger.target.filteredLines(LogLevels.warn)[0]).toMatchInlineSnapshot(` + "[level:40] The option \`packageJson\` is deprecated and will be removed in ts-jest 27. This option is not used by internal \`ts-jest\` + " + `) }) }) diff --git a/src/config/config-set.ts b/src/config/config-set.ts index dbbecb65c0..dcc6407de8 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -197,9 +197,6 @@ export class ConfigSet { options.tsConfig ?? options.tsconfig ?? true, ) - // packageJson - const packageJson: TsJestConfig['packageJson'] = this.getInlineOrFileConfigOpt(options.packageJson ?? true) - // transformers let transformers: ConfigCustomTransformer = Object.create(null) const { astTransformers } = options @@ -260,6 +257,10 @@ export class ConfigSet { } } + if (options.packageJson) { + this.logger.warn(Deprecations.PackageJson) + } + // babel config (for babel-jest) default is undefined so we don't need to have fallback like tsConfig or packageJson const babelConfig: TsJestConfig['babelConfig'] = this.getInlineOrFileConfigOpt(options.babelConfig) @@ -290,7 +291,6 @@ export class ConfigSet { // parsed options const res: TsJestConfig = { tsConfig, - packageJson, babelConfig, diagnostics, isolatedModules: !!options.isolatedModules, diff --git a/src/types.ts b/src/types.ts index f08c045440..85bdf95d49 100644 --- a/src/types.ts +++ b/src/types.ts @@ -172,22 +172,12 @@ interface TsJestConfig$babelConfig$inline { value: BabelConfig } type TsJestConfig$babelConfig = TsJestConfig$babelConfig$file | TsJestConfig$babelConfig$inline | undefined -interface TsJestConfig$packageJson$file { - kind: 'file' - value: string | undefined -} -interface TsJestConfig$packageJson$inline { - kind: 'inline' - value: any -} -type TsJestConfig$packageJson = TsJestConfig$packageJson$file | TsJestConfig$packageJson$inline | undefined type TsJestConfig$stringifyContentPathRegex = string | undefined /** * @internal */ export interface TsJestConfig { tsConfig: TsJestConfig$tsConfig - packageJson: TsJestConfig$packageJson isolatedModules: boolean compiler: string diagnostics: TsJestConfig$diagnostics diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 7b18af0da7..a699df89d4 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -39,6 +39,7 @@ export const enum Deprecations { HelperMovedToUtils = "The `{{helper}}` helper has been moved to `ts-jest/utils`. Use `import { {{helper}} } from 'ts-jest/utils'` instead.", 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', TsConfig = 'The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead', + PackageJson = 'The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`', } /**