Skip to content

Commit

Permalink
chore: migrate pretty-format to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 4, 2020
1 parent 30b6cee commit 341f941
Show file tree
Hide file tree
Showing 41 changed files with 191 additions and 121 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
### Fixes

- `[jest-transform]` Show enhanced `SyntaxError` message for all `SyntaxError`s ([#10749](https://github.com/facebook/jest/pull/10749))
- `[pretty-format]` [**BREAKING**] Convert to ES Modules ([#10515](https://github.com/facebook/jest/pull/10515))

### Chore & Maintenance

Expand Down
2 changes: 1 addition & 1 deletion docs/JestPlatform.md
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -141,6 +141,7 @@
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
},
"resolutions": {
"@testing-library/dom": "patch:@testing-library/dom@*#./patches/dom-testing.diff",
"@types/jest/jest-diff": "^25.1.0",
"@types/jest/pretty-format": "^25.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/formatNodeAssertErrors.ts
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/utils.ts
Expand Up @@ -13,7 +13,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'});
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/Deprecated.ts
Expand Up @@ -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});

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-diff/README.md
Expand Up @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-diff/src/index.ts
Expand Up @@ -7,7 +7,10 @@

import chalk = require('chalk');
import getType = require('jest-get-type');
import prettyFormat = require('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';
Expand All @@ -33,7 +36,7 @@ const {
Immutable,
ReactElement,
ReactTestComponent,
} = prettyFormat.plugins;
} = prettyFormatPlugins;

const PLUGINS = [
ReactTestComponent,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/__tests__/array.test.ts
Expand Up @@ -6,7 +6,7 @@
*
*/

import pretty = require('pretty-format');
import {format as pretty} from 'pretty-format';
import each from '../';

const noop = () => {};
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/table/array.ts
Expand Up @@ -8,7 +8,7 @@

import * as util from 'util';
import type {Global} from '@jest/types';
import pretty = require('pretty-format');
import {format as pretty} from 'pretty-format';
import type {EachTests} from '../bind';

const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp%]/g;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/table/template.ts
Expand Up @@ -8,7 +8,7 @@

import type {Global} from '@jest/types';
import {isPrimitive} from 'jest-get-type';
import pretty = require('pretty-format');
import {format as pretty} from 'pretty-format';
import type {EachTests} from '../bind';

type Template = Record<string, unknown>;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/validation.ts
Expand Up @@ -8,7 +8,7 @@

import chalk = require('chalk');
import type {Global} from '@jest/types';
import pretty = require('pretty-format');
import {format as pretty} from 'pretty-format';

type TemplateData = Global.TemplateData;

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/expectationResultFactory.ts
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/isError.ts
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-leak-detector/src/index.ts
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-matcher-utils/src/__tests__/index.test.ts
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-matcher-utils/src/index.ts
Expand Up @@ -18,7 +18,10 @@ import diffDefault, {
diffStringsUnified,
} from 'jest-diff';
import getType = require('jest-get-type');
import prettyFormat = require('pretty-format');
import {
format as prettyFormat,
plugins as prettyFormatPlugins,
} from 'pretty-format';
import Replaceable from './Replaceable';
import deepCyclicCopyReplaceable from './deepCyclicCopyReplaceable';

Expand All @@ -29,7 +32,7 @@ const {
Immutable,
ReactElement,
ReactTestComponent,
} = prettyFormat.plugins;
} = prettyFormatPlugins;

const PLUGINS = [
ReactTestComponent,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-message-util/src/index.ts
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-serializer/src/__tests__/index.test.ts
Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-snapshot/src/__tests__/dedentLines.test.ts
Expand Up @@ -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');
Expand Down
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/__tests__/printSnapshot.test.ts
Expand Up @@ -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,
Expand Down
14 changes: 9 additions & 5 deletions packages/jest-snapshot/src/plugins.ts
Expand Up @@ -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 {
Expand All @@ -15,9 +19,9 @@ const {
ReactElement,
ReactTestComponent,
AsymmetricMatcher,
} = prettyFormat.plugins;
} = prettyFormatPlugins;

let PLUGINS: prettyFormat.Plugins = [
let PLUGINS: PrettyFormatPlugins = [
ReactTestComponent,
ReactElement,
DOMElement,
Expand All @@ -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;
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/printSnapshot.ts
Expand Up @@ -33,7 +33,7 @@ import {
getLabelPrinter,
matcherHint,
} from 'jest-matcher-utils';
import prettyFormat = require('pretty-format');
import prettyFormat from 'pretty-format';
import {
aBackground2,
aBackground3,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/utils.ts
Expand Up @@ -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';

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-validate/src/__tests__/fixtures/jestConfig.ts
Expand Up @@ -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<string, any>) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-validate/src/utils.ts
Expand Up @@ -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`;
Expand Down

0 comments on commit 341f941

Please sign in to comment.