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

[Bug]: Cannot show diff when .toMatchInlineSnapshot throws exception #13180

Closed
liuxingbaoyu opened this issue Aug 26, 2022 · 10 comments · Fixed by #13181
Closed

[Bug]: Cannot show diff when .toMatchInlineSnapshot throws exception #13180

liuxingbaoyu opened this issue Aug 26, 2022 · 10 comments · Fixed by #13181

Comments

@liuxingbaoyu
Copy link
Contributor

liuxingbaoyu commented Aug 26, 2022

Version

29.0

Steps to reproduce

git clone https://github.com/babel/babel
yarn up jest*
make build
yarn jest babel-preset-react

I know this is overly complicated to reproduce, I'm still investigating, just opened an issue first in case anyone can think of what could be the reason for this, will update if I find anything new!😃

Expected behavior

Differences are displayed normally.

Actual behavior

normalize options › Babel 7 › default values

    expect(received).toMatchInlineSnapshot(snapshot)

    Snapshot name: `normalize options Babel 7 default values 2`

    - Snapshot  - 0
    + Received  + 0

    @@ -7,5 +7,5 @@
        "runtime": "automatic",
        "throwIfNamespace": true,
        "useBuiltIns": undefined,
        "useSpread": undefined,
      }

      113 |         }
      114 |       `);
    > 115 |       expect(normalizeOptions({ runtime: "automatic" })).toMatchInlineSnapshot(`
          |                                                          ^
      116 |         Object {
      117 |           "development": false,
      118 |           "importSource": undefined,

      at Object.toMatchInlineSnapshot (packages/babel-preset-react/test/normalize-options.skip-bundled.js:115:58)

Additional context

No response

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11700KF @ 3.60GHz
  Binaries:
    Node: 18.7.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 3.1.1 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^29.0.0 => 29.0.0
@SimenB
Copy link
Member

SimenB commented Aug 26, 2022

Huh, this is a weird one 😅 It's like the error is toString-ed before it's thrown

@SimenB
Copy link
Member

SimenB commented Aug 26, 2022

@liuxingbaoyu the issue is in jest-light-runner. This is the result using "normal" jest-runner.

image

I tried applying https://github.com/prettier/prettier/pull/13355/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R129 which made no difference

@SimenB
Copy link
Member

SimenB commented Aug 26, 2022

@nicolo-ribaudo @liuxingbaoyu this is actually not new with jest 29 - seems like jest-light-runner doesn't properly support inline snapshot errors.

This diff on babel's main branch gives the same weird error using Jest 28

diff --git i/jest.config.js w/jest.config.js
index d499a021de..8c9108c56f 100644
--- i/jest.config.js
+++ w/jest.config.js
@@ -70,4 +70,5 @@ module.exports = {
   // package should be declared explicitly in the package.json
   // Yarn will generate correct file links so that Jest can resolve correctly
   moduleNameMapper: null,
+  snapshotFormat: { escapeString: false, printBasicPrototype: false },
 };

The snapshotFormat changes are why your snapshots are changed, fwiw

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2022
@liuxingbaoyu
Copy link
Contributor Author

Yeah, I tried without jest-light-runner, as I wrote in the issue, it outputs

- Snapshot - 0
+Received +0

, is this expected?

@SimenB
Copy link
Member

SimenB commented Aug 26, 2022

Ah, good catch

@SimenB SimenB reopened this Aug 26, 2022
@liuxingbaoyu
Copy link
Contributor Author

Ah, just saw your latest reply, and yes, I'm also guessing that the snapshot change might be related to jest-light-runner, thank you so much for looking into this!😃

@SimenB
Copy link
Member

SimenB commented Aug 26, 2022

@liuxingbaoyu fixed the diffing issue in https://github.com/facebook/jest/releases/tag/v29.0.1. The weird error is in jest-light-runner as mentioned 🙂

@liuxingbaoyu
Copy link
Contributor Author

Thanks for the quick fix! I will continue to investigate jest-light-runner.

@SimenB
Copy link
Member

SimenB commented Aug 26, 2022

Thanks for noticing! 😀 Very confusing diff for users upgrading

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2022
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