question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Snapshot test crashes with the `coverage` option (& in CI env)

See original GitHub issue

Current behavior:

After the migration from version 10 to version 11, the snapshot test crashes locally with the coverage (react-scripts test --coverage) option and in the CI (circleci) environment with and without the coverage option.

To reproduce:

Locally Snapshot tests:

  1. react-scripts test (OK)
  2. react-scripts test --coverage (KO)

Example1: Capture d’écran 2021-10-16 à 18 42 29

Example2:

const StyledTable = styled(Table)`
    border: none;
    font-weight: normal;
    .Table__row {
        border: none;
    }
    ...
`;
Capture d’écran 2021-10-16 à 19 09 21 **Expected behavior:**

Environment information:

  • react version: 17.0.2
  • @emotion/react version: 11.4.1
  • @emotion/styled version: 11.3.0
  • @emotion/jest version: 11.3.0
  • react-scripts version: 4.0.3

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Oct 17, 2021

Hello @Andarist, It is a private project. The problem is, I can’t reproduce on another simple app.

That is only an indication that this might be related to your project and that I can’t help you much since I don’t have access to it.

The question is: In your opinion, what can cause this variation (the order of generated classes and the order of css rules)?

It’s hard to tell without seeing the code and the project as a whole.

The majority of related logic should be in getStyleElements, getClassNamesFromNodes and getPrettyStylesFromClassNames. I recommend you to dive into th debugger and just compare both runs - with the --coverage option and without it. This should answer all the questions.

0reactions
Andaristcommented, Oct 18, 2021

Then you should look into why classNames are different here - I really don’t have magic tips here, I would myself just start debugging to get to the bottom of this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest finds tests but doesn't collect coverage - Stack Overflow
The quick fix I said in my comment, using --watchAll instead, eg: react-scripts test --coverage --watchAll . Just for future reference, ...
Read more >
jest-environment-node | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >
Continuous integration for React applications using Jest and ...
Begin by writing tests for the App component. A good starting point is adding a snapshot test to ensure that the component renders...
Read more >
.NET Code Coverage for Continuous Integration using ...
How much of our code is being covered by our unit tests ? Are there areas we are not testing ? By capturing...
Read more >
Configuring Vitest
To configure vitest itself, add test property in your Vite config. ... When importing such dependencies in Node environment using named ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found