Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source code missing in reporters on error, when certain line width is reached, very inconsistent #5431

Closed
6 tasks done
jkavalec opened this issue Mar 26, 2024 · 1 comment · Fixed by #5465
Closed
6 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@jkavalec
Copy link

jkavalec commented Mar 26, 2024

Describe the bug

Using Vitest Basic and Default reporters, there is issue where source showing code where error occurred is not displayed upon reaching certain width (this happens also when error line is short, but subsequent line is long enough).

Another issue is that this behavior is not consistent, as for instance string assertion with around 150 chars shows (breaks at 152), while array literal assertion breaks before 80

Reproduction

I tried it on Vitest examples Basic example, just inserting following assertions, using Default and Basic reporters

  // long assertion works
  expect('test test test test test test test test test test test test test test test test test test test test test test test test test').toBe('test')
  
  // until caret at end of line is at position 152 in this case
  expect('test test test test test test test test test test test test test test test test test test test test test test test test test t').toBe('test')

  // it starts working when assertion clause is moved to next line
  expect('test test test test test test test test test test test test test test test test test test test test test test test test test t')
  .toBe('test')

  // here inconsistency shows, as array literal like this works
  expect([{prop: 7}, {prop: 7}, {prop: 7}]).toBe([{another: 8} ])

  // yet it stops working when it is significantly shorter than long string assertion example no.1
  // here failing even before reaching column 80
  expect([{prop: 7}, {prop: 7}, {prop: 7}, {prop: 7}]).toBe([{another: 8} ])

  // working again when line-break is inserted
  expect([{prop: 7}, {prop: 7}, {prop: 7}, {prop: 7}])
  .toBe([{another: 8} ])
  expect(
    [{prop: 7}, {prop: 7}, {prop: 7}, {prop: 7}]
    ).toBe([{another: 8} ])

System Info

tried Vitest 1.3.1 and 1.4.0

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Apr 1, 2024

It looks like this is because of the following 200 limit is checked again highlighted code, which includes ANSI color codes and the amount such code depends on the code. For example, your array example switches colors more often than simple string, so the ANSI code length adds up quickly. Btw, I updated your code to add "ts" highlight.

// to long, maybe it's a minified file, skip for codeframe
if (lineLength > 200)
return ''

@hi-ogawa hi-ogawa added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Apr 1, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants