Skip to content

Commit

Permalink
chore: migrate pretty-format to ESM (#10515)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 26, 2020
1 parent 59ae078 commit 034cd34
Show file tree
Hide file tree
Showing 38 changed files with 130 additions and 108 deletions.
13 changes: 7 additions & 6 deletions CHANGELOG.md
Expand Up @@ -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))
Expand All @@ -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

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 @@ -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"
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 @@ -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'});
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
4 changes: 2 additions & 2 deletions packages/jest-diff/src/index.ts
Expand Up @@ -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';
Expand All @@ -33,7 +33,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 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 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 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 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
4 changes: 2 additions & 2 deletions packages/jest-matcher-utils/src/index.ts
Expand Up @@ -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';

Expand All @@ -29,7 +29,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 @@ -34,7 +34,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
17 changes: 9 additions & 8 deletions packages/pretty-format/README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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<any>) => unknown) {
Expand Down
4 changes: 2 additions & 2 deletions packages/pretty-format/src/__tests__/ConvertAnsi.test.ts
Expand Up @@ -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, {
Expand Down

0 comments on commit 034cd34

Please sign in to comment.