Skip to content

Commit 9c7ea38

Browse files
authored
fix: revert concordance diff, use jest's diff output (#3582)
1 parent d9e1419 commit 9c7ea38

28 files changed

+1933
-310
lines changed

packages/expect/src/jest-expect.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
186186
'expected #{this} to be truthy',
187187
'expected #{this} to not be truthy',
188188
obj,
189+
false,
189190
)
190191
})
191192
def('toBeFalsy', function () {
@@ -195,6 +196,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
195196
'expected #{this} to be falsy',
196197
'expected #{this} to not be falsy',
197198
obj,
199+
false,
198200
)
199201
})
200202
def('toBeGreaterThan', function (expected: number | bigint) {
@@ -207,6 +209,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
207209
`expected ${actual} to be not greater than ${expected}`,
208210
actual,
209211
expected,
212+
false,
210213
)
211214
})
212215
def('toBeGreaterThanOrEqual', function (expected: number | bigint) {
@@ -219,6 +222,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
219222
`expected ${actual} to be not greater than or equal to ${expected}`,
220223
actual,
221224
expected,
225+
false,
222226
)
223227
})
224228
def('toBeLessThan', function (expected: number | bigint) {
@@ -231,6 +235,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
231235
`expected ${actual} to be not less than ${expected}`,
232236
actual,
233237
expected,
238+
false,
234239
)
235240
})
236241
def('toBeLessThanOrEqual', function (expected: number | bigint) {
@@ -243,6 +248,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
243248
`expected ${actual} to be not less than or equal to ${expected}`,
244249
actual,
245250
expected,
251+
false,
246252
)
247253
})
248254
def('toBeNaN', function () {
@@ -328,6 +334,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
328334
`expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
329335
received,
330336
expected,
337+
false,
331338
)
332339
})
333340

@@ -356,10 +363,10 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
356363
}
357364
const formatCalls = (spy: EnhancedSpy, msg: string, actualCall?: any) => {
358365
if (spy.mock.calls) {
359-
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
360-
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
366+
msg += c().gray(`\n\nReceived: \n\n${spy.mock.calls.map((callArg, i) => {
367+
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
361368
if (actualCall)
362-
methodCall += diff(actualCall, callArg, { showLegend: false })
369+
methodCall += diff(actualCall, callArg, { omitAnnotationLines: true })
363370
else
364371
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')
365372
@@ -371,10 +378,10 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
371378
return msg
372379
}
373380
const formatReturns = (spy: EnhancedSpy, msg: string, actualReturn?: any) => {
374-
msg += c().gray(`\n\nReceived: \n${spy.mock.results.map((callReturn, i) => {
375-
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`)
381+
msg += c().gray(`\n\nReceived: \n\n${spy.mock.results.map((callReturn, i) => {
382+
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`)
376383
if (actualReturn)
377-
methodCall += diff(actualReturn, callReturn.value, { showLegend: false })
384+
methodCall += diff(actualReturn, callReturn.value, { omitAnnotationLines: true })
378385
else
379386
methodCall += stringify(callReturn).split('\n').map(line => ` ${line}`).join('\n')
380387
@@ -394,6 +401,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
394401
`expected "${spyName}" to not be called #{exp} times`,
395402
number,
396403
callCount,
404+
false,
397405
)
398406
})
399407
def('toHaveBeenCalledOnce', function () {
@@ -406,6 +414,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
406414
`expected "${spyName}" to not be called once`,
407415
1,
408416
callCount,
417+
false,
409418
)
410419
})
411420
def(['toHaveBeenCalled', 'toBeCalled'], function () {
@@ -525,6 +534,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
525534
`expected error not to be instance of ${name}`,
526535
expected,
527536
thrown,
537+
false,
528538
)
529539
}
530540

@@ -546,6 +556,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
546556
'expected error not to match asymmetric matcher',
547557
matcher.toString(),
548558
thrown,
559+
false,
549560
)
550561
}
551562

@@ -561,6 +572,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
561572
`expected "${spyName}" to not be successfully called`,
562573
calledAndNotThrew,
563574
!calledAndNotThrew,
575+
false,
564576
)
565577
})
566578
def(['toHaveReturnedTimes', 'toReturnTimes'], function (times: number) {
@@ -573,6 +585,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
573585
`expected "${spyName}" to not be successfully called ${times} times`,
574586
`expected number of returns: ${times}`,
575587
`received number of returns: ${successfulReturns}`,
588+
false,
576589
)
577590
})
578591
def(['toHaveReturnedWith', 'toReturnWith'], function (value: any) {

packages/expect/src/jest-matcher-utils.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getColors, stringify } from '@vitest/utils'
2-
import { unifiedDiff } from '@vitest/utils/diff'
3-
import type { DiffOptions, MatcherHintOptions } from './types'
2+
import type { MatcherHintOptions } from './types'
43

4+
export { diff } from '@vitest/utils/diff'
55
export { stringify }
66

77
export function getMatcherUtils() {
@@ -101,10 +101,3 @@ export function getMatcherUtils() {
101101
printExpected,
102102
}
103103
}
104-
105-
// TODO: do something with options
106-
export function diff(a: any, b: any, options?: DiffOptions) {
107-
return unifiedDiff(b, a, {
108-
showLegend: options?.showLegend,
109-
})
110-
}

packages/expect/src/types.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export type ChaiPlugin = FirstFunctionArgument<typeof chaiUse>
1717

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

20+
export type { DiffOptions } from '@vitest/utils/diff'
21+
2022
export interface MatcherHintOptions {
2123
comment?: string
2224
expectedColor?: Formatter
@@ -28,29 +30,6 @@ export interface MatcherHintOptions {
2830
secondArgumentColor?: Formatter
2931
}
3032

31-
export interface DiffOptions {
32-
aAnnotation?: string
33-
aColor?: Formatter
34-
aIndicator?: string
35-
bAnnotation?: string
36-
bColor?: Formatter
37-
bIndicator?: string
38-
changeColor?: Formatter
39-
changeLineTrailingSpaceColor?: Formatter
40-
commonColor?: Formatter
41-
commonIndicator?: string
42-
commonLineTrailingSpaceColor?: Formatter
43-
contextLines?: number
44-
emptyFirstOrLastLinePlaceholder?: string
45-
expand?: boolean
46-
includeChangeCounts?: boolean
47-
omitAnnotationLines?: boolean
48-
patchColor?: Formatter
49-
// pretty-format type
50-
compareKeys?: any
51-
showLegend?: boolean
52-
}
53-
5433
export interface MatcherState {
5534
assertionCalls: number
5635
currentTestName?: string

packages/ui/client/components/views/ViewReportError.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script setup lang="ts">
22
import type { ErrorWithDiff } from '#types'
3-
import { unifiedDiff } from '~/composables/diff'
43
import { openInEditor, shouldOpenInEditor } from '~/composables/error'
54
65
const props = defineProps<{
@@ -20,7 +19,7 @@ const isDiffShowable = computed(() => {
2019
})
2120
2221
function diff() {
23-
return unifiedDiff(props.error.actual, props.error.expected)
22+
return props.error.diff
2423
}
2524
</script>
2625

packages/ui/client/composables/diff.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"prepublishOnly": "pnpm build"
4848
},
4949
"dependencies": {
50-
"concordance": "^5.0.4",
50+
"diff-sequences": "^29.4.3",
5151
"loupe": "^2.3.6",
5252
"pretty-format": "^27.5.1"
5353
}

packages/utils/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import pkg from './package.json' assert { type: 'json' }
99
const entries = {
1010
index: 'src/index.ts',
1111
helpers: 'src/helpers.ts',
12-
diff: 'src/diff.ts',
12+
diff: 'src/diff/index.ts',
1313
error: 'src/error.ts',
1414
types: 'src/types.ts',
1515
}

packages/utils/src/descriptors.ts

Lines changed: 0 additions & 98 deletions
This file was deleted.

packages/utils/src/diff.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)