From eb5d6804544423f7fbd1bbd3206386cb603363ea Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Mon, 1 Apr 2024 12:39:17 +0900 Subject: [PATCH] fix(vitest): check unhighlighted code for code frame skip limit --- packages/vitest/src/node/error.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/node/error.ts b/packages/vitest/src/node/error.ts index d4e94fb7018f..610838dcb1d2 100644 --- a/packages/vitest/src/node/error.ts +++ b/packages/vitest/src/node/error.ts @@ -5,6 +5,7 @@ import c from 'picocolors' import cliTruncate from 'cli-truncate' import type { StackTraceParserOptions } from '@vitest/utils/source-map' import { inspect } from '@vitest/utils' +import stripAnsi from 'strip-ansi' import type { ErrorWithDiff, ParsedStack } from '../types' import { lineSplitRE, parseErrorStacktrace, positionToOffset } from '../utils/source-map' import { F_POINTER } from '../utils/figures' @@ -290,7 +291,7 @@ export function generateCodeFrame( const lineLength = lines[j].length // to long, maybe it's a minified file, skip for codeframe - if (lineLength > 200) + if (stripAnsi(lines[j]).length > 200) return '' res.push(lineNo(j + 1) + cliTruncate(lines[j].replace(/\t/g, ' '), columns - 5 - indent))