Fail Jest tests if warnings or errors are logged to the console
What does this MR do and why?
Adds a package and configuration to Jest in order to have it return a Fail if tests encounter console errors or warnings.
Jest core doesn't do this (and people have lots of opinions about that).
We encountered a minor regression recently after upgrading a package that could've been caught pre-merge if the warnings in yarn test
had caused a pipeline failure.
Screenshots, screen recordings, or links to review app
- Before: Example of an undesirable pipeline pass: https://gitlab.com/gitlab-org/gitlab-docs/-/jobs/2847230913
- After: Example of a desirable pipeline failure: https://gitlab.com/gitlab-org/gitlab-docs/-/jobs/2847299345
How to set up and validate locally
- Check out commit
06329d
(a recent merge on main that had a jest test with errors) and runyarn test
. You should see errors, but the tests pass. - Check out the
jest-fail-on-warn
branch and runyarn test
. You should see errors, and the test with errors fails.
Merge request acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this merge request.
Edited by Sarah German