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 on snapshots are not truncated #5073

Closed
6 tasks done
kernelwhisperer opened this issue Jan 29, 2024 · 4 comments · Fixed by #5333
Closed
6 tasks done

Large diffs on snapshots are not truncated #5073

kernelwhisperer opened this issue Jan 29, 2024 · 4 comments · Fixed by #5333
Labels
enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome

Comments

@kernelwhisperer
Copy link

Describe the bug

I'm using expect(result).toMatchSnapshot() on a large array resulting in a 45.000 line snapshot.

The issue is that it takes a very long time for the test runner to display the diff inside the terminal.

I was expecting the output to be truncated, using the default value of chaiConfig.truncateThreshold, but the full diff is printed instead.

I've also tried using chaiConfig: { showDiff: false } which seems to have no effect.

Reproduction

Is this really needed?

I've went searching through the issues, my hunch is that snapshot diffing works differently and it ignores chaiConfig.

System Info

WSL 2 Ubuntu - vitest 1.2.2

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Jan 29, 2024

Is this really needed?

Yes, it is!

chaiConfig is not used for snapshots and never was because snapshots is not a chai feature.

Snapshots should show only changed lines, we use jest's diff display. Unless your whole snapshot is different, you shouldn't see it in full.

@kernelwhisperer
Copy link
Author

The whole snapshot is different, yes.

Perhaps this is a feature request then, rather than a bug, correct?

@sheremet-va
Copy link
Member

I guess we can add an option to truncate diff patches somehow. It should be disabled by default though.

@sheremet-va sheremet-va added enhancement New feature or request pr welcome p2-nice-to-have Not breaking anything but nice to have (priority) and removed pending triage labels Jan 30, 2024
@willieho
Copy link
Contributor

willieho commented Mar 1, 2024

I guess we can add an option to truncate diff patches somehow. It should be disabled by default though.

I'd like to take a shot at this enhancement/feature. After tracing the codebase, I think we can add a configuration option in DiffOptions so that we could have a more general control over diff truncation, instead of being specific to Snapshot. Does it sound reasonable?

willieho added a commit to willieho/vitest that referenced this issue Mar 4, 2024
willieho added a commit to willieho/vitest that referenced this issue Mar 5, 2024
willieho added a commit to willieho/vitest that referenced this issue Mar 23, 2024
willieho added a commit to willieho/vitest that referenced this issue Mar 27, 2024
willieho added a commit to willieho/vitest that referenced this issue Apr 4, 2024
renovate bot referenced this issue in solid-design-system/solid Apr 11, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[vite-node](https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme)
([source](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vite-node))
| [`1.4.0` ->
`1.5.0`](https://renovatebot.com/diffs/npm/vite-node/1.4.0/1.5.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/vite-node/1.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/vite-node/1.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/vite-node/1.4.0/1.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/vite-node/1.4.0/1.5.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>vitest-dev/vitest (vite-node)</summary>

###
[`v1.5.0`](https://github.com/vitest-dev/vitest/releases/tag/v1.5.0)

[Compare
Source](https://github.com/vitest-dev/vitest/compare/v1.4.0...v1.5.0)

#####    🚀 Features

- Add configuration for diff truncation  -  by
[@&#8203;willieho](https://github.com/willieho) in
[https://github.com/vitest-dev/vitest/issues/5073](https://github.com/vitest-dev/vitest/issues/5073)
and
[https://github.com/vitest-dev/vitest/issues/5333](https://github.com/vitest-dev/vitest/issues/5333)
[<samp>(6797b)</samp>](https://github.com/vitest-dev/vitest/commit/6797b041)
- Remove unrelated noise from diff for toMatchObject()  -  by
[@&#8203;geersch](https://github.com/geersch) in
[https://github.com/vitest-dev/vitest/issues/5364](https://github.com/vitest-dev/vitest/issues/5364)
[<samp>(99276)</samp>](https://github.com/vitest-dev/vitest/commit/99276399)
- Allow custom host for --inspect and --inspect-brk  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va) in
[https://github.com/vitest-dev/vitest/issues/5509](https://github.com/vitest-dev/vitest/issues/5509)
[<samp>(61572)</samp>](https://github.com/vitest-dev/vitest/commit/6157282c)
- **coverage**: V8 to ignore empty lines, comments, types  -  by
[@&#8203;AriPerkkio](https://github.com/AriPerkkio) in
[https://github.com/vitest-dev/vitest/issues/5457](https://github.com/vitest-dev/vitest/issues/5457)
[<samp>(10b89)</samp>](https://github.com/vitest-dev/vitest/commit/10b89713)

#####    🐞 Bug Fixes

- `describe` calls not taking generic type parameters  -  by
[@&#8203;aryaemami59](https://github.com/aryaemami59) in
[https://github.com/vitest-dev/vitest/issues/5415](https://github.com/vitest-dev/vitest/issues/5415)
[<samp>(16bac)</samp>](https://github.com/vitest-dev/vitest/commit/16bacfab)
- Prevent hang when `process` is mocked  -  by
[@&#8203;AriPerkkio](https://github.com/AriPerkkio) in
[https://github.com/vitest-dev/vitest/issues/5430](https://github.com/vitest-dev/vitest/issues/5430)
[<samp>(0ec4d)</samp>](https://github.com/vitest-dev/vitest/commit/0ec4d0e0)
- Don't check for "node:internal/console/" in console interceptor in
case the environment is not Node.js  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va)
[<samp>(87d36)</samp>](https://github.com/vitest-dev/vitest/commit/87d36a7a)
- The value received by toMatch should be a string  -  by
[@&#8203;btea](https://github.com/btea) in
[https://github.com/vitest-dev/vitest/issues/5428](https://github.com/vitest-dev/vitest/issues/5428)
[<samp>(67485)</samp>](https://github.com/vitest-dev/vitest/commit/674851ca)
- Increase stack trace limit for location, don't hardcode suite position
 -  by [@&#8203;sheremet-va](https://github.com/sheremet-va) in
[https://github.com/vitest-dev/vitest/issues/5518](https://github.com/vitest-dev/vitest/issues/5518)
[<samp>(04b23)</samp>](https://github.com/vitest-dev/vitest/commit/04b234d1)
-   **benchmark**:
- Run benchmark suites sequentially  -  by
[@&#8203;hi-ogawa](https://github.com/hi-ogawa) in
[https://github.com/vitest-dev/vitest/issues/5444](https://github.com/vitest-dev/vitest/issues/5444)
[<samp>(1f548)</samp>](https://github.com/vitest-dev/vitest/commit/1f548340)
- Fix benchmark summary of single bench suite  -  by
[@&#8203;hi-ogawa](https://github.com/hi-ogawa) in
[https://github.com/vitest-dev/vitest/issues/5489](https://github.com/vitest-dev/vitest/issues/5489)
[<samp>(db981)</samp>](https://github.com/vitest-dev/vitest/commit/db98145f)
- Table reporter for non TTY output  -  by
[@&#8203;hi-ogawa](https://github.com/hi-ogawa) in
[https://github.com/vitest-dev/vitest/issues/5484](https://github.com/vitest-dev/vitest/issues/5484)
[<samp>(bea23)</samp>](https://github.com/vitest-dev/vitest/commit/bea234b1)
-   **expect**:
- Fix `toHaveBeenNthCalledWith` error message when not called  -  by
[@&#8203;hi-ogawa](https://github.com/hi-ogawa) in
[https://github.com/vitest-dev/vitest/issues/5420](https://github.com/vitest-dev/vitest/issues/5420)
[<samp>(e5253)</samp>](https://github.com/vitest-dev/vitest/commit/e5253de4)
-   **types**:
- Pass correct type for suite factory  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va) in
[https://github.com/vitest-dev/vitest/issues/5437](https://github.com/vitest-dev/vitest/issues/5437)
[<samp>(26718)</samp>](https://github.com/vitest-dev/vitest/commit/26718eb5)
-   **utils**:
- Fix object diff with getter only property  -  by
[@&#8203;hi-ogawa](https://github.com/hi-ogawa) in
[https://github.com/vitest-dev/vitest/issues/5466](https://github.com/vitest-dev/vitest/issues/5466)
[<samp>(366d9)</samp>](https://github.com/vitest-dev/vitest/commit/366d97c3)
-   **vite-node**:
- Fix `isValidNodeImport` to check `"type": "module"` first  -  by
[@&#8203;hi-ogawa](https://github.com/hi-ogawa) in
[https://github.com/vitest-dev/vitest/issues/5416](https://github.com/vitest-dev/vitest/issues/5416)
[<samp>(6fb15)</samp>](https://github.com/vitest-dev/vitest/commit/6fb15280)
-   **vitest**:
- Correctly send console events when state changes  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va)
[<samp>(3463f)</samp>](https://github.com/vitest-dev/vitest/commit/3463f9bb)
- Initiate FakeTimers on demand  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va) in
[https://github.com/vitest-dev/vitest/issues/5450](https://github.com/vitest-dev/vitest/issues/5450)
[<samp>(e4e93)</samp>](https://github.com/vitest-dev/vitest/commit/e4e939ba)
- Check unhighlighted code for code frame line limit  -  by
[@&#8203;hi-ogawa](https://github.com/hi-ogawa) in
[https://github.com/vitest-dev/vitest/issues/5465](https://github.com/vitest-dev/vitest/issues/5465)
[<samp>(6ae7e)</samp>](https://github.com/vitest-dev/vitest/commit/6ae7eaa2)
- Correctly filter by parent folder  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va) in
[https://github.com/vitest-dev/vitest/issues/5408](https://github.com/vitest-dev/vitest/issues/5408)
[<samp>(91b06)</samp>](https://github.com/vitest-dev/vitest/commit/91b06cce)
- Close inspector immediately if run is canceled  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va) in
[https://github.com/vitest-dev/vitest/issues/5519](https://github.com/vitest-dev/vitest/issues/5519)
[<samp>(b8006)</samp>](https://github.com/vitest-dev/vitest/commit/b80062d7)
-   **workspace**:
- Set CWD to config directory, allow overriding local .env  -  by
[@&#8203;sheremet-va](https://github.com/sheremet-va) in
[https://github.com/vitest-dev/vitest/issues/5476](https://github.com/vitest-dev/vitest/issues/5476)
[<samp>(d4003)</samp>](https://github.com/vitest-dev/vitest/commit/d4003882)

#####     [View changes on
GitHub](https://github.com/vitest-dev/vitest/compare/v1.4.0...v1.5.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 5am every weekday" in timezone
Europe/Berlin, Automerge - "after 10pm every weekday,before 5am every
weekday" in timezone Europe/Berlin.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Never, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/solid-design-system/solid).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@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
enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants