From 16bfc7e68a7362458096bec8022706ca56d5a7a4 Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Thu, 29 Apr 2021 16:38:41 -0400 Subject: [PATCH 1/2] Use named import from pretty-format, not default --- packages/jest-circus/src/formatNodeAssertErrors.ts | 2 +- packages/jest-circus/src/utils.ts | 2 +- packages/jest-config/src/Deprecated.ts | 2 +- packages/jest-core/src/runGlobalHook.ts | 2 +- packages/jest-diff/src/index.ts | 5 ++++- packages/jest-each/src/table/array.ts | 2 +- packages/jest-each/src/table/template.ts | 2 +- packages/jest-each/src/validation.ts | 2 +- packages/jest-jasmine2/src/expectationResultFactory.ts | 2 +- packages/jest-jasmine2/src/isError.ts | 2 +- packages/jest-leak-detector/src/index.ts | 2 +- packages/jest-matcher-utils/src/__tests__/index.test.ts | 2 +- packages/jest-matcher-utils/src/index.ts | 5 ++++- packages/jest-message-util/src/index.ts | 2 +- packages/jest-serializer/src/__tests__/index.test.ts | 2 +- packages/jest-snapshot/src/__tests__/mockSerializer.test.ts | 2 +- packages/jest-snapshot/src/printSnapshot.ts | 2 +- packages/jest-snapshot/src/utils.ts | 2 +- packages/jest-validate/src/utils.ts | 2 +- 19 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/jest-circus/src/formatNodeAssertErrors.ts b/packages/jest-circus/src/formatNodeAssertErrors.ts index aef7dd9fb47f..9c5216869189 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 from 'pretty-format'; +import {format as 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 7d4c43b1088b..faeb9dab00aa 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, Global} from '@jest/types'; import {ErrorWithStack, convertDescriptorToString, formatTime} from 'jest-util'; -import prettyFormat from 'pretty-format'; +import {format as 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 5439ceee0a3f..86aa2222c8a4 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 from 'pretty-format'; +import {format as prettyFormat} from 'pretty-format'; const format = (value: unknown) => prettyFormat(value, {min: true}); diff --git a/packages/jest-core/src/runGlobalHook.ts b/packages/jest-core/src/runGlobalHook.ts index 10e817e4829c..02aac73f0c10 100644 --- a/packages/jest-core/src/runGlobalHook.ts +++ b/packages/jest-core/src/runGlobalHook.ts @@ -12,7 +12,7 @@ import {createScriptTransformer} from '@jest/transform'; import type {Config} from '@jest/types'; import type {Test} from 'jest-runner'; import {interopRequireDefault} from 'jest-util'; -import prettyFormat from 'pretty-format'; +import {format as prettyFormat} from 'pretty-format'; export default async ({ allTests, diff --git a/packages/jest-diff/src/index.ts b/packages/jest-diff/src/index.ts index 010af4d04f0b..24d9ce71cc28 100644 --- a/packages/jest-diff/src/index.ts +++ b/packages/jest-diff/src/index.ts @@ -7,7 +7,10 @@ import chalk = require('chalk'); import {getType} from 'jest-get-type'; -import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format'; +import { + format as 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'; diff --git a/packages/jest-each/src/table/array.ts b/packages/jest-each/src/table/array.ts index 5bee8ee47b59..d8b3daf9661c 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 from 'pretty-format'; +import {format as 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 ad0cacca28fc..68c19616c797 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 from 'pretty-format'; +import {format as 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 5b7e5a9eee3a..3355023150ff 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 from 'pretty-format'; +import {format as 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 86069b1d633c..fec55f2a7b55 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 from 'pretty-format'; +import {format as 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 72a77f0aa844..05f68725e4e5 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 from 'pretty-format'; +import {format as 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 232c00425348..65ca08841604 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 from 'pretty-format'; +import {format as 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 d02c16de4cb1..62abb4db61e0 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 from 'pretty-format'; +import {format as 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 d1fa946db3a0..a1df63d92b19 100644 --- a/packages/jest-matcher-utils/src/index.ts +++ b/packages/jest-matcher-utils/src/index.ts @@ -18,7 +18,10 @@ import diffDefault, { diffStringsUnified, } from 'jest-diff'; import {getType, isPrimitive} from 'jest-get-type'; -import prettyFormat, {plugins as prettyFormatPlugins} from 'pretty-format'; +import { + format as prettyFormat, + plugins as prettyFormatPlugins, +} from 'pretty-format'; import Replaceable from './Replaceable'; import deepCyclicCopyReplaceable from './deepCyclicCopyReplaceable'; diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index 7fc130c66ed2..d838b86b23fd 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 from 'pretty-format'; +import {format as 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 8c3a67781735..09b9b852910c 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 from 'pretty-format'; +import {format as prettyFormat} from 'pretty-format'; import serializer from '..'; const objs = [ diff --git a/packages/jest-snapshot/src/__tests__/mockSerializer.test.ts b/packages/jest-snapshot/src/__tests__/mockSerializer.test.ts index 95e62b770167..6ad4224440b7 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 from 'pretty-format'; +import {format as prettyFormat} from 'pretty-format'; import plugin from '../mockSerializer'; test('mock with 0 calls and default name', () => { diff --git a/packages/jest-snapshot/src/printSnapshot.ts b/packages/jest-snapshot/src/printSnapshot.ts index 629424d3700c..1d3af52ac865 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 from 'pretty-format'; +import {format as prettyFormat} from 'pretty-format'; import { aBackground2, aBackground3, diff --git a/packages/jest-snapshot/src/utils.ts b/packages/jest-snapshot/src/utils.ts index ac20dfd9aa80..fa8b22cb1d45 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 from 'pretty-format'; +import {format as prettyFormat} from 'pretty-format'; import {getSerializers} from './plugins'; import type {SnapshotData} from './types'; diff --git a/packages/jest-validate/src/utils.ts b/packages/jest-validate/src/utils.ts index 169aab829df0..569861a904b9 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 from 'pretty-format'; +import {format as prettyFormat} from 'pretty-format'; const BULLET: string = chalk.bold('\u25cf'); export const DEPRECATION = `${BULLET} Deprecation Warning`; From e5f10f7fcaffb9c464ea6be0487f0ed4086b8b6c Mon Sep 17 00:00:00 2001 From: Ian VanSchooten Date: Thu, 29 Apr 2021 16:51:07 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b12641b6f14..46646173719b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ - `[pretty-format]` [**BREAKING**] Convert to ES Modules ([#10515](https://github.com/facebook/jest/pull/10515)) - `[pretty-format]` Only call `hasAttribute` if it's a function ([#11000](https://github.com/facebook/jest/pull/11000)) - `[pretty-format]` Handle jsdom attributes properly ([#11189](https://github.com/facebook/jest/pull/11189)) +- `[pretty-format]` Import pretty-format using named imports ([#11360](https://github.com/facebook/jest/pull/11360)) ### Chore & Maintenance