[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(vitest): check unhighlighted code for code frame line limit (#5465)

authored by

Hiroshi Ogawa and committed by
GitHub
(Apr 1, 2024, 10:46 AM +0200) 6ae7eaa2 e4e939ba

+18 -2
+6
test/reporters/fixtures/code-frame-line-limit.test.ts
··· 1 + import { test, expect } from "vitest" 2 + 3 + test("basic", () => { 4 + // line length is 85 but highlight makes this line 245 chars 5 + expect([{ prop: 7 }, { prop: 7 }, { prop: 7 }, { prop: 7 }]).toBe([{ another: 8 }]) 6 + })
+9
test/reporters/tests/code-frame-line-limit.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + import { resolve } from 'pathe' 3 + import { runVitest } from '../../test-utils' 4 + 5 + test('show code frame', async () => { 6 + const filename = resolve('./fixtures/code-frame-line-limit.test.ts') 7 + const { stderr } = await runVitest({ root: './fixtures' }, [filename]) 8 + expect(stderr).toContain('5| expect([{ prop: 7 },') 9 + })
+3 -2
packages/vitest/src/node/error.ts
··· 5 5 import cliTruncate from 'cli-truncate' 6 6 import type { StackTraceParserOptions } from '@vitest/utils/source-map' 7 7 import { inspect } from '@vitest/utils' 8 + import stripAnsi from 'strip-ansi' 8 9 import type { ErrorWithDiff, ParsedStack } from '../types' 9 10 import { lineSplitRE, parseErrorStacktrace, positionToOffset } from '../utils/source-map' 10 11 import { F_POINTER } from '../utils/figures' ··· 289 290 290 291 const lineLength = lines[j].length 291 292 292 - // to long, maybe it's a minified file, skip for codeframe 293 - if (lineLength > 200) 293 + // too long, maybe it's a minified file, skip for codeframe 294 + if (stripAnsi(lines[j]).length > 200) 294 295 return '' 295 296 296 297 res.push(lineNo(j + 1) + cliTruncate(lines[j].replace(/\t/g, ' '), columns - 5 - indent))