Skip to content

Commit

Permalink
fix: displayDiff with non-string
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 6, 2022
1 parent e27068b commit 61fbddb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Expand Up @@ -113,7 +113,7 @@ const SPACE_SYMBOL = '\u{00B7}' // middle dot
const replaceTrailingSpaces = (text: string): string =>
text.replace(/\s+$/gm, spaces => SPACE_SYMBOL.repeat(spaces.length))

export const stringify = (object: unknown, maxDepth = 10, options?: PrettyFormatOptions): string => {
export function stringify(object: unknown, maxDepth = 10, options?: PrettyFormatOptions): string {
const MAX_LENGTH = 10000
let result

Expand Down
3 changes: 2 additions & 1 deletion packages/vitest/src/node/error.ts
Expand Up @@ -7,6 +7,7 @@ import cliTruncate from 'cli-truncate'
import type { ErrorWithDiff, ParsedStack, Position } from '../types'
import { interpretSourcePos, lineSplitRE, parseStacktrace, posToNumber } from '../utils/source-map'
import { F_POINTER } from '../utils/figures'
import { stringify } from '../integrations/chai/jest-matcher-utils'
import type { Vitest } from './core'
import { unifiedDiff } from './diff'

Expand Down Expand Up @@ -46,7 +47,7 @@ export async function printError(error: unknown, ctx: Vitest) {
handleImportOutsideModuleError(e.stack || e.stackStr || '', ctx)

if (e.showDiff)
displayDiff(e.actual, e.expected, ctx.console, ctx.config.outputTruncateLength)
displayDiff(stringify(e.actual), stringify(e.expected), ctx.console, ctx.config.outputTruncateLength)
}

const esmErrors = [
Expand Down

0 comments on commit 61fbddb

Please sign in to comment.