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

chore: export DiffOptions from jest-diff #8027

Merged
merged 2 commits into from Mar 3, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -44,7 +44,7 @@
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
- `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818))
- `[jest-regex-util]`: Migrate to TypeScript ([#7822](https://github.com/facebook/jest/pull/7822))
- `[jest-diff]`: Migrate to TypeScript ([#7824](https://github.com/facebook/jest/pull/7824))
- `[jest-diff]`: Migrate to TypeScript ([#7824](https://github.com/facebook/jest/pull/7824), [#8027](https://github.com/facebook/jest/pull/8027))
- `[jest-leak-detector]`: Migrate to TypeScript ([#7825](https://github.com/facebook/jest/pull/7825))
- `[jest-changed-files]`: Migrate to TypeScript ([#7827](https://github.com/facebook/jest/pull/7827))
- `[jest-matcher-utils]`: Migrate to TypeScript ([#7835](https://github.com/facebook/jest/pull/7835))
Expand Down
1 change: 0 additions & 1 deletion packages/jest-circus/package.json
Expand Up @@ -33,7 +33,6 @@
"@types/co": "^4.6.0",
"@types/stack-utils": "^1.0.1",
"execa": "^1.0.0",
"jest-diff": "^24.0.0",
"jest-runtime": "^24.1.0"
},
"engines": {
Expand Down
10 changes: 6 additions & 4 deletions packages/jest-circus/src/formatNodeAssertErrors.ts
Expand Up @@ -6,14 +6,16 @@
*/

import {AssertionError} from 'assert';
import {diff, printExpected, printReceived} from 'jest-matcher-utils';
import {
diff,
printExpected,
printReceived,
DiffOptions,
} from 'jest-matcher-utils';
import chalk from 'chalk';
import prettyFormat from 'pretty-format';
import {Event, State, TestError} from './types';

// TODO replace with import {DiffOptions} from 'jest-matcher-utils';
type DiffOptions = Parameters<typeof diff>[2];

interface AssertionErrorWithStack extends AssertionError {
stack: string;
}
Expand Down
1 change: 0 additions & 1 deletion packages/jest-circus/tsconfig.json
Expand Up @@ -5,7 +5,6 @@
"rootDir": "src"
},
"references": [
{"path": "../jest-diff"},
{"path": "../jest-each"},
{"path": "../jest-environment"},
{"path": "../jest-matcher-utils"},
Expand Down
13 changes: 9 additions & 4 deletions packages/jest-diff/src/index.ts
Expand Up @@ -10,7 +10,7 @@ import chalk from 'chalk';
import getType from 'jest-get-type';
import diffStrings from './diffStrings';
import {NO_DIFF_MESSAGE, SIMILAR_MESSAGE} from './constants';
import {DiffOptions} from './types';
import {DiffOptions as JestDiffOptions} from './types';

const {
AsymmetricMatcher,
Expand Down Expand Up @@ -42,7 +42,7 @@ const FALLBACK_FORMAT_OPTIONS_0 = {...FALLBACK_FORMAT_OPTIONS, indent: 0};

// Generate a string that will highlight the difference between two values
// with green and red. (similar to how github does code diffing)
function diff(a: any, b: any, options?: DiffOptions): string | null {
function diff(a: any, b: any, options?: JestDiffOptions): string | null {
if (Object.is(a, b)) {
return NO_DIFF_MESSAGE;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ function diff(a: any, b: any, options?: DiffOptions): string | null {
function comparePrimitive(
a: number | boolean,
b: number | boolean,
options?: DiffOptions,
options?: JestDiffOptions,
) {
return diffStrings(
prettyFormat(a, FORMAT_OPTIONS),
Expand All @@ -112,7 +112,7 @@ function sortSet(set: Set<unknown>) {
return new Set(Array.from(set.values()).sort());
}

function compareObjects(a: Object, b: Object, options?: DiffOptions) {
function compareObjects(a: Object, b: Object, options?: JestDiffOptions) {
let diffMessage;
let hasThrown = false;

Expand Down Expand Up @@ -150,4 +150,9 @@ function compareObjects(a: Object, b: Object, options?: DiffOptions) {
return diffMessage;
}

// eslint-disable-next-line no-redeclare
namespace diff {
export type DiffOptions = JestDiffOptions;
}

export = diff;
4 changes: 3 additions & 1 deletion packages/jest-matcher-utils/src/index.ts
Expand Up @@ -6,7 +6,7 @@
*/

import chalk from 'chalk';
import jestDiff from 'jest-diff';
import jestDiff, {DiffOptions} from 'jest-diff';
import getType from 'jest-get-type';
import prettyFormat from 'pretty-format';
const {
Expand Down Expand Up @@ -35,6 +35,8 @@ export type MatcherHintOptions = {
secondArgument?: string;
};

export {DiffOptions};

export const EXPECTED_COLOR = chalk.green;
export const RECEIVED_COLOR = chalk.red;
export const INVERTED_COLOR = chalk.inverse;
Expand Down