It's been one month since the last major release and we've made significant improvements to Jest since. In this major release we are updating the snapshot format we are using which will likely require snapshots to be updated when upgrading Jest. We don't make these changes lightly and don't expect this to happen often but we think it is necessary to improve the format from time to time.
Jest 16 features a new reporter interface that shows running tests as well as a live summary and a progress bar based on the estimated test runtime from previous test runs. We also improved the CLI output to work better with different color schemes. If there were test failures in a previous run, Jest will now always run those tests first to give useful signal to users as quickly as possible.
We also added a lot of new features which you may find useful:
- New CLI flags were added: A
-t <pattern>option was added to filter tests from the command line much like
fitdoes in tests.
- Previously failed tests now always run first.
jest <pattern>is now case-insensitive to make it easier to filter test files.
- A test run in watch mode can now be interrupted. During a test run, simply press any of the keys used for input during watch mode (
enter) to abort a test run and start a new one.
--bailflag now also works in watch mode. Together with running failed tests first, Jest's watch mode will now feel turbocharged!
- Jest now automatically considers files and tests with the
- Jest warns about duplicate manual mock files and we improved automatically created mocks for ES modules compiled with babel.
jest.clearAllMocksfunction was added to clear all mocks in between tests.
- We improved module resolution when
- Finally, a
--findRelatedTests <fileA> <fileB>cli option was added to run tests related to the specified files. This is especially helpful as a pre-commit hook if you'd like to run tests only on a specified set of files that have tests associated with them.
This is what Jest looks like when a test run is interrupted in watch mode:
Jest's snapshot implementation was completely rewritten. The new version of the
jest-snapshot package is now structured in a way that allows for easier integration into other test runners and enables more cool integrations like with React Storybook. Jest doesn't mark snapshots as obsolete in a file with skipped or failing tests. We also made a number of changes to the snapshot format:
- Objects and Arrays are now printed with a trailing comma to minimize future changes to snapshots.
- We removed function names from snapshots. They were causing issues with different versions of Node, with code coverage instrumentation and we generally felt like it wasn't useful signal to show to the user that the name of a function has changed.
- Snapshots are now sorted using natural sort order within a file.
When upgrading to Jest 16, the diff might look similar to this one: