From f35a8010f31073c11c9eaf75305fb35f5feb7f9d Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 3 Mar 2019 13:41:59 +0100 Subject: [PATCH 1/2] chore: export `DiffOptions` from `jest-diff` --- packages/jest-circus/package.json | 1 - packages/jest-circus/src/formatNodeAssertErrors.ts | 10 ++++++---- packages/jest-circus/tsconfig.json | 1 - packages/jest-diff/src/index.ts | 13 +++++++++---- packages/jest-matcher-utils/src/index.ts | 4 +++- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index f946c2a14f49..900ef052e55a 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -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": { diff --git a/packages/jest-circus/src/formatNodeAssertErrors.ts b/packages/jest-circus/src/formatNodeAssertErrors.ts index 8310f8fac781..9fa8f0031dd2 100644 --- a/packages/jest-circus/src/formatNodeAssertErrors.ts +++ b/packages/jest-circus/src/formatNodeAssertErrors.ts @@ -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[2]; - interface AssertionErrorWithStack extends AssertionError { stack: string; } diff --git a/packages/jest-circus/tsconfig.json b/packages/jest-circus/tsconfig.json index 8da1643828ba..979ba4e24667 100644 --- a/packages/jest-circus/tsconfig.json +++ b/packages/jest-circus/tsconfig.json @@ -5,7 +5,6 @@ "rootDir": "src" }, "references": [ - {"path": "../jest-diff"}, {"path": "../jest-each"}, {"path": "../jest-environment"}, {"path": "../jest-matcher-utils"}, diff --git a/packages/jest-diff/src/index.ts b/packages/jest-diff/src/index.ts index 176a8cbd5d38..8bcfa54b96e5 100644 --- a/packages/jest-diff/src/index.ts +++ b/packages/jest-diff/src/index.ts @@ -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, @@ -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; } @@ -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), @@ -112,7 +112,7 @@ function sortSet(set: Set) { 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; @@ -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; diff --git a/packages/jest-matcher-utils/src/index.ts b/packages/jest-matcher-utils/src/index.ts index 69c681ffb345..75e4b53bdcf2 100644 --- a/packages/jest-matcher-utils/src/index.ts +++ b/packages/jest-matcher-utils/src/index.ts @@ -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 { @@ -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; From 5610139f9c3aa6fe08f426ed15daa154ce4ebc53 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 3 Mar 2019 13:44:01 +0100 Subject: [PATCH 2/2] link to PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01505a96598d..9d328e2a912c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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))