Skip to content

Commit

Permalink
refactor(config): deprecate packageJson option (#2034)
Browse files Browse the repository at this point in the history
The option `packageJson` is not used in internal `ts-jest` so it makes sense to remove it.
  • Loading branch information
ahnpnl committed Oct 18, 2020
1 parent 2bb4430 commit 1538fa6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 59 deletions.
1 change: 0 additions & 1 deletion src/__helpers__/fakers.ts
Expand Up @@ -19,7 +19,6 @@ export function tsJestConfig(options?: Partial<TsJestConfig>): TsJestConfig {
transformers: options?.transformers ?? Object.create(null),
babelConfig: undefined,
tsConfig: undefined,
packageJson: undefined,
stringifyContentPathRegex: undefined,
diagnostics: { ignoreCodes: [], pretty: false, throws: true },
...options,
Expand Down
12 changes: 0 additions & 12 deletions src/config/__snapshots__/config-set.spec.ts.snap
Expand Up @@ -214,10 +214,6 @@ Object {
"throws": true,
},
"isolatedModules": false,
"packageJson": Object {
"kind": "file",
"value": undefined,
},
"stringifyContentPathRegex": undefined,
"transformers": Object {},
"tsConfig": Object {
Expand All @@ -241,10 +237,6 @@ Object {
"throws": true,
},
"isolatedModules": false,
"packageJson": Object {
"kind": "file",
"value": undefined,
},
"stringifyContentPathRegex": undefined,
"transformers": Object {},
"tsConfig": Object {
Expand All @@ -268,10 +260,6 @@ Object {
"throws": true,
},
"isolatedModules": false,
"packageJson": Object {
"kind": "file",
"value": undefined,
},
"stringifyContentPathRegex": undefined,
"transformers": Object {},
"tsConfig": Object {
Expand Down
57 changes: 25 additions & 32 deletions 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'
Expand Down Expand Up @@ -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\`
"
`)
})
})

Expand Down
8 changes: 4 additions & 4 deletions src/config/config-set.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -290,7 +291,6 @@ export class ConfigSet {
// parsed options
const res: TsJestConfig = {
tsConfig,
packageJson,
babelConfig,
diagnostics,
isolatedModules: !!options.isolatedModules,
Expand Down
10 changes: 0 additions & 10 deletions src/types.ts
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/utils/messages.ts
Expand Up @@ -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`',
}

/**
Expand Down

0 comments on commit 1538fa6

Please sign in to comment.