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

fix: revert concordance diff, use jest's diff output #3582

Merged
merged 5 commits into from Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 6 additions & 6 deletions packages/expect/src/jest-expect.ts
Expand Up @@ -356,10 +356,10 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
}
const formatCalls = (spy: EnhancedSpy, msg: string, actualCall?: any) => {
if (spy.mock.calls) {
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
msg += c().gray(`\n\nReceived: \n\n${spy.mock.calls.map((callArg, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
if (actualCall)
methodCall += diff(actualCall, callArg, { showLegend: false })
methodCall += diff(actualCall, callArg, { omitAnnotationLines: true })
else
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')

Expand All @@ -371,10 +371,10 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
return msg
}
const formatReturns = (spy: EnhancedSpy, msg: string, actualReturn?: any) => {
msg += c().gray(`\n\nReceived: \n${spy.mock.results.map((callReturn, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`)
msg += c().gray(`\n\nReceived: \n\n${spy.mock.results.map((callReturn, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`)
if (actualReturn)
methodCall += diff(actualReturn, callReturn.value, { showLegend: false })
methodCall += diff(actualReturn, callReturn.value, { omitAnnotationLines: true })
else
methodCall += stringify(callReturn).split('\n').map(line => ` ${line}`).join('\n')

Expand Down
11 changes: 2 additions & 9 deletions packages/expect/src/jest-matcher-utils.ts
@@ -1,7 +1,7 @@
import { getColors, stringify } from '@vitest/utils'
import { unifiedDiff } from '@vitest/utils/diff'
import type { DiffOptions, MatcherHintOptions } from './types'
import type { MatcherHintOptions } from './types'

export { diff } from '@vitest/utils/diff'
export { stringify }

export function getMatcherUtils() {
Expand Down Expand Up @@ -101,10 +101,3 @@ export function getMatcherUtils() {
printExpected,
}
}

// TODO: do something with options
export function diff(a: any, b: any, options?: DiffOptions) {
return unifiedDiff(b, a, {
showLegend: options?.showLegend,
})
}
25 changes: 2 additions & 23 deletions packages/expect/src/types.ts
Expand Up @@ -17,6 +17,8 @@ export type ChaiPlugin = FirstFunctionArgument<typeof chaiUse>

export type Tester = (a: any, b: any) => boolean | undefined

export type { DiffOptions } from '@vitest/utils/diff'

export interface MatcherHintOptions {
comment?: string
expectedColor?: Formatter
Expand All @@ -28,29 +30,6 @@ export interface MatcherHintOptions {
secondArgumentColor?: Formatter
}

export interface DiffOptions {
aAnnotation?: string
aColor?: Formatter
aIndicator?: string
bAnnotation?: string
bColor?: Formatter
bIndicator?: string
changeColor?: Formatter
changeLineTrailingSpaceColor?: Formatter
commonColor?: Formatter
commonIndicator?: string
commonLineTrailingSpaceColor?: Formatter
contextLines?: number
emptyFirstOrLastLinePlaceholder?: string
expand?: boolean
includeChangeCounts?: boolean
omitAnnotationLines?: boolean
patchColor?: Formatter
// pretty-format type
compareKeys?: any
showLegend?: boolean
}

export interface MatcherState {
assertionCalls: number
currentTestName?: string
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/client/components/views/ViewReportError.vue
@@ -1,6 +1,5 @@
<script setup lang="ts">
import type { ErrorWithDiff } from '#types'
import { unifiedDiff } from '~/composables/diff'
import { openInEditor, shouldOpenInEditor } from '~/composables/error'

const props = defineProps<{
Expand All @@ -20,7 +19,7 @@ const isDiffShowable = computed(() => {
})

function diff() {
return unifiedDiff(props.error.actual, props.error.expected)
return props.error.diff
}
</script>

Expand Down
1 change: 0 additions & 1 deletion packages/ui/client/composables/diff.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/utils/package.json
Expand Up @@ -47,7 +47,7 @@
"prepublishOnly": "pnpm build"
},
"dependencies": {
"concordance": "^5.0.4",
"diff-sequences": "^29.4.3",
"loupe": "^2.3.6",
"pretty-format": "^27.5.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/rollup.config.js
Expand Up @@ -9,7 +9,7 @@ import pkg from './package.json' assert { type: 'json' }
const entries = {
index: 'src/index.ts',
helpers: 'src/helpers.ts',
diff: 'src/diff.ts',
diff: 'src/diff/index.ts',
error: 'src/error.ts',
types: 'src/types.ts',
}
Expand Down
98 changes: 0 additions & 98 deletions packages/utils/src/descriptors.ts

This file was deleted.

51 changes: 0 additions & 51 deletions packages/utils/src/diff.ts

This file was deleted.