Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make jest-matcher-utils use ESM exports #4342

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/jest-circus/src/format_node_assert_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import type {DiffOptions} from 'jest-diff/src/diff_strings.js';
import type {Event, State} from 'types/Circus';

const {printReceived, printExpected} = require('jest-matcher-utils');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seemed weird to use require here, but maybe on purpose?

const chalk = require('chalk');
const diff = require('jest-diff');
import {printExpected, printReceived} from 'jest-matcher-utils';
import chalk from 'chalk';
import diff from 'jest-diff';

type AssertionError = {|
actual: ?string,
Expand Down
1 change: 0 additions & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"jest-environment-node": "^20.0.3",
"jest-get-type": "^20.0.3",
"jest-jasmine2": "^20.0.4",
"jest-matcher-utils": "^20.0.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither this nor jest-diff actually used it...

"jest-regex-util": "^20.0.3",
"jest-resolve": "^20.0.4",
"jest-util": "^20.0.3",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"dependencies": {
"chalk": "^2.0.1",
"diff": "^3.2.0",
"jest-matcher-utils": "^20.0.3",
"jest-get-type": "^20.0.3",
"pretty-format": "^20.0.3"
}
Expand Down
59 changes: 23 additions & 36 deletions packages/jest-matcher-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const PLUGINS = [
AsymmetricMatcher,
];

const EXPECTED_COLOR = chalk.green;
const EXPECTED_BG = chalk.bgGreen;
const RECEIVED_COLOR = chalk.red;
const RECEIVED_BG = chalk.bgRed;
export const EXPECTED_COLOR = chalk.green;
export const EXPECTED_BG = chalk.bgGreen;
export const RECEIVED_COLOR = chalk.red;
export const RECEIVED_BG = chalk.bgRed;

const NUMBERS = [
'zero',
Expand All @@ -49,11 +49,11 @@ const NUMBERS = [
'thirteen',
];

const SUGGEST_TO_EQUAL = chalk.dim(
export const SUGGEST_TO_EQUAL = chalk.dim(
'Looks like you wanted to test for object/array equality with strict `toBe` matcher. You probably need to use `toEqual` instead.',
);

const stringify = (object: any, maxDepth?: number = 10): string => {
export const stringify = (object: any, maxDepth?: number = 10): string => {
const MAX_LENGTH = 10000;
let result;

Expand All @@ -77,15 +77,17 @@ const stringify = (object: any, maxDepth?: number = 10): string => {
: result;
};

const highlightTrailingWhitespace = (text: string, bgColor: Function): string =>
text.replace(/\s+$/gm, bgColor('$&'));
export const highlightTrailingWhitespace = (
text: string,
bgColor: Function,
): string => text.replace(/\s+$/gm, bgColor('$&'));

const printReceived = (object: any) =>
export const printReceived = (object: any) =>
highlightTrailingWhitespace(RECEIVED_COLOR(stringify(object)), RECEIVED_BG);
const printExpected = (value: any) =>
export const printExpected = (value: any) =>
highlightTrailingWhitespace(EXPECTED_COLOR(stringify(value)), EXPECTED_BG);

const printWithType = (
export const printWithType = (
name: string,
received: any,
print: (value: any) => string,
Expand All @@ -99,7 +101,7 @@ const printWithType = (
);
};

const ensureNoExpected = (expected: any, matcherName: string) => {
export const ensureNoExpected = (expected: any, matcherName: string) => {
matcherName || (matcherName = 'This');
if (typeof expected !== 'undefined') {
throw new Error(
Expand All @@ -111,7 +113,7 @@ const ensureNoExpected = (expected: any, matcherName: string) => {
}
};

const ensureActualIsNumber = (actual: any, matcherName: string) => {
export const ensureActualIsNumber = (actual: any, matcherName: string) => {
matcherName || (matcherName = 'This matcher');
if (typeof actual !== 'number') {
throw new Error(
Expand All @@ -123,7 +125,7 @@ const ensureActualIsNumber = (actual: any, matcherName: string) => {
}
};

const ensureExpectedIsNumber = (expected: any, matcherName: string) => {
export const ensureExpectedIsNumber = (expected: any, matcherName: string) => {
matcherName || (matcherName = 'This matcher');
if (typeof expected !== 'number') {
throw new Error(
Expand All @@ -135,15 +137,19 @@ const ensureExpectedIsNumber = (expected: any, matcherName: string) => {
}
};

const ensureNumbers = (actual: any, expected: any, matcherName: string) => {
export const ensureNumbers = (
actual: any,
expected: any,
matcherName: string,
) => {
ensureActualIsNumber(actual, matcherName);
ensureExpectedIsNumber(expected, matcherName);
};

const pluralize = (word: string, count: number) =>
export const pluralize = (word: string, count: number) =>
(NUMBERS[count] || count) + ' ' + word + (count === 1 ? '' : 's');

const matcherHint = (
export const matcherHint = (
matcherName: string,
received: string = 'received',
expected: string = 'expected',
Expand All @@ -163,22 +169,3 @@ const matcherHint = (
chalk.dim(')')
);
};

module.exports = {
EXPECTED_BG,
EXPECTED_COLOR,
RECEIVED_BG,
RECEIVED_COLOR,
SUGGEST_TO_EQUAL,
ensureActualIsNumber,
ensureExpectedIsNumber,
ensureNoExpected,
ensureNumbers,
highlightTrailingWhitespace,
matcherHint,
pluralize,
printExpected,
printReceived,
printWithType,
stringify,
};
2 changes: 1 addition & 1 deletion packages/jest-matchers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
PromiseMatcherFn,
} from 'types/Matchers';

import utils from 'jest-matcher-utils';
import * as utils from 'jest-matcher-utils';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this was the actual error

import matchers from './matchers';
import spyMatchers from './spy_matchers';
import toThrowMatchers from './to_throw_matchers';
Expand Down