@@ -2,15 +2,16 @@ import type { DiffOptions } from '@vitest/utils/diff'
22import { stripVTControlCharacters } from 'node:util'
33import { processError } from '@vitest/runner'
44import { diff , diffStringsUnified , printDiffOrStringify } from '@vitest/utils/diff'
5- import { expect , test , vi } from 'vitest'
6- import { displayDiff } from '../../../packages/vitest/src/node/error'
5+ import { expect , test } from 'vitest'
6+
7+ function wrapDiff ( diff ?: string ) {
8+ return diff && stripVTControlCharacters ( `\n${ diff } \n` )
9+ }
710
811test ( 'displays string diff' , ( ) => {
912 const stringA = 'Hello AWorld'
1013 const stringB = 'Hello BWorld'
11- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
12- displayDiff ( printDiffOrStringify ( stringA , stringB ) , console as any )
13- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
14+ expect ( wrapDiff ( printDiffOrStringify ( stringA , stringB ) ) ) . toMatchInlineSnapshot ( `
1415 "
1516 Expected: "Hello BWorld"
1617 Received: "Hello AWorld"
@@ -21,9 +22,7 @@ test('displays string diff', () => {
2122test ( 'displays object diff' , ( ) => {
2223 const objectA = { a : 1 , b : 2 }
2324 const objectB = { a : 1 , b : 3 }
24- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
25- displayDiff ( diff ( objectA , objectB ) , console as any )
26- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
25+ expect ( wrapDiff ( diff ( objectA , objectB ) ) ) . toMatchInlineSnapshot ( `
2726 "
2827 - Expected
2928 + Received
@@ -40,9 +39,7 @@ test('displays object diff', () => {
4039test ( 'display truncated object diff' , ( ) => {
4140 const objectA = { a : 1 , b : 2 , c : 3 , d : 4 , e : 5 }
4241 const objectB = { a : 1 , b : 3 , c : 4 , d : 5 , e : 6 }
43- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
44- displayDiff ( diff ( objectA , objectB , { truncateThreshold : 4 } ) , console as any )
45- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
42+ expect ( wrapDiff ( diff ( objectA , objectB , { truncateThreshold : 4 } ) ) ) . toMatchInlineSnapshot ( `
4643 "
4744 - Expected
4845 + Received
@@ -61,9 +58,7 @@ test('display truncated object diff', () => {
6158test ( 'display one line string diff' , ( ) => {
6259 const string1 = 'string1'
6360 const string2 = 'string2'
64- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
65- displayDiff ( diff ( string1 , string2 ) , console as any )
66- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
61+ expect ( wrapDiff ( diff ( string1 , string2 ) ) ) . toMatchInlineSnapshot ( `
6762 "
6863 - Expected
6964 + Received
@@ -77,9 +72,7 @@ test('display one line string diff', () => {
7772test ( 'display one line string diff should not be affected by truncateThreshold' , ( ) => {
7873 const string1 = 'string1'
7974 const string2 = 'string2'
80- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
81- displayDiff ( diff ( string1 , string2 , { truncateThreshold : 3 } ) , console as any )
82- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
75+ expect ( wrapDiff ( diff ( string1 , string2 , { truncateThreshold : 3 } ) ) ) . toMatchInlineSnapshot ( `
8376 "
8477 - Expected
8578 + Received
@@ -93,9 +86,7 @@ test('display one line string diff should not be affected by truncateThreshold',
9386test ( 'display multiline string diff' , ( ) => {
9487 const string1 = 'string1\nstring2\nstring3'
9588 const string2 = 'string2\nstring2\nstring1'
96- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
97- displayDiff ( diff ( string1 , string2 ) , console as any )
98- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
89+ expect ( wrapDiff ( diff ( string1 , string2 ) ) ) . toMatchInlineSnapshot ( `
9990 "
10091 - Expected
10192 + Received
@@ -112,9 +103,7 @@ test('display multiline string diff', () => {
112103test ( 'display truncated multiline string diff' , ( ) => {
113104 const string1 = 'string1\nstring2\nstring3'
114105 const string2 = 'string2\nstring2\nstring1'
115- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
116- displayDiff ( diff ( string1 , string2 , { truncateThreshold : 2 } ) , console as any )
117- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
106+ expect ( wrapDiff ( diff ( string1 , string2 , { truncateThreshold : 2 } ) ) ) . toMatchInlineSnapshot ( `
118107 "
119108 - Expected
120109 + Received
@@ -130,9 +119,7 @@ test('display truncated multiline string diff', () => {
130119test ( 'display truncated multiple items array diff' , ( ) => {
131120 const array1 = Array . from ( { length : 45000 } ) . fill ( 'foo' )
132121 const array2 = Array . from ( { length : 45000 } ) . fill ( 'bar' )
133- const console = { log : vi . fn ( ) , error : vi . fn ( ) }
134- displayDiff ( diff ( array1 , array2 , { truncateThreshold : 3 } ) , console as any )
135- expect ( stripVTControlCharacters ( console . error . mock . calls [ 0 ] [ 0 ] ) ) . toMatchInlineSnapshot ( `
122+ expect ( wrapDiff ( diff ( array1 , array2 , { truncateThreshold : 3 } ) ) ) . toMatchInlineSnapshot ( `
136123 "
137124 - Expected
138125 + Received
0 commit comments