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

Snapshot serializers added with expect.addSnapshotSerializer are not used #552

Closed
askoufis opened this issue May 4, 2023 · 3 comments · Fixed by #558
Closed

Snapshot serializers added with expect.addSnapshotSerializer are not used #552

askoufis opened this issue May 4, 2023 · 3 comments · Fixed by #558

Comments

@askoufis
Copy link

askoufis commented May 4, 2023

🐛 Bug Report

Custom snapshot serializers added with expect.addSnapshotSerializer are not used. Only custom snapshots serializers configured via snapshotSerializers actually work.

This behaviour appears to have broken in version 8.

To Reproduce

  • git clone https://github.com/askoufis/jest-puppeteer-repro
  • pnpm install
  • pnpm test

The test in foo.test.js is run. This has a custom serializer added that prepends some text to the snapshot. However the snapshot does not contain this test, which is a bug.

  • git switch jest-puppeteer-7
  • pnpm install
  • pnpm test

This branch has jest-puppeter@7 installed. The snapshot serializer works in this case.

  • git switch config-snapshot-serializers
  • pnpm install
  • pnpm test

This branch has the snapshot serializer configured in the jest config instead of the test file, and it's using jest-puppeteer@8. The snapshot now fails as the serializer has prepended some text to the snapshot, which is the expected behaviour.

Expected behavior

Custom snapshot serializers added with expect.addSnapshotSerializer should work.

Link to repl or repo (highly encouraged)

https://github.com/askoufis/jest-puppeteer-repro

System info

Paste the results here:

## System:
 - OS: macOS 13.2.1
 - CPU: (10) arm64 Apple M1 Pro
 - Memory: 4.52 GB / 32.00 GB
 - Shell: 3.6.1 - /opt/homebrew/bin/fish
## Binaries:
 - Node: 16.20.0 - ~/.local/share/.volta/tools/image/node/16.20.0/bin/node
 - Yarn: 1.22.19 - ~/.local/share/.volta/tools/image/yarn/1.22.19/bin/yarn
 - npm: 8.19.4 - ~/.local/share/.volta/tools/image/node/16.20.0/bin/npm
 - Watchman: 2023.05.01.00 - /opt/homebrew/bin/watchman
## npmPackages:
 - jest-puppeteer: ^8.0.6 => 8.0.6
@gregberge
Copy link
Member

Hello @askoufis, thanks. I think it is a problem in the overriding of expect.

@askoufis
Copy link
Author

askoufis commented May 23, 2023

Did a bit of debugging. To me, the overriding of expect is correct. It's similar enough to the code in expect-puppeteer v7 (when this used to work) that I don't think it's the culprit.

What's interesting is that when calling addSnapshotSerializer, which is just an alias for addSerializer, the PLUGINS array is updated correctly. However, when getSerializers is called later on (internally within jest somewhere), the PLUGINS array is back to its original state with only 7 elements (you'd expect there to be at least 8).

@askoufis
Copy link
Author

Thanks for the fix! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants