diff --git a/CHANGELOG.md b/CHANGELOG.md index 781155053460..92078e6ab849 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,20 +4,20 @@ - `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874)) - `[jest-config]` [**BREAKING**] Use `jest-circus` as default test runner ([#10686](https://github.com/facebook/jest/pull/10686)) -- `[jest-runner]` [**BREAKING**] set exit code to 1 if test logs after teardown ([#10728](https://github.com/facebook/jest/pull/10728)) -- `[jest-snapshot]`: [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792)) - `[jest-repl, jest-runner]` [**BREAKING**] Run transforms over environment ([#8751](https://github.com/facebook/jest/pull/8751)) +- `[jest-runner]` [**BREAKING**] set exit code to 1 if test logs after teardown ([#10728](https://github.com/facebook/jest/pull/10728)) +- `[jest-snapshot]` [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792)) - `[jest-runner]` [**BREAKING**] Run transforms over `runnner` ([#8823](https://github.com/facebook/jest/pull/8823)) - `[jest-runner]` [**BREAKING**] Run transforms over `testRunnner` ([#8823](https://github.com/facebook/jest/pull/8823)) ### Fixes +- `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708)) - `[jest-circus]` Fixed the issue of beforeAll & afterAll hooks getting executed even if it is inside a skipped `describe` block [#10451](https://github.com/facebook/jest/issues/10451) - `[jest-circus]` Fix `testLocation` on Windows when using `test.each` ([#10871](https://github.com/facebook/jest/pull/10871)) +- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638)) - `[jest-jasmine2]` Fixed the issue of beforeAll & afterAll hooks getting executed even if it is inside a skipped `describe` block when it has child `tests` marked as either `only` or `todo` [#10451](https://github.com/facebook/jest/issues/10451) - `[jest-jasmine2]` Fixed the issues of child `tests` marked with `only` or `todo` getting executed even if it is inside a skipped parent `describe` block [#10451](https://github.com/facebook/jest/issues/10451) -- `[jest-console]` `console.dir` now respects the second argument correctly ([#10638](https://github.com/facebook/jest/pull/10638)) -- `[expect]` [**BREAKING**] Revise `expect.not.objectContaining()` to be the inverse of `expect.objectContaining()`, as documented. ([#10708](https://github.com/facebook/jest/pull/10708)) - `[jest-reporter]` Handle empty files when reporting code coverage with V8 ([#10819](https://github.com/facebook/jest/pull/10819)) - `[jest-resolve]` Replace read-pkg-up with escalade package ([#10781](https://github.com/facebook/jest/pull/10781)) - `[jest-resolve]` Disable `jest-pnp-resolver` for Yarn 2 ([#10847](https://github.com/facebook/jest/pull/10847)) @@ -26,18 +26,19 @@ - `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749)) - `[jest-transform]` [**BREAKING**] Refactor API to pass an options bag around rather than multiple boolean options ([#10753](https://github.com/facebook/jest/pull/10753)) - `[jest-transform]` [**BREAKING**] Refactor API of transformers to pass an options bag rather than separate `config` and other options +- `[pretty-format]` [**BREAKING**] Convert to ES Modules ([#10515](https://github.com/facebook/jest/pull/10515)) ### Chore & Maintenance -- `[jest-console]` [**BREAKING**] Move `root` into `config` and take `GlobalConfig` as mandatory parameter for `getConsoleOutput` ([#10126](https://github.com/facebook/jest/pull/10126)) - `[*]` [**BREAKING**] Only support Node LTS releases and Node 15 ([#10685](https://github.com/facebook/jest/pull/10685)) - `[*]` [**BREAKING**] Add `exports` field to all `package.json`s ([#9921](https://github.com/facebook/jest/pull/9921)) - `[*]` Make it easier for Jest's packages to use the VM escape hatch ([#10824](https://github.com/facebook/jest/pull/10824)) - `[jest-config]` [**BREAKING**] Remove `enabledTestsMap` config, use `filter` instead ([#10787](https://github.com/facebook/jest/pull/10787)) +- `[jest-console]` [**BREAKING**] Move `root` into `config` and take `GlobalConfig` as mandatory parameter for `getConsoleOutput` ([#10126](https://github.com/facebook/jest/pull/10126)) +- `[jest-fake-timers]` Clarify global behavior of `jest.useFakeTimers` and `jest.useRealTimers` ([#10867](https://github.com/facebook/jest/pull/10867)) - `[jest-resolve]` [**BREAKING**] Migrate to ESM ([#10688](https://github.com/facebook/jest/pull/10688)) - `[jest-repl, jest-runtime]` [**BREAKING**] Move the `jest-runtime` CLI into `jest-repl` ([#10016](https://github.com/facebook/jest/pull/10016)) - `[jest-util]` No longer checking `enumerable` when adding `process.domain` ([#10862](https://github.com/facebook/jest/pull/10862)) -- `[jest-fake-timers]` Clarify global behavior of `jest.useFakeTimers` and `jest.useRealTimers` ([#10867](https://github.com/facebook/jest/pull/10867)) ### Performance diff --git a/docs/JestPlatform.md b/docs/JestPlatform.md index 648acb758943..5ed250b1ef0a 100644 --- a/docs/JestPlatform.md +++ b/docs/JestPlatform.md @@ -160,7 +160,7 @@ Exports a function that converts any JavaScript value into a human-readable stri ### Example ```javascript -const prettyFormat = require('pretty-format'); +const {format: prettyFormat} = require('pretty-format'); const val = {object: {}}; val.circularReference = val; diff --git a/package.json b/package.json index 800bead8e714..1d857c72e66b 100644 --- a/package.json +++ b/package.json @@ -145,6 +145,7 @@ "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" }, "resolutions": { + "@testing-library/dom/pretty-format": "26.6.1", "@types/jest/jest-diff": "^25.1.0", "@types/jest/pretty-format": "^25.1.0", "fbjs-scripts": "patch:fbjs-scripts@^1.1.0#./patches/fbjs-scripts.patch" diff --git a/packages/jest-circus/src/formatNodeAssertErrors.ts b/packages/jest-circus/src/formatNodeAssertErrors.ts index 602d1414c61c..aef7dd9fb47f 100644 --- a/packages/jest-circus/src/formatNodeAssertErrors.ts +++ b/packages/jest-circus/src/formatNodeAssertErrors.ts @@ -14,7 +14,7 @@ import { printExpected, printReceived, } from 'jest-matcher-utils'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; interface AssertionErrorWithStack extends AssertionError { stack: string; diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index 345bdf2b1d54..311308f2ce25 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -14,7 +14,7 @@ import StackUtils = require('stack-utils'); import type {AssertionResult, Status} from '@jest/test-result'; import type {Circus} from '@jest/types'; import {ErrorWithStack, convertDescriptorToString, formatTime} from 'jest-util'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; import {ROOT_DESCRIBE_BLOCK_NAME, getState} from './state'; const stackUtils = new StackUtils({cwd: 'A path that does not exist'}); diff --git a/packages/jest-config/src/Deprecated.ts b/packages/jest-config/src/Deprecated.ts index 841983fa1a3b..0e0bc23ee732 100644 --- a/packages/jest-config/src/Deprecated.ts +++ b/packages/jest-config/src/Deprecated.ts @@ -7,7 +7,7 @@ import chalk = require('chalk'); import type {DeprecatedOptions} from 'jest-validate'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; const format = (value: unknown) => prettyFormat(value, {min: true}); diff --git a/packages/jest-diff/README.md b/packages/jest-diff/README.md index f63843ce8f3c..5fcaca167f1e 100644 --- a/packages/jest-diff/README.md +++ b/packages/jest-diff/README.md @@ -165,7 +165,7 @@ You might call this function for case insensitive or Unicode equivalence compari ### Example of diffLinesUnified2 ```js -import format from 'pretty-format'; +import {format} from 'pretty-format'; const a = { text: 'Ignore indentation in serialized object', diff --git a/packages/jest-diff/src/index.ts b/packages/jest-diff/src/index.ts index 6f6ba8be46f0..7046d79d3839 100644 --- a/packages/jest-diff/src/index.ts +++ b/packages/jest-diff/src/index.ts @@ -7,7 +7,7 @@ import chalk = require('chalk'); import getType = require('jest-get-type'); -import prettyFormat = require('pretty-format'); +import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format'; import {DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff} from './cleanupSemantic'; import {NO_DIFF_MESSAGE, SIMILAR_MESSAGE} from './constants'; import {diffLinesRaw, diffLinesUnified, diffLinesUnified2} from './diffLines'; @@ -33,7 +33,7 @@ const { Immutable, ReactElement, ReactTestComponent, -} = prettyFormat.plugins; +} = prettyFormatPlugins; const PLUGINS = [ ReactTestComponent, diff --git a/packages/jest-each/src/__tests__/array.test.ts b/packages/jest-each/src/__tests__/array.test.ts index 19136ae65f81..e95b8e4e701d 100644 --- a/packages/jest-each/src/__tests__/array.test.ts +++ b/packages/jest-each/src/__tests__/array.test.ts @@ -6,7 +6,7 @@ * */ -import pretty = require('pretty-format'); +import pretty from 'pretty-format'; import each from '../'; const noop = () => {}; diff --git a/packages/jest-each/src/table/array.ts b/packages/jest-each/src/table/array.ts index 016bf4baa778..5bee8ee47b59 100644 --- a/packages/jest-each/src/table/array.ts +++ b/packages/jest-each/src/table/array.ts @@ -8,7 +8,7 @@ import * as util from 'util'; import type {Global} from '@jest/types'; -import pretty = require('pretty-format'); +import pretty from 'pretty-format'; import type {EachTests} from '../bind'; const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp%]/g; diff --git a/packages/jest-each/src/table/template.ts b/packages/jest-each/src/table/template.ts index 995a1fbe0738..c3cf5d22830b 100644 --- a/packages/jest-each/src/table/template.ts +++ b/packages/jest-each/src/table/template.ts @@ -8,7 +8,7 @@ import type {Global} from '@jest/types'; import {isPrimitive} from 'jest-get-type'; -import pretty = require('pretty-format'); +import pretty from 'pretty-format'; import type {EachTests} from '../bind'; type Template = Record; diff --git a/packages/jest-each/src/validation.ts b/packages/jest-each/src/validation.ts index 3782bedebea1..3cd70e143127 100644 --- a/packages/jest-each/src/validation.ts +++ b/packages/jest-each/src/validation.ts @@ -8,7 +8,7 @@ import chalk = require('chalk'); import type {Global} from '@jest/types'; -import pretty = require('pretty-format'); +import pretty from 'pretty-format'; type TemplateData = Global.TemplateData; diff --git a/packages/jest-jasmine2/src/expectationResultFactory.ts b/packages/jest-jasmine2/src/expectationResultFactory.ts index 69d5893202dc..86069b1d633c 100644 --- a/packages/jest-jasmine2/src/expectationResultFactory.ts +++ b/packages/jest-jasmine2/src/expectationResultFactory.ts @@ -6,7 +6,7 @@ */ import type {FailedAssertion} from '@jest/test-result'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; function messageFormatter({error, message, passed}: Options) { if (passed) { diff --git a/packages/jest-jasmine2/src/isError.ts b/packages/jest-jasmine2/src/isError.ts index 1eb0aef83ace..72a77f0aa844 100644 --- a/packages/jest-jasmine2/src/isError.ts +++ b/packages/jest-jasmine2/src/isError.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; export default function isError( // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types diff --git a/packages/jest-leak-detector/src/index.ts b/packages/jest-leak-detector/src/index.ts index d1c115a2cf6c..232c00425348 100644 --- a/packages/jest-leak-detector/src/index.ts +++ b/packages/jest-leak-detector/src/index.ts @@ -11,7 +11,7 @@ import {promisify} from 'util'; import {setFlagsFromString} from 'v8'; import {runInNewContext} from 'vm'; import {isPrimitive} from 'jest-get-type'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; const tick = promisify(setImmediate); diff --git a/packages/jest-matcher-utils/src/__tests__/index.test.ts b/packages/jest-matcher-utils/src/__tests__/index.test.ts index 2e28dfba9441..d02c16de4cb1 100644 --- a/packages/jest-matcher-utils/src/__tests__/index.test.ts +++ b/packages/jest-matcher-utils/src/__tests__/index.test.ts @@ -8,7 +8,7 @@ import chalk = require('chalk'); import {alignedAnsiStyleSerializer} from '@jest/test-utils'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; import { MatcherHintOptions, diff, diff --git a/packages/jest-matcher-utils/src/index.ts b/packages/jest-matcher-utils/src/index.ts index 3013c77ebc53..bd4547f9b89a 100644 --- a/packages/jest-matcher-utils/src/index.ts +++ b/packages/jest-matcher-utils/src/index.ts @@ -18,7 +18,7 @@ import diffDefault, { diffStringsUnified, } from 'jest-diff'; import getType = require('jest-get-type'); -import prettyFormat = require('pretty-format'); +import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format'; import Replaceable from './Replaceable'; import deepCyclicCopyReplaceable from './deepCyclicCopyReplaceable'; @@ -29,7 +29,7 @@ const { Immutable, ReactElement, ReactTestComponent, -} = prettyFormat.plugins; +} = prettyFormatPlugins; const PLUGINS = [ ReactTestComponent, diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index 93645110aaf3..9dcaf9c94c40 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -13,7 +13,7 @@ import micromatch = require('micromatch'); import slash = require('slash'); import StackUtils = require('stack-utils'); import type {Config, TestResult} from '@jest/types'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; import type {Frame} from './types'; export type {Frame} from './types'; diff --git a/packages/jest-serializer/src/__tests__/index.test.ts b/packages/jest-serializer/src/__tests__/index.test.ts index d6c8f82e157b..8c3a67781735 100644 --- a/packages/jest-serializer/src/__tests__/index.test.ts +++ b/packages/jest-serializer/src/__tests__/index.test.ts @@ -8,7 +8,7 @@ import {tmpdir} from 'os'; import * as path from 'path'; import * as fs from 'graceful-fs'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; import serializer from '..'; const objs = [ diff --git a/packages/jest-snapshot/src/__tests__/dedentLines.test.ts b/packages/jest-snapshot/src/__tests__/dedentLines.test.ts index 43cdcb8447ed..429b74fec8da 100644 --- a/packages/jest-snapshot/src/__tests__/dedentLines.test.ts +++ b/packages/jest-snapshot/src/__tests__/dedentLines.test.ts @@ -5,11 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -import format = require('pretty-format'); +import {plugins as builtinPlugins, format} from 'pretty-format'; import {dedentLines} from '../dedentLines'; const $$typeof = Symbol.for('react.test.json'); -const plugins = [format.plugins.ReactTestComponent]; +const plugins = [builtinPlugins.ReactTestComponent]; const formatLines2 = val => format(val, {indent: 2, plugins}).split('\n'); const formatLines0 = val => format(val, {indent: 0, plugins}).split('\n'); diff --git a/packages/jest-snapshot/src/__tests__/mockSerializer.test.ts b/packages/jest-snapshot/src/__tests__/mockSerializer.test.ts index 821c86a86025..95e62b770167 100644 --- a/packages/jest-snapshot/src/__tests__/mockSerializer.test.ts +++ b/packages/jest-snapshot/src/__tests__/mockSerializer.test.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; import plugin from '../mockSerializer'; test('mock with 0 calls and default name', () => { diff --git a/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts b/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts index 38cc0cf821d5..6ea4f4056b28 100644 --- a/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts +++ b/packages/jest-snapshot/src/__tests__/printSnapshot.test.ts @@ -8,7 +8,7 @@ import ansiRegex = require('ansi-regex'); import styles = require('ansi-styles'); import chalk = require('chalk'); -import format = require('pretty-format'); +import format from 'pretty-format'; import { aBackground2, aBackground3, diff --git a/packages/jest-snapshot/src/plugins.ts b/packages/jest-snapshot/src/plugins.ts index fdaf455e4470..530af15dc1f1 100644 --- a/packages/jest-snapshot/src/plugins.ts +++ b/packages/jest-snapshot/src/plugins.ts @@ -5,7 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -import prettyFormat = require('pretty-format'); +import { + Plugin as PrettyFormatPlugin, + Plugins as PrettyFormatPlugins, + plugins as prettyFormatPlugins, +} from 'pretty-format'; import jestMockSerializer from './mockSerializer'; const { @@ -15,9 +19,9 @@ const { ReactElement, ReactTestComponent, AsymmetricMatcher, -} = prettyFormat.plugins; +} = prettyFormatPlugins; -let PLUGINS: prettyFormat.Plugins = [ +let PLUGINS: PrettyFormatPlugins = [ ReactTestComponent, ReactElement, DOMElement, @@ -28,8 +32,8 @@ let PLUGINS: prettyFormat.Plugins = [ ]; // Prepend to list so the last added is the first tested. -export const addSerializer = (plugin: prettyFormat.Plugin): void => { +export const addSerializer = (plugin: PrettyFormatPlugin): void => { PLUGINS = [plugin].concat(PLUGINS); }; -export const getSerializers = (): prettyFormat.Plugins => PLUGINS; +export const getSerializers = (): PrettyFormatPlugins => PLUGINS; diff --git a/packages/jest-snapshot/src/printSnapshot.ts b/packages/jest-snapshot/src/printSnapshot.ts index cae43b41ebf5..34a4370f7436 100644 --- a/packages/jest-snapshot/src/printSnapshot.ts +++ b/packages/jest-snapshot/src/printSnapshot.ts @@ -34,7 +34,7 @@ import { getLabelPrinter, matcherHint, } from 'jest-matcher-utils'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; import { aBackground2, aBackground3, diff --git a/packages/jest-snapshot/src/utils.ts b/packages/jest-snapshot/src/utils.ts index 4441b3825a94..bfaa4d5024eb 100644 --- a/packages/jest-snapshot/src/utils.ts +++ b/packages/jest-snapshot/src/utils.ts @@ -10,7 +10,7 @@ import chalk = require('chalk'); import * as fs from 'graceful-fs'; import naturalCompare = require('natural-compare'); import type {Config} from '@jest/types'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; import {getSerializers} from './plugins'; import type {SnapshotData} from './types'; diff --git a/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts b/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts index f157b5d80312..cff071ccb772 100644 --- a/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts +++ b/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts @@ -127,7 +127,8 @@ const validConfig = { watchman: true, }; -const format = (value: string) => require('pretty-format')(value, {min: true}); +const format = (value: string) => + require('pretty-format').format(value, {min: true}); const deprecatedConfig = { preprocessorIgnorePatterns: (config: Record) => diff --git a/packages/jest-validate/src/utils.ts b/packages/jest-validate/src/utils.ts index a7fb56787224..169aab829df0 100644 --- a/packages/jest-validate/src/utils.ts +++ b/packages/jest-validate/src/utils.ts @@ -7,7 +7,7 @@ import chalk = require('chalk'); import leven from 'leven'; -import prettyFormat = require('pretty-format'); +import prettyFormat from 'pretty-format'; const BULLET: string = chalk.bold('\u25cf'); export const DEPRECATION = `${BULLET} Deprecation Warning`; diff --git a/packages/pretty-format/README.md b/packages/pretty-format/README.md index 92a235d99b85..6b2053be2695 100755 --- a/packages/pretty-format/README.md +++ b/packages/pretty-format/README.md @@ -14,11 +14,11 @@ $ yarn add pretty-format ## Usage ```js -const prettyFormat = require('pretty-format'); // CommonJS +const {format: prettyFormat} = require('pretty-format'); // CommonJS ``` ```js -import prettyFormat from 'pretty-format'; // ES2015 modules +import {format as prettyFormat} from 'pretty-format'; // ES2015 modules ``` ```js @@ -102,17 +102,18 @@ The `pretty-format` package provides some built-in plugins, including: // CommonJS const React = require('react'); const renderer = require('react-test-renderer'); -const prettyFormat = require('pretty-format'); -const ReactElement = prettyFormat.plugins.ReactElement; -const ReactTestComponent = prettyFormat.plugins.ReactTestComponent; +const {format: prettyFormat, plugins} = require('pretty-format'); + +const {ReactElement, ReactTestComponent} = plugins; ``` ```js +// ES2015 modules and destructuring assignment import React from 'react'; import renderer from 'react-test-renderer'; -// ES2015 modules and destructuring assignment -import prettyFormat from 'pretty-format'; -const {ReactElement, ReactTestComponent} = prettyFormat.plugins; +import {plugins, format as prettyFormat} from 'pretty-format'; + +const {ReactElement, ReactTestComponent} = plugins; ``` ```js diff --git a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts index 3ba1f18253cc..20ba762a718b 100644 --- a/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts +++ b/packages/pretty-format/src/__tests__/AsymmetricMatcher.test.ts @@ -5,10 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import prettyFormat from '../'; -import {OptionsReceived} from '../types'; +import prettyFormat, {plugins} from '../'; +import type {OptionsReceived} from '../types'; -const {AsymmetricMatcher} = prettyFormat.plugins; +const {AsymmetricMatcher} = plugins; let options: OptionsReceived; function fnNameFor(func: (...any: Array) => unknown) { diff --git a/packages/pretty-format/src/__tests__/ConvertAnsi.test.ts b/packages/pretty-format/src/__tests__/ConvertAnsi.test.ts index 6e74956c34f5..aee6f3683f1d 100644 --- a/packages/pretty-format/src/__tests__/ConvertAnsi.test.ts +++ b/packages/pretty-format/src/__tests__/ConvertAnsi.test.ts @@ -6,9 +6,9 @@ */ import ansiStyle = require('ansi-styles'); -import prettyFormat = require('../'); +import prettyFormat, {plugins} from '../'; -const {ConvertAnsi} = prettyFormat.plugins; +const {ConvertAnsi} = plugins; const prettyFormatResult = (val: string) => prettyFormat(val, { diff --git a/packages/pretty-format/src/__tests__/DOMCollection.test.ts b/packages/pretty-format/src/__tests__/DOMCollection.test.ts index 011951457900..b42c2b6b73db 100644 --- a/packages/pretty-format/src/__tests__/DOMCollection.test.ts +++ b/packages/pretty-format/src/__tests__/DOMCollection.test.ts @@ -8,10 +8,10 @@ */ /* eslint-env browser*/ -import prettyFormat from '../'; +import {plugins} from '../'; import setPrettyPrint from './setPrettyPrint'; -const {DOMCollection, DOMElement} = prettyFormat.plugins; +const {DOMCollection, DOMElement} = plugins; setPrettyPrint([DOMCollection, DOMElement]); diff --git a/packages/pretty-format/src/__tests__/DOMElement.test.ts b/packages/pretty-format/src/__tests__/DOMElement.test.ts index 6ad40955532e..8c86488ebf0e 100644 --- a/packages/pretty-format/src/__tests__/DOMElement.test.ts +++ b/packages/pretty-format/src/__tests__/DOMElement.test.ts @@ -8,10 +8,10 @@ */ /* eslint-env browser*/ -import prettyFormat from '../'; +import prettyFormat, {plugins} from '../'; import setPrettyPrint from './setPrettyPrint'; -const {DOMElement} = prettyFormat.plugins; +const {DOMElement} = plugins; setPrettyPrint([DOMElement]); diff --git a/packages/pretty-format/src/__tests__/Immutable.test.ts b/packages/pretty-format/src/__tests__/Immutable.test.ts index 751ed51623d9..7fe9925adf36 100644 --- a/packages/pretty-format/src/__tests__/Immutable.test.ts +++ b/packages/pretty-format/src/__tests__/Immutable.test.ts @@ -9,10 +9,10 @@ import Immutable from 'immutable'; import React from 'react'; -import prettyFormat from '..'; +import {plugins} from '..'; import setPrettyPrint from './setPrettyPrint'; -const {Immutable: ImmutablePlugin, ReactElement} = prettyFormat.plugins; +const {Immutable: ImmutablePlugin, ReactElement} = plugins; setPrettyPrint([ReactElement, ImmutablePlugin]); diff --git a/packages/pretty-format/src/__tests__/ReactElement.test.ts b/packages/pretty-format/src/__tests__/ReactElement.test.ts index 8946c4e3027a..911048067c38 100644 --- a/packages/pretty-format/src/__tests__/ReactElement.test.ts +++ b/packages/pretty-format/src/__tests__/ReactElement.test.ts @@ -6,10 +6,10 @@ */ import React from 'react'; -import prettyFormat from '..'; +import {plugins} from '../'; import setPrettyPrint from './setPrettyPrint'; -const {ReactElement} = prettyFormat.plugins; +const {ReactElement} = plugins; setPrettyPrint([ReactElement]); diff --git a/packages/pretty-format/src/__tests__/react.test.tsx b/packages/pretty-format/src/__tests__/react.test.tsx index 8591eaa43d72..0e636b0eb648 100644 --- a/packages/pretty-format/src/__tests__/react.test.tsx +++ b/packages/pretty-format/src/__tests__/react.test.tsx @@ -7,14 +7,14 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import prettyFormat from '..'; -import {OptionsReceived} from '../types'; +import prettyFormat, {plugins} from '..'; +import type {OptionsReceived} from '../types'; const elementSymbol = Symbol.for('react.element'); const fragmentSymbol = Symbol.for('react.fragment'); const suspenseSymbol = Symbol.for('react.suspense'); const testSymbol = Symbol.for('react.test.json'); -const {ReactElement, ReactTestComponent} = prettyFormat.plugins; +const {ReactElement, ReactTestComponent} = plugins; const formatElement = (element: unknown, options?: OptionsReceived) => prettyFormat(element, {plugins: [ReactElement], ...options}); diff --git a/packages/pretty-format/src/index.ts b/packages/pretty-format/src/index.ts index e37a12c34863..8a0e1f26b8c2 100644 --- a/packages/pretty-format/src/index.ts +++ b/packages/pretty-format/src/index.ts @@ -21,7 +21,30 @@ import DOMElement from './plugins/DOMElement'; import Immutable from './plugins/Immutable'; import ReactElement from './plugins/ReactElement'; import ReactTestComponent from './plugins/ReactTestComponent'; -import type * as PrettyFormat from './types'; +import type { + Colors, + Config, + NewPlugin, + Options, + OptionsReceived, + Plugin, + Plugins, + Refs, + Theme, +} from './types'; + +export type { + Colors, + Config, + Options, + OptionsReceived, + OldPlugin, + NewPlugin, + Plugin, + Plugins, + Refs, + Theme, +} from './types'; const toString = Object.prototype.toString; const toISOString = Date.prototype.toISOString; @@ -176,10 +199,10 @@ function printBasicValue( */ function printComplexValue( val: any, - config: PrettyFormat.Config, + config: Config, indentation: string, depth: number, - refs: PrettyFormat.Refs, + refs: Refs, hasCalledToJSON?: boolean, ): string { if (refs.indexOf(val) !== -1) { @@ -258,19 +281,17 @@ function printComplexValue( '}'; } -function isNewPlugin( - plugin: PrettyFormat.Plugin, -): plugin is PrettyFormat.NewPlugin { - return (plugin as PrettyFormat.NewPlugin).serialize != null; +function isNewPlugin(plugin: Plugin): plugin is NewPlugin { + return (plugin as NewPlugin).serialize != null; } function printPlugin( - plugin: PrettyFormat.Plugin, + plugin: Plugin, val: any, - config: PrettyFormat.Config, + config: Config, indentation: string, depth: number, - refs: PrettyFormat.Refs, + refs: Refs, ): string { let printed; @@ -305,7 +326,7 @@ function printPlugin( return printed; } -function findPlugin(plugins: PrettyFormat.Plugins, val: unknown) { +function findPlugin(plugins: Plugins, val: unknown) { for (let p = 0; p < plugins.length; p++) { try { if (plugins[p].test(val)) { @@ -321,10 +342,10 @@ function findPlugin(plugins: PrettyFormat.Plugins, val: unknown) { function printer( val: unknown, - config: PrettyFormat.Config, + config: Config, indentation: string, depth: number, - refs: PrettyFormat.Refs, + refs: Refs, hasCalledToJSON?: boolean, ): string { const plugin = findPlugin(config.plugins, val); @@ -352,7 +373,7 @@ function printer( ); } -const DEFAULT_THEME: PrettyFormat.Theme = { +const DEFAULT_THEME: Theme = { comment: 'gray', content: 'reset', prop: 'yellow', @@ -364,7 +385,7 @@ const DEFAULT_THEME_KEYS = Object.keys(DEFAULT_THEME) as Array< keyof typeof DEFAULT_THEME >; -const DEFAULT_OPTIONS: PrettyFormat.Options = { +const DEFAULT_OPTIONS: Options = { callToJSON: true, escapeRegex: false, escapeString: true, @@ -377,7 +398,7 @@ const DEFAULT_OPTIONS: PrettyFormat.Options = { theme: DEFAULT_THEME, }; -function validateOptions(options: PrettyFormat.OptionsReceived) { +function validateOptions(options: OptionsReceived) { Object.keys(options).forEach(key => { if (!DEFAULT_OPTIONS.hasOwnProperty(key)) { throw new Error(`pretty-format: Unknown option "${key}".`); @@ -403,9 +424,7 @@ function validateOptions(options: PrettyFormat.OptionsReceived) { } } -const getColorsHighlight = ( - options: PrettyFormat.OptionsReceived, -): PrettyFormat.Colors => +const getColorsHighlight = (options: OptionsReceived): Colors => DEFAULT_THEME_KEYS.reduce((colors, key) => { const value = options.theme && options.theme[key] !== undefined @@ -426,30 +445,28 @@ const getColorsHighlight = ( return colors; }, Object.create(null)); -const getColorsEmpty = (): PrettyFormat.Colors => +const getColorsEmpty = (): Colors => DEFAULT_THEME_KEYS.reduce((colors, key) => { colors[key] = {close: '', open: ''}; return colors; }, Object.create(null)); -const getPrintFunctionName = (options?: PrettyFormat.OptionsReceived) => +const getPrintFunctionName = (options?: OptionsReceived) => options && options.printFunctionName !== undefined ? options.printFunctionName : DEFAULT_OPTIONS.printFunctionName; -const getEscapeRegex = (options?: PrettyFormat.OptionsReceived) => +const getEscapeRegex = (options?: OptionsReceived) => options && options.escapeRegex !== undefined ? options.escapeRegex : DEFAULT_OPTIONS.escapeRegex; -const getEscapeString = (options?: PrettyFormat.OptionsReceived) => +const getEscapeString = (options?: OptionsReceived) => options && options.escapeString !== undefined ? options.escapeString : DEFAULT_OPTIONS.escapeString; -const getConfig = ( - options?: PrettyFormat.OptionsReceived, -): PrettyFormat.Config => ({ +const getConfig = (options?: OptionsReceived): Config => ({ callToJSON: options && options.callToJSON !== undefined ? options.callToJSON @@ -491,10 +508,7 @@ function createIndent(indent: number): string { * @param val any potential JavaScript object * @param options Custom settings */ -function prettyFormat( - val: unknown, - options?: PrettyFormat.OptionsReceived, -): string { +export function format(val: unknown, options?: OptionsReceived): string { if (options) { validateOptions(options); if (options.plugins) { @@ -518,7 +532,7 @@ function prettyFormat( return printComplexValue(val, getConfig(options), '', 0, []); } -prettyFormat.plugins = { +export const plugins = { AsymmetricMatcher, ConvertAnsi, DOMCollection, @@ -528,17 +542,4 @@ prettyFormat.plugins = { ReactTestComponent, }; -declare namespace prettyFormat { - export type Colors = PrettyFormat.Colors; - export type Config = PrettyFormat.Config; - export type Options = PrettyFormat.Options; - export type OptionsReceived = PrettyFormat.OptionsReceived; - export type OldPlugin = PrettyFormat.OldPlugin; - export type NewPlugin = PrettyFormat.NewPlugin; - export type Plugin = PrettyFormat.Plugin; - export type Plugins = PrettyFormat.Plugins; - export type Refs = PrettyFormat.Refs; - export type Theme = PrettyFormat.Theme; -} - -export = prettyFormat; +export default format; diff --git a/scripts/checkCopyrightHeaders.js b/scripts/checkCopyrightHeaders.js index 3972de557871..503c6c8fe5f0 100755 --- a/scripts/checkCopyrightHeaders.js +++ b/scripts/checkCopyrightHeaders.js @@ -20,6 +20,7 @@ const createRegExp = pattern => new RegExp(pattern); const GENERIC_IGNORED_EXTENSIONS = [ 'lock', 'patch', + 'diff', 'exe', 'bin', 'cfg', diff --git a/yarn.lock b/yarn.lock index e07c3ff63ea9..d55a40221f12 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2106,7 +2106,7 @@ __metadata: languageName: unknown linkType: soft -"@jest/types@^26.6.2, @jest/types@workspace:packages/jest-types": +"@jest/types@^26.6.1, @jest/types@^26.6.2, @jest/types@workspace:packages/jest-types": version: 0.0.0-use.local resolution: "@jest/types@workspace:packages/jest-types" dependencies: @@ -16278,6 +16278,18 @@ fsevents@~2.1.2: languageName: unknown linkType: soft +"pretty-format@npm:26.6.1": + version: 26.6.1 + resolution: "pretty-format@npm:26.6.1" + dependencies: + "@jest/types": ^26.6.1 + ansi-regex: ^5.0.0 + ansi-styles: ^4.0.0 + react-is: ^17.0.1 + checksum: a9e31328106e91efde5b49aef7f7b2e668bdaec4a890598bf7ee32560c628738341f5ac5a2985cfbf627e168325492a8c72892b64a0ecea0c9224f93c27f55f2 + languageName: node + linkType: hard + "pretty-format@npm:^24.7.0, pretty-format@npm:^24.9.0": version: 24.9.0 resolution: "pretty-format@npm:24.9.0"