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 Sep 15, 2020
1 parent 23f425c commit 71cb36e
Show file tree
Hide file tree
Showing 37 changed files with 129 additions and 120 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@

### Chore & Maintenance

- `[pretty-format]` [**BREAKING**] Convert to ES Modules ([#10515](https://github.com/facebook/jest/pull/10515))

### Performance

## 26.4.2
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
2 changes: 1 addition & 1 deletion packages/jest-circus/src/formatNodeAssertErrors.ts
Expand Up @@ -14,7 +14,7 @@ import {
printReceived,
} from 'jest-matcher-utils';
import chalk = require('chalk');
import prettyFormat = require('pretty-format');
import {format as 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 @@ -12,7 +12,7 @@ import isGeneratorFn from 'is-generator-fn';
import co from 'co';
import dedent = require('dedent');
import StackUtils = require('stack-utils');
import prettyFormat = require('pretty-format');
import {format as prettyFormat} from 'pretty-format';
import type {AssertionResult, Status} from '@jest/test-result';
import {ROOT_DESCRIBE_BLOCK_NAME, getState} from './state';

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/Deprecated.ts
Expand Up @@ -6,7 +6,7 @@
*/

import chalk = require('chalk');
import prettyFormat = require('pretty-format');
import {format as prettyFormat} from 'pretty-format';
import type {DeprecatedOptions} from 'jest-validate';

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 @@ -5,7 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

import prettyFormat = require('pretty-format');
import {
format as prettyFormat,
plugins as prettyFormatPlugins,
} from 'pretty-format';
import chalk = require('chalk');
import getType = require('jest-get-type');
import {DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff} from './cleanupSemantic';
Expand Down Expand Up @@ -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 @@ -7,7 +7,7 @@
*/

import * as util from 'util';
import pretty = require('pretty-format');
import {format as pretty} from 'pretty-format';

import type {Global} from '@jest/types';
import type {EachTests} from '../bind';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/table/template.ts
Expand Up @@ -6,7 +6,7 @@
*
*/

import pretty = require('pretty-format');
import {format as pretty} from 'pretty-format';
import {isPrimitive} from 'jest-get-type';
import type {Global} from '@jest/types';
import type {EachTests} from '../bind';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/validation.ts
Expand Up @@ -7,7 +7,7 @@
*/

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

type TemplateData = Global.TemplateData;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/expectationResultFactory.ts
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import prettyFormat = require('pretty-format');
import {format as prettyFormat} from 'pretty-format';
import type {FailedAssertion} from '@jest/test-result';

function messageFormatter({error, message, passed}: Options) {
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 {format as 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 @@ -10,7 +10,7 @@
import {setFlagsFromString} from 'v8';
import {runInNewContext} from 'vm';
import {promisify} from 'util';
import prettyFormat = require('pretty-format');
import {format as prettyFormat} from 'pretty-format';
import {isPrimitive} from 'jest-get-type';

const tick = promisify(setImmediate);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-matcher-utils/src/__tests__/index.test.ts
Expand Up @@ -7,7 +7,7 @@
*/

import chalk = require('chalk');
import prettyFormat = require('pretty-format');
import {format as prettyFormat} from 'pretty-format';
import {alignedAnsiStyleSerializer} from '@jest/test-utils';
import {
MatcherHintOptions,
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-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 {format as prettyFormat} from 'pretty-format';

import serializer from '..';

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 {format as prettyFormat} from 'pretty-format';

import plugin from '../mock_serializer';

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 jestSnapshot = require('../index');
import {
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 './mock_serializer';

Expand All @@ -16,9 +20,9 @@ const {
ReactElement,
ReactTestComponent,
AsymmetricMatcher,
} = prettyFormat.plugins;
} = prettyFormatPlugins;

let PLUGINS: prettyFormat.Plugins = [
let PLUGINS: PrettyFormatPlugins = [
ReactTestComponent,
ReactElement,
DOMElement,
Expand All @@ -29,8 +33,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 {format as prettyFormat} from 'pretty-format';

import {
aBackground2,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/utils.ts
Expand Up @@ -10,7 +10,7 @@ import * as fs from 'graceful-fs';
import naturalCompare = require('natural-compare');
import chalk = require('chalk');
import type {Config} from '@jest/types';
import prettyFormat = require('pretty-format');
import {format as 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 @@ -6,7 +6,7 @@
*/

import chalk = require('chalk');
import prettyFormat = require('pretty-format');
import {format as prettyFormat} from 'pretty-format';
import leven from 'leven';

const BULLET: string = chalk.bold('\u25cf');
Expand Down

0 comments on commit 71cb36e

Please sign in to comment.