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

Large diffs do not show #2519

Closed
6 tasks done
silverwind opened this issue Dec 16, 2022 · 7 comments · Fixed by #2522
Closed
6 tasks done

Large diffs do not show #2519

silverwind opened this issue Dec 16, 2022 · 7 comments · Fixed by #2522

Comments

@silverwind
Copy link
Contributor

silverwind commented Dec 16, 2022

Describe the bug

vitest does not render large object diffs. The config options outputDiffLines: Infinity, and outputTruncateLength: Infinity seem to have no effect, it shows this unhelpful message with no diff visible at all:

AssertionError: expected [ Array(500) ] to deeply equal [ Array(500) ]

Reproduction

https://github.com/silverwind/vitest-diff

Clone, npm install and npx vitest yields this unhelpful output:

 RUN  v0.25.8 /Users/silverwind/git/vitest-diff

 ❯ test.js (1)
   × diff

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test.js > diff
AssertionError: expected [ Array(500) ] to deeply equal [ Array(500) ]
 ❯ test.js:6:13
      4|   const a = JSON.parse(readFileSync(new URL("a.json", import.meta.url), "utf8"));
      5|   const b = JSON.parse(readFileSync(new URL("b.json", import.meta.url), "utf8"));
      6|   expect(a).toEqual(b);
       |             ^
      7| });
      8|



⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

 Test Files  1 failed (1)
      Tests  1 failed (1)
   Start at  13:09:01
   Duration  1.28s (transform 339ms, setup 0ms, collect 3ms, tests 56ms)

System Info

System:
    OS: macOS 13.0.1
    CPU: (8) x64 Intel(R) Core(TM) i7-1060NG7 CPU @ 1.20GHz
    Memory: 153.65 MB / 16.00 GB
    Shell: 5.9 - /usr/local/bin/zsh
  Binaries:
    Node: 19.2.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.19.3 - /usr/local/bin/npm
  npmPackages:
    vitest: 0.25.8 => 0.25.8

Used Package Manager

npm

Validations

@silverwind silverwind changed the title Large diffs do not show at all Large diffs do not show Dec 16, 2022
@silverwind
Copy link
Contributor Author

Thanks for the new options. I updated the repro and it does at least now render part of the diff, although it is pretty slow, took around 20 seconds to produce the output on my machine.

Still, it's only rendering part of the diff, and it's hiding 4951 lines, is it expected?

  - Expected  - 1500
  + Received  + 1500

      Object {
        "address": Object {
  -       "city": "Sandoná",
  -       "street": "35539 Nolan Lights",
  +       "city": "Vatican City",
  +       "street": "95452 Davion Grove",
        },
  -     "full name": "Hilda Labadie",
  +     "full name": "Corey Maggio",
      },
      Object {
        "address": Object {
  -       "city": "Benkovac",
  -       "street": "1515 Dietrich Lights",
  +       "city": "Thaton",
  +       "street": "8704 Trey Motorway",
        },
  -     "full name": "Stacy Lakin",
  +     "full name": "Kelvin Jaskolski",
      },
      Object {
        "address": Object {
  -       "city": "Pizitou",
  -       "street": "84570 Jay Fall",
  +       "city": "Iriba",
  +       "street": "89217 Hyatt Dale",
        },
  -     "full name": "Lana Klocko",
  +     "full name": "Connie Considine",
      },
      Object {
        "address": Object {
  -       "city": "Grenville",
  -       "street": "73389 Stamm Land",
  +       "city": "As Samawah",
  +       "street": "2630 Sincere Avenue",
        },
  -     "full name": "Louis Jones",
  +     "full name": "Tabitha Nikolaus",
      },
      Object {
        "address": Object {
  -       "city": "Quruqsoy",
  -       "street": "674 Kreiger Avenue",
  +       "city": "La Fermina",
  +       "street": "760 Gillian Prairie",
        },
  -     "full name": "Gerard Mills",
  +     "full name": "Claire D'Amore",
  ... 4951 more lines

@sheremet-va
Copy link
Member

Yes, look into the new options to display more.

@sheremet-va
Copy link
Member

We are comparing objects as strings, and it is very slow, yes. This is why it’s nor enabled by default.

@silverwind
Copy link
Contributor Author

silverwind commented Dec 20, 2022

The new options are already all set to Infinity, so that seems to not be enough to show all lines.

Regarding text diff performance, I had good experience with jsdiff diffLines, maybe worth looking into.

@sheremet-va
Copy link
Member

sheremet-va commented Dec 20, 2022

The new options are already all set to Infinity, so that seems to not be enough to show all lines.

I forgot to pass them down 🤦🏻 --outputDiffMaxLines is the one you need here.

@sheremet-va
Copy link
Member

#2828 removes these options - please, let me know if it works for you

@silverwind
Copy link
Contributor Author

silverwind commented Feb 8, 2023

Does it mean that diffs will not be cut down by any arbitrary limits any more and will always show in full? If so I'm happy to accept that, as it reduces my config.

Imho, the default should be unopinionated and just show everything. If users have specific cases where diff gets too large, they can limit it themselves if the new diff package support such a mechanism, but I see that as a completely optional effort on vitest's side to support it.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants