Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(jest-config)!: do not normalize long deprecated configuration options #12701

Merged
merged 4 commits into from Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. I was sure this note was removed long time ago ;D


:::

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