Skip to content

Commit

Permalink
refactor(jest-config)!: do not normalize long deprecated configuratio…
Browse files Browse the repository at this point in the history
…n options (#12701)
  • Loading branch information
mrazauskas committed Apr 20, 2022
1 parent d2f03ef commit f60f84e
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 315 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@
- `[jest-config]` [**BREAKING**] Rename `moduleLoader` to `runtime` ([#10817](https://github.com/facebook/jest/pull/10817))
- `[jest-config]` [**BREAKING**] Rename `extraGlobals` to `sandboxInjectedGlobals` ([#10817](https://github.com/facebook/jest/pull/10817))
- `[jest-config]` [**BREAKING**] Throw an error instead of showing a warning if multiple configs are used ([#12510](https://github.com/facebook/jest/pull/12510))
- `[jest-config]` [**BREAKING**] Do not normalize long deprecated configuration options `preprocessorIgnorePatterns`,`scriptPreprocessor`, `setupTestFrameworkScriptFile` and `testPathDirs` ([#1251270110](https://github.com/facebook/jest/pull/12701))
- `[jest-cli, jest-core]` Add `--ignoreProjects` CLI argument to ignore test suites by project name ([#12620](https://github.com/facebook/jest/pull/12620))
- `[jest-core]` Pass project config to `globalSetup`/`globalTeardown` function as second argument ([#12440](https://github.com/facebook/jest/pull/12440))
- `[jest-core]` Stabilize test runners with event emitters ([#12641](https://github.com/facebook/jest/pull/12641))
Expand All @@ -38,7 +39,7 @@
- `[jest-mock]` [**BREAKING**] Improve the usage of `jest.fn` generic type argument ([#12489](https://github.com/facebook/jest/pull/12489))
- `[jest-mock]` Add support for auto-mocking async generator functions ([#11080](https://github.com/facebook/jest/pull/11080))
- `[jest-mock]` Add `contexts` member to mock functions ([#12601](https://github.com/facebook/jest/pull/12601))
- `[@jest/reporters]` Add GitHub Actions reporter ([#11320](https://github.com/facebook/jest/pull/11320), [#12658](https://github.com/facebook/jest/pull/12658)
- `[@jest/reporters]` Add GitHub Actions reporter ([#11320](https://github.com/facebook/jest/pull/11320), [#12658](https://github.com/facebook/jest/pull/12658))
- `[@jest/reporters]` Pass `reporterContext` to custom reporter constructors as third argument ([#12657](https://github.com/facebook/jest/pull/12657))
- `[jest-resolve]` [**BREAKING**] Add support for `package.json` `exports` ([#11961](https://github.com/facebook/jest/pull/11961), [#12373](https://github.com/facebook/jest/pull/12373))
- `[jest-resolve]` Support package self-reference ([#12682](https://github.com/facebook/jest/pull/12682))
Expand Down
6 changes: 0 additions & 6 deletions docs/Configuration.md
Expand Up @@ -1108,12 +1108,6 @@ If you want a path to be [relative to the root directory of your project](#rootd

For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in these modules.

:::info

`setupTestFrameworkScriptFile` is deprecated in favor of `setupFilesAfterEnv`.

:::

Example `setupFilesAfterEnv` array in a jest.config.js:

```js
Expand Down
28 changes: 3 additions & 25 deletions packages/jest-config/src/Deprecated.ts
Expand Up @@ -7,9 +7,6 @@

import chalk = require('chalk');
import type {DeprecatedOptions} from 'jest-validate';
import {format as prettyFormat} from 'pretty-format';

const format = (value: unknown) => prettyFormat(value, {min: true});

const deprecatedOptions: DeprecatedOptions = {
browser: () =>
Expand All @@ -29,38 +26,24 @@ const deprecatedOptions: DeprecatedOptions = {
Please update your configuration.`,

preprocessorIgnorePatterns: (options: {
preprocessorIgnorePatterns: (_options: {
preprocessorIgnorePatterns?: Array<string>;
}) => ` Option ${chalk.bold(
'"preprocessorIgnorePatterns"',
)} was replaced by ${chalk.bold(
'"transformIgnorePatterns"',
)}, which support multiple preprocessors.
Jest now treats your current configuration as:
{
${chalk.bold('"transformIgnorePatterns"')}: ${chalk.bold(
format(options.preprocessorIgnorePatterns),
)}
}
Please update your configuration.`,

scriptPreprocessor: (options: {
scriptPreprocessor: (_options: {
scriptPreprocessor?: string;
}) => ` Option ${chalk.bold(
'"scriptPreprocessor"',
)} was replaced by ${chalk.bold(
'"transform"',
)}, which support multiple preprocessors.
Jest now treats your current configuration as:
{
${chalk.bold('"transform"')}: ${chalk.bold(
`{".*": ${format(options.scriptPreprocessor)}}`,
)}
}
Please update your configuration.`,

setupTestFrameworkScriptFile: (_options: {
Expand All @@ -73,17 +56,12 @@ const deprecatedOptions: DeprecatedOptions = {
Please update your configuration.`,

testPathDirs: (options: {
testPathDirs: (_options: {
testPathDirs?: Array<string>;
}) => ` Option ${chalk.bold('"testPathDirs"')} was replaced by ${chalk.bold(
'"roots"',
)}.
Jest now treats your current configuration as:
{
${chalk.bold('"roots"')}: ${chalk.bold(format(options.testPathDirs))}
}
Please update your configuration.
`,

Expand Down
259 changes: 169 additions & 90 deletions packages/jest-config/src/__tests__/__snapshots__/normalize.test.ts.snap
@@ -1,22 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Upgrade help logs a warning when \`scriptPreprocessor\` and/or \`preprocessorIgnorePatterns\` are used 1`] = `
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"preprocessorIgnorePatterns"</> was replaced by <bold>"transformIgnorePatterns"</>, which support multiple preprocessors.</>
<yellow></>
<yellow> Jest now treats your current configuration as:</>
<yellow> {</>
<yellow> <bold>"transformIgnorePatterns"</>: <bold>["bar/baz", "qux/quux"]</></>
<yellow> }</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>"
`;

exports[`displayName generates a default color for the runner jest-runner 1`] = `"yellow"`;

exports[`displayName generates a default color for the runner jest-runner-eslint 1`] = `"magenta"`;
Expand Down Expand Up @@ -132,7 +115,29 @@ exports[`extensionsToTreatAsEsm throws on .mjs 1`] = `
<red></>"
`;

exports[`extraGlobals logs a deprecation warning when \`extraGlobals\` is used 1`] = `
exports[`logs a deprecation warning when 'browser' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"browser"</> has been deprecated. Please install "browser-resolve" and use the "resolver" option in Jest configuration as shown in the documentation: https://jestjs.io/docs/configuration#resolver-string</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`logs a deprecation warning when 'extraGlobals' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
Expand All @@ -156,7 +161,7 @@ exports[`extraGlobals logs a deprecation warning when \`extraGlobals\` is used 1
}
`;

exports[`moduleLoader logs a deprecation warning when \`moduleLoader\` is used 1`] = `
exports[`logs a deprecation warning when 'moduleLoader' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
Expand All @@ -180,6 +185,151 @@ exports[`moduleLoader logs a deprecation warning when \`moduleLoader\` is used 1
}
`;

exports[`logs a deprecation warning when 'preprocessorIgnorePatterns' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"preprocessorIgnorePatterns"</> was replaced by <bold>"transformIgnorePatterns"</>, which support multiple preprocessors.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`logs a deprecation warning when 'scriptPreprocessor' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"scriptPreprocessor"</> was replaced by <bold>"transform"</>, which support multiple preprocessors.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`logs a deprecation warning when 'setupTestFrameworkScriptFile' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"setupTestFrameworkScriptFile"</> was replaced by configuration <bold>"setupFilesAfterEnv"</>, which supports multiple paths.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`logs a deprecation warning when 'testPathDirs' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"testPathDirs"</> was replaced by <bold>"roots"</>.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow> </>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`logs a deprecation warning when 'testURL' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"testURL"</> was replaced by passing the URL via <bold>"testEnvironmentOptions.url"</>.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`logs a deprecation warning when 'timers' option is passed 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"timers"</> was replaced by <bold>"fakeTimers"</>.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`preset throws when module was found but no "jest-preset.js" or "jest-preset.json" files 1`] = `
"<red><bold><bold>● </><bold>Validation Error</>:</>
<red></>
Expand Down Expand Up @@ -288,29 +438,6 @@ exports[`runner throw error when a runner is not found 1`] = `
<red></>"
`;

exports[`setupTestFrameworkScriptFile logs a deprecation warning when \`setupTestFrameworkScriptFile\` is used 1`] = `
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"setupTestFrameworkScriptFile"</> was replaced by configuration <bold>"setupFilesAfterEnv"</>, which supports multiple paths.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>"
`;

exports[`setupTestFrameworkScriptFile logs an error when \`setupTestFrameworkScriptFile\` and \`setupFilesAfterEnv\` are used 1`] = `
"<red><bold><bold>● </><bold>Validation Error</>:</>
<red></>
<red> Options: <bold>setupTestFrameworkScriptFile</> and <bold>setupFilesAfterEnv</> cannot be used together.</>
<red> Please change your configuration to only use <bold>setupFilesAfterEnv</>.</>
<red></>
<red> <bold>Configuration Documentation:</></>
<red> https://jestjs.io/docs/configuration</>
<red></>"
`;

exports[`testEnvironment throws on invalid environment names 1`] = `
"<red><bold><bold>● </><bold>Validation Error</>:</>
<red></>
Expand Down Expand Up @@ -345,54 +472,6 @@ exports[`testTimeout should throw an error if timeout is a negative number 1`] =
<red></>"
`;

exports[`testURL logs a deprecation warning when \`testURL\` is used 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"testURL"</> was replaced by passing the URL via <bold>"testEnvironmentOptions.url"</>.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`timers logs a deprecation warning when \`timers\` is used 1`] = `
[MockFunction] {
"calls": Array [
Array [
"<yellow><bold><bold>●</><bold> Deprecation Warning</>:</>
<yellow></>
<yellow> Option <bold>"timers"</> was replaced by <bold>"fakeTimers"</>.</>
<yellow></>
<yellow> Please update your configuration.</>
<yellow></>
<yellow> <bold>Configuration Documentation:</></>
<yellow> https://jestjs.io/docs/configuration</>
<yellow></>",
],
],
"results": Array [
Object {
"type": "return",
"value": undefined,
},
],
}
`;

exports[`watchPlugins throw error when a watch plugin is not found 1`] = `
"<red><bold><bold>● </><bold>Validation Error</>:</>
<red></>
Expand Down

0 comments on commit f60f84e

Please sign in to comment.