Can jest include snapshots in test runs, but exclude from contributing to code coverage?

Viewed 595

Let's say we have the following files:

 - component.tsx
 - component.test.tsx (1 behavioral test)
 - component_snapshot.test.tsx (1 snapshot test)

Let's say component.test.tsx provides 50% code coverage of component.tsx, while component_snapshot.test.tsx provides 100% code coverage.

Is it possible to configure jest to run both test files to see if both sets of tests pass, but exclude the snapshot testing from the overall test coverage report? In this scenario, the final coverage report would show component.tsx as having 50% test coverage, but with 2 tests passing.

I can achieve this behavior in individual commands:

  • react-scripts test -> 2 tests are run, but no coverage report

  • react-scripts test --coverage --testMatch='**/__tests__/**/*.+(ts|tsx|js)' --testMatch='**/?(*.)+(spec|test).+(ts|tsx|js)' --testMatch='!**/*snapshot*' -> 1 test run, snapshots are excluded, so they don't run and therefore don't report coverage

I'm hoping for a configuration that will run all tests (including snapshots), but prevent snapshots from having an effect on the coverage report.

0 Answers
Related