From 05916b920160da5b43a20b47025eea43b4a1a5c3 Mon Sep 17 00:00:00 2001 From: Ahn Date: Wed, 11 Nov 2020 09:35:12 +0100 Subject: [PATCH] refactor(config): remove support for `packageJson` option (#2128) BREAKING CHANGE: `packageJson` config option is not used in internal `ts-jest` so this option is now removed --- docs/user/config/index.md | 2 - docs/user/config/packageJson.md | 69 ------------------- .../__snapshots__/logger.test.ts.snap | 57 --------------- e2e/__tests__/logger.test.ts | 20 +----- src/config/config-set.spec.ts | 24 +------ src/config/config-set.ts | 6 +- src/types.ts | 10 --- 7 files changed, 3 insertions(+), 185 deletions(-) delete mode 100644 docs/user/config/packageJson.md diff --git a/docs/user/config/index.md b/docs/user/config/index.md index d30ab39a0f..f803664611 100644 --- a/docs/user/config/index.md +++ b/docs/user/config/index.md @@ -213,7 +213,6 @@ All options have default values which should fit most of the projects. Click on | [**`diagnostics`**][diagnostics] | [Diagnostics related configuration.][diagnostics] | `boolean`\|`object` | _enabled_ | | [**`babelConfig`**][babelConfig] | [Babel(Jest) related configuration.][babelConfig] | `boolean`\|`string`\|`object` | _disabled_ | | [**`stringifyContentPathRegex`**][stringifyContentPathRegex] | [Files which will become modules returning self content.][stringifyContentPathRegex] | `string`\|`RegExp` | _disabled_ | -| [**`packageJson`**][packageJson] | [Package metadata.][packageJson] | `string`\|`object`\|`boolean` | _auto_ | ## Version checking @@ -267,4 +266,3 @@ npx ts-jest config:migrate package.json [diagnostics]: diagnostics [babelConfig]: babelConfig [stringifyContentPathRegex]: stringifyContentPathRegex -[packageJson]: packageJson diff --git a/docs/user/config/packageJson.md b/docs/user/config/packageJson.md deleted file mode 100644 index 6d2343010a..0000000000 --- a/docs/user/config/packageJson.md +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: packageJson Config option ---- - -The `packageJson` option specifies the `package.json` file to use. An inline object may also be specified instead of a file path. - -By default, the `package.json` file at the root of the project will be used. If it cannot be found, an empty project definition will be used instead. - -### Examples - -#### Path to a `packageJson` file - -The path should be relative to the current working directory where you start Jest from. You can also use `` in the path to start from the project root dir. - -
- -```js -// jest.config.js -module.exports = { - // [...] - globals: { - 'ts-jest': { - packageJson: 'package.json' - } - } -}; -``` - -
- -```js -// OR from a non-trivial path -// jest.config.js -module.exports = { - // [...] - globals: { - 'ts-jest': { - packageJson: '/../../shared/package.json' - } - } -}; -``` - -
- -#### Inline package metadata - -
- -```js -// jest.config.js -module.exports = { - // [...] - globals: { - 'ts-jest': { - packageJson: { - "name": "my-project", - "version": "1.0.0", - "dependencies": { - // [...] - } - } - } - } -}; -``` - -
- diff --git a/e2e/__tests__/__snapshots__/logger.test.ts.snap b/e2e/__tests__/__snapshots__/logger.test.ts.snap index 0f10b2138a..1e08c41d3b 100644 --- a/e2e/__tests__/__snapshots__/logger.test.ts.snap +++ b/e2e/__tests__/__snapshots__/logger.test.ts.snap @@ -127,63 +127,6 @@ Array [ ] `; -exports[`ts-jest logging deprecation warning with packageJson config should pass using template "default" 1`] = ` - √ jest - ↳ exit code: 0 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) The option \`packageJson\` is deprecated and will be removed in ts-jest 27. This option is not used by internal \`ts-jest\` - PASS ./Hello.spec.ts - Hello Class - √ should create a new Hello - - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`ts-jest logging deprecation warning with packageJson config should pass using template "with-babel-7" 1`] = ` - √ jest - ↳ exit code: 0 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) The option \`packageJson\` is deprecated and will be removed in ts-jest 27. This option is not used by internal \`ts-jest\` - PASS ./Hello.spec.ts - Hello Class - √ should create a new Hello - - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - -exports[`ts-jest logging deprecation warning with packageJson config should pass using template "with-babel-7-string-config" 1`] = ` - √ jest - ↳ exit code: 0 - ===[ STDOUT ]=================================================================== - - ===[ STDERR ]=================================================================== - ts-jest[config] (WARN) The option \`packageJson\` is deprecated and will be removed in ts-jest 27. This option is not used by internal \`ts-jest\` - PASS ./Hello.spec.ts - Hello Class - √ should create a new Hello - - Test Suites: 1 passed, 1 total - Tests: 1 passed, 1 total - Snapshots: 0 total - Time: XXs - Ran all test suites. - ================================================================================ -`; - exports[`ts-jest logging with unsupported version test with TS_JEST_DISABLE_VER_CHECKER is not set in process.env should pass using template "with-unsupported-version" 1`] = ` √ jest ↳ exit code: 0 diff --git a/e2e/__tests__/logger.test.ts b/e2e/__tests__/logger.test.ts index de56f30177..f89e06d0d0 100644 --- a/e2e/__tests__/logger.test.ts +++ b/e2e/__tests__/logger.test.ts @@ -1,7 +1,7 @@ import { LogContexts, LogLevels } from 'bs-logger' import { existsSync } from 'fs' -import { PackageSets, allValidPackageSets, allPackageSetsWithPreset } from '../__helpers__/templates' +import { PackageSets, allValidPackageSets } from '../__helpers__/templates' import { configureTestCase } from '../__helpers__/test-case' describe('ts-jest logging', () => { @@ -90,22 +90,4 @@ describe('ts-jest logging', () => { }) }) } - - describe('deprecation warning', () => { - describe('with packageJson config', () => { - const testCase = configureTestCase('simple', { - tsJestConfig: { - packageJson: true, - } - }) - - testCase.runWithTemplates(allPackageSetsWithPreset, 0, (runTest, { testLabel }) => { - it(testLabel, () => { - const result = runTest() - expect(result.status).toBe(0) - expect(result).toMatchSnapshot() - }) - }) - }) - }) }) diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index 5d61f765e0..494fe4d296 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable jest/no-mocks-import */ import type { Transformer } from '@jest/transform' -import { LogLevels, testing } from 'bs-logger' +import { testing } from 'bs-logger' import { join, resolve } from 'path' import ts from 'typescript' @@ -29,28 +29,6 @@ beforeEach(() => { jest.clearAllMocks() }) -describe('packageJson', () => { - it('should not contain packageJson in final tsJest config', () => { - const logger = testing.createLoggerMock() - createConfigSet({ - jestConfig: { - globals: { - 'ts-jest': { - packageJson: true, - }, - }, - } as any, - resolve: null, - logger, - }) - - 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\` - " - `) - }) -}) // packageJson - describe('parsedTsConfig', () => { const get = (tsJest?: TsJestGlobalOptions) => createConfigSet({ tsJestConfig: tsJest }).parsedTsConfig diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 27833fe4cc..1bd22dd1d7 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -41,7 +41,7 @@ import { importer } from '../utils/importer' import { stringify } from '../utils/json' import { rootLogger } from '../utils/logger' import { Memoize } from '../utils/memoize' -import { Deprecations, Errors, ImportReasons, interpolate } from '../utils/messages' +import { Errors, ImportReasons, interpolate } from '../utils/messages' import { normalizeSlashes } from '../utils/normalize-slashes' import { sha1 } from '../utils/sha1' import { TSError } from '../utils/ts-error' @@ -206,10 +206,6 @@ export class ConfigSet { * @internal */ private _setupTsJestCfg(options: TsJestGlobalOptions): void { - 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 if (!options.babelConfig) { this.logger.debug('babel is disabled') diff --git a/src/types.ts b/src/types.ts index 6a5552ebf1..033a7a0e8e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -56,16 +56,6 @@ export interface TsJestGlobalOptions { */ tsconfig?: boolean | string | _ts.CompilerOptions - /** - * packageJson. It can be: - * - `true` (or `undefined`, it's the default): use default package.json file - * - `path/to/package.json`: path to a specific package.json file ( can be used) - * - `{...}`: contents of a package.json - * - * @default undefined uses the default package.json file - */ - packageJson?: boolean | string | Record - /** * Compiles files as isolated modules (disables some features and type-checking) *