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 produced by toThrowErrorMatchingSnapshot might not match on CI #4407

Closed
okonet opened this issue Sep 1, 2017 · 11 comments
Closed

Comments

@okonet
Copy link
Contributor

okonet commented Sep 1, 2017

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Using .toThrowErrorMatchingSnapshot() on code that prints error using ansi codes (i.e. using chalk) produces different snapshots if run locally or on CI.

I'm running using jest-validate and here is the test I wrote for it: https://github.com/okonet/lint-staged/pull/141/files#diff-bdc504f1ee32ed7f1704def433667f72R223

This test runs locally but fails on CI. See https://travis-ci.org/okonet/lint-staged/jobs/270725061

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

git clone [email protected]:okonet/lint-staged.git
cd lint-staged && npm install && npm test

This should be free of errors. Running same command on Travis CI will fail the build, though: https://travis-ci.org/okonet/lint-staged/jobs/270725061

What is the expected behavior?

Snapshots should match locally and on CI.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

Default Jest config with babel-jest
macOS 10.12.
node 8.1.3
npm 5.3.0

@cpojer
Copy link
Member

cpojer commented Sep 1, 2017

I don't think there is anything we can really do about this… If your terminal supports colors in one place but not in another, then the output may differ and toThrowErrorMatchingSnapshot may not be the right matcher for you, unfortunately :(

@cpojer cpojer closed this as completed Sep 1, 2017
@cpojer
Copy link
Member

cpojer commented Sep 1, 2017

I'm happy to reopen if there is a proposal that will work consistently, and happy to merge PRs.

@thymikee
Copy link
Collaborator

thymikee commented Sep 1, 2017

You can however create a custom serializer which will strip the colors if they don't matter

@cpojer
Copy link
Member

cpojer commented Sep 1, 2017

Oh yeah, that's a good solution, I like that one.

@okonet
Copy link
Contributor Author

okonet commented Sep 1, 2017

@cpojer would you merge a PR for the default serializer that does that or adds an option?

@cpojer
Copy link
Member

cpojer commented Sep 1, 2017

Nah, I think publishing that serializer in a separate package makes most sense to me. We can link to it from somewhere on the Jest docs, though (do we have a space for extensions to Jest there?).

@thymikee
Copy link
Collaborator

thymikee commented Sep 1, 2017

We should have a community section with known and reliable libs around Jest

@cpojer
Copy link
Member

cpojer commented Sep 1, 2017

Agreed!

@gnapse
Copy link

gnapse commented Jun 7, 2018

Hi, I'm needing a serializer that performs exactly what was needed in this case, and I can't find it referenced in the docs. I found this community section and from there there's a link to "more resources" and to jest-awesome but I found no such serializer in those places.

@gnapse
Copy link

gnapse commented Jun 7, 2018

Ok we found one, and I'll link to it for future reference to others that pass by this issue:

https://github.com/joaogranado/jest-serializer-ansi

@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 May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants