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

Jest 20 #3490

Merged
merged 2 commits into from
May 6, 2017
Merged

Jest 20 #3490

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,81 @@
## master

## jest 20.0.0

* New `--projects` option to run one instance of Jest in multiple projects at the same time. ([#3400](https://github.com/facebook/jest/pull/3400))
* New multi project runner ([#3156](https://github.com/facebook/jest/pull/3156))
* New keyboard/arrow selection for watch mode typeaheads. ([#3386](https://github.com/facebook/jest/pull/3386))
* New --listTests flag. ([#3441](https://github.com/facebook/jest/pull/3441))
* New --showConfig flag. ([#3296](https://github.com/facebook/jest/pull/3296))
* New promise support for all `expect` matchers through `.resolves` and `.rejects`. ([#3068](https://github.com/facebook/jest/pull/3068))
* New `expect.hasAssertions()` function similar to `expect.assertions()`. ([#3379](https://github.com/facebook/jest/pull/3379))
* New `this.equals` function exposed to custom matchers. ([#3469](https://github.com/facebook/jest/pull/3469))
* New `valid-expect` lint rule in `eslint-plugin-jest`. ([#3067](https://github.com/facebook/jest/pull/3067))
* New HtmlElement pretty-format plugin. ([#3230](https://github.com/facebook/jest/pull/3230))
* New Immutable pretty-format plugins. ([#2899](https://github.com/facebook/jest/pull/2899))
* New test environment per file setting through `@jest-environment` in the docblock. ([#2859](https://github.com/facebook/jest/pull/2859))
* New feature that allows every configuration option to be set from the command line. ([#3424](https://github.com/facebook/jest/pull/3424))
* New feature to add custom reporters to Jest through `reporters` in the configuration. ([#3349](https://github.com/facebook/jest/pull/3349))
* New feature to add expected and actual values to AssertionError. ([#3217](https://github.com/facebook/jest/pull/3217))
* New feature to map code coverage from transformers. ([#2290](https://github.com/facebook/jest/pull/2290))
* New feature to run untested code coverage in parallel. ([#3407](https://github.com/facebook/jest/pull/3407))
* New option to define a custom resolver. ([#2998](https://github.com/facebook/jest/pull/2998))
* New printing support for text and comment nodes in html pretty-format. ([#3355](https://github.com/facebook/jest/pull/3355))
* New snapshot testing FAQ ([#3425](https://github.com/facebook/jest/pull/3425))
* New support for custom platforms on jest-haste-map. ([#3162](https://github.com/facebook/jest/pull/3162))
* New support for mocking native async methods. ([#3209](https://github.com/facebook/jest/pull/3209))
* New guide on how to use Jest with any JavaScript framework. ([#3243](https://github.com/facebook/jest/pull/3243))
* New translation system for the Jest website.
* Breaking Change: Forked Jasmine 2.5 into Jest's own test runner and rewrote large parts of Jasmine. ([#3147](https://github.com/facebook/jest/pull/3147))
* Breaking Change: Jest does not write new snapshots by default on CI. ([#3456](https://github.com/facebook/jest/pull/3456))
* Breaking Change: Moved the typescript parser from `jest-editor-support` into a separate `jest-test-typescript-parser` package. ([#2973](https://github.com/facebook/jest/pull/2973))
* Breaking Change: Replaced auto-loading of babel-polyfill with only regenerator-runtime, fixes a major memory leak. ([#2755](https://github.com/facebook/jest/pull/2755))
* Fixed `babel-jest` to look up the `babel` field in `package.json` as a fallback.
* Fixed `jest-editor-support`'s parser to not crash on incomplete ASTs. ([#3259](https://github.com/facebook/jest/pull/3259))
* Fixed `jest-resolve` to use `is-builtin-module` instead of `resolve.isCore`. ([#2997](https://github.com/facebook/jest/pull/2997))
* Fixed `jest-snapshot` to normalize line endings in the `serialize` function. ([#3002](https://github.com/facebook/jest/pull/3002))
* Fixed behavior of `--silent` flag. ([#3003](https://github.com/facebook/jest/pull/3003))
* Fixed bug with watchers on macOS causing test to crash. ([#2957](https://github.com/facebook/jest/pull/2957))
* Fixed CLI `notify` option not taking precedence over config option. ([#3340](https://github.com/facebook/jest/pull/3340))
* Fixed detection of the npm client in SummaryReporter to support Yarn. ([#3263](https://github.com/facebook/jest/pull/3263))
* Fixed done.fail not passing arguments ([#3241](https://github.com/facebook/jest/pull/3241))
* Fixed fake timers to restore after resetting mocks. ([#2467](https://github.com/facebook/jest/pull/2467))
* Fixed handling of babylon's parser options in `jest-editor-support`. ([#3344](https://github.com/facebook/jest/pull/3344))
* Fixed Jest to properly cache transform results. ([#3334](https://github.com/facebook/jest/pull/3334))
* Fixed Jest to use human-readable colors for Jest's own snapshots. ([#3119](https://github.com/facebook/jest/pull/3119))
* Fixed jest-config to use UID for default cache folder. ([#3380](https://github.com/facebook/jest/pull/3380)), ([#3387](https://github.com/facebook/jest/pull/3387))
* Fixed jest-runtime to expose inner error when it fails to write to the cache. ([#3373](https://github.com/facebook/jest/pull/3373))
* Fixed lifecycle hooks to make afterAll hooks operate the same as afterEach. ([#3275](https://github.com/facebook/jest/pull/3275))
* Fixed pretty-format to run plugins before serializing nested basic values. ([#3017](https://github.com/facebook/jest/pull/3017))
* Fixed return value of mocks so they can explicitly be set to return `undefined`. ([#3354](https://github.com/facebook/jest/pull/3354))
* Fixed runner to run tests associated with snapshots when the snapshot changes. ([#3025](https://github.com/facebook/jest/pull/3025))
* Fixed snapshot serializer require, restructured pretty-format. ([#3399](https://github.com/facebook/jest/pull/3399))
* Fixed spacing in test name pattern typeahead ([#3315](https://github.com/facebook/jest/pull/3315))
* Fixed support for Babel 7 in babel-jest. ([#3271](https://github.com/facebook/jest/pull/3271))
* Fixed testMatch to find tests in .folders. ([#3006](https://github.com/facebook/jest/pull/3006))
* Fixed testNamePattern and testPathPattern to work better together. ([#3327](https://github.com/facebook/jest/pull/3327))
* Fixed to show reject reason when expecting resolve. ([#3134](https://github.com/facebook/jest/pull/3134))
* Fixed toHaveProperty() to use hasOwnProperty from Object ([#3410](https://github.com/facebook/jest/pull/3410))
* Fixed watch mode typeahead filter cursor behavior. ([#3392](https://github.com/facebook/jest/pull/3392))
* Fixed watch mode usage prompt to collapse after first run. ([#3078](https://github.com/facebook/jest/pull/3078))
* Fixed watch mode's screen clearing. [(#2959) ([#3294](https://github.com/facebook/jest/pull/3294))
* Improved and consolidated Jest's configuration file resolution. ([#3472](https://github.com/facebook/jest/pull/3472))
* Improved documentation throughout the Jest website.
* Improved documentation to explicitly mention that snapshots must be reviewed. ([#3203](https://github.com/facebook/jest/pull/3203))
* Improved documentation to make it clear CRA users don't need to add dependencies. ([#3312](https://github.com/facebook/jest/pull/3312))
* Improved eslint-plugin-jest's handling of `expect`. ([#3306](https://github.com/facebook/jest/pull/3306))
* Improved flow-coverage, eslint rules and test coverage within the Jest repository.
* Improved printing of `expect.assertions` error. ([#3033](https://github.com/facebook/jest/pull/3033))
* Improved Windows test coverage of Jest.
* Refactored configs & transform ([#3376](https://github.com/facebook/jest/pull/3376))
* Refactored reporters to pass individual Tests to reporters. ([#3289](https://github.com/facebook/jest/pull/3289))
* Refactored TestRunner ([#3166](https://github.com/facebook/jest/pull/3166))
* Refactored watch mode prompts. ([#3290](https://github.com/facebook/jest/pull/3290))
* Deleted `jest-file-exists`. ([#3105](https://github.com/facebook/jest/pull/3105))
* Removed `Config` type. ([#3366](https://github.com/facebook/jest/pull/3366))
* Removed all usage of `jest-file-exists`. ([#3101](https://github.com/facebook/jest/pull/3101))
* Adopted prettier on the Jest codebase.

## jest 19.0.1

* Fix infinite loop when using `--watch` with `--coverage`.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![CircleCI Build Status](https://circleci.com/gh/facebook/jest.svg?style=shield)](https://circleci.com/gh/facebook/jest)
[![Travis Build Status](https://travis-ci.org/facebook/jest.svg?branch=master)](https://travis-ci.org/facebook/jest) [![Windows Build Status](https://ci.appveyor.com/api/projects/status/8n38o44k585hhvhd/branch/master?svg=true)](https://ci.appveyor.com/project/Daniel15/jest/branch/master) [![npm version](https://badge.fury.io/js/jest.svg)](http://badge.fury.io/js/jest)

🃏 Painless JavaScript Testing
🃏 Delightful JavaScript Testing

- **👩🏻‍💻 Easy Setup**: Jest is a complete and easy to set up JavaScript testing solution. In fact, Jest works out of the box for any React project.

Expand Down Expand Up @@ -148,7 +148,7 @@ Learn more about using Jest at http://facebook.github.io/jest
* [Getting Started](http://facebook.github.io/jest/docs/getting-started.html)
* [Guides](http://facebook.github.io/jest/docs/snapshot-testing.html)
* [API Reference](http://facebook.github.io/jest/docs/api.html)
* [Configuring package.json](http://facebook.github.io/jest/docs/configuration.html)
* [Configuring Jest](http://facebook.github.io/jest/docs/configuration.html)

## Contributing

Expand Down
88 changes: 88 additions & 0 deletions blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: Jest 20: 💖 Delightful Testing & 🏃🏽 Multi-Project-Runner
author: Christoph Pojer
authorURL: http://twitter.com/cpojer
authorFBID: 100000023028168
---

A few months ago we announced [Jest 19](http://facebook.github.io/jest/blog/2017/02/21/jest-19-immersive-watch-mode-test-platform-improvements.html) which came with major new features and was the biggest Jest release until today. Jest 20 has twice the amount of changes compared to the previous version, features a complete rewrite of the test runner, adds new testing APIs. The new release enables a new level of customization and configuration for projects all while making it effortless to upgrade. Beyond Painless JavaScript Testing, we believe Jest is now delivering a **Delightful JavaScript Testing experience**. Let's take a look at the best new features and changes in depth:

## Multi-Project-Runner & Configuration Overhaul

Until now, Jest could only operate in one project at a time. This is often cumbersome if you are working on many smaller projects that each have their own setup and configuration. With Jest 20, we rewrote the test runner completely to run many projects at the same time within a single instance of Jest, for example if you are working on a React frontend and a node.js backend. Here is a video of Jest running tests for [React](https://github.com/facebook/react), [Relay](https://github.com/facebook/relay), [Yarn](https://github.com/yarnpkg/yarn) and Jest all at the same time:

![multi-runner](/jest/img/blog/20-multi-runner.gif)

<!--truncate-->

Jest is now collapsing the usage guide after the first test run to save vertical space in the terminal. Along with this, we also improved watch mode by adding arrow-key support to the test pattern typeaheads and the test file and test name pattern typeaheads now work together rather than being unrelated features which allow to select the right tests to run more easily:

![typeahead](/jest/img/blog/20-typeahead.png)

Further, we completely overhauled how the configuration system works inside of Jest. You can now pass any configuration option through the CLI to overwrite the ones specified in your configuration file. Along with that, we changed Jest to look for a `jest.config.js` file by default which means you are now able to define a Jest configuration using JavaScript as well as being able to configure it through `package.json` like before. Through the addition of all these new features, you are now able to combine Jest in more powerful ways than ever before. For example, if you would like to find out which tests Jest would run given a set of changed files from a commit across multiple projects in a monorepo, you can combine cli arguments like this now:

```
$ jest --projects projectA projectB --listTests --findRelatedTests projectA/banana.js projectB/kiwi.js
[
"projectA/banana.test.js",
"projectB/kiwi.test.js",
"projectB/pineapple.test.js",
]
```

This is especially useful for continuous integration (CI) systems where you may want to only run a subset of tests for Pull Requests to prevent Jest from running thousands of test files on every small change.

Finally, we are now properly mapping code coverage when using TypeScript and we are running code coverage for untested files in worker processes which yields significant speed ups for this feature.

## New & Improved Testing APIs

We made a number of additions and improvements to the testing APIs which will help write more effective tests. We'd like to point out that all of these improvements were made entirely by community members!

* **Better async testing:** Added new async/Promise support through resolves/rejects modifiers on expect: `expect(Promise(…)).resolves.toEqual(…)`. [See documentation](https://facebook.github.io/jest/docs/en/expect.html#resolves).
* **Expect <n> assertions:** Along with the existing `expect.assertions(n)`, the new `expect.hasAssertions()` can be used to ensure a test has at least one assertion.
* **Lint Plugin:** A `valid-expect` rule was added to `eslint-plugin-jest` to ensure that an assertion is called after invoking `expect`. This will prevent mistakes like a stray `expect(banana);` with a missing assertion call.
* **Pretty-Format Plugins:** A number of new pretty-format plugins were added to Jest. We now pretty-print [Immutable.js](https://github.com/facebook/immutable-js/) data structures and HtmlElements in assertion failures and snapshots.
* **Custom Environment:** It is now possible to add a `@jest-environment node|jsdom` annoation to the doc-block comment of a test file to use a test environment different from the default for individual tests.

Here is an example of all how all the new APIs together will make testing more delightful:

```
test('compares apples and bananas', async () => {
expect.hasAssertions(); // Ensure this test has at least one assertion.

await expect(
Promise.resolve(Immutable.Map({apples: 1, bananas: 2})),
).resolves.toEqual(Immutable.Map({apples: 1, bananas: 3}));

expect('banana'); // valid-expect in eslint-plugin-jest will show an error.
});
```

This example will print a test failure similar to this:

![testing-apis](/jest/img/blog/20-testing-apis.png)

## Breaking Changes

As with every major release, we are making a number of breaking changes to make larger changes in the future possible and to push the testing experience to a new level. This time, we tried our best to only break APIs that we don't expect to affect the majority of Jest's users:

* **Fork of Jasmine 2.5:** We finally decided to fork Jasmine itself and take ownership over Jest's own test runner. This will allow us to improve all aspects of the unit testing experience in the future but for now we are focused on incremental rewrites and reducing the API surface. If you see a test breaking as a result of a Jasmine API that is now missing, there should be an equivalent feature on the `jest` or `expect` objects. As such, we have removed many Jasmine features that aren't generally used in most codebases.
* **New Snapshots on CI:** Snapshots must always be committed along with the test and the modules they are testing. We changed Jest to not save new snapshots automatically in Continuous Integration (CI) environments or when the `--ci` flag is specified. To overwrite this behavior, which is generally not recommended, the `--updateSnapshot` flag can be used.
* **Babel-Polyfill:** Jest used to load `babel-polyfill` automatically when using babel-jest which resulted in memory leaks inside of Jest. In most versions of node, it is not necessary to load `babel-polyfill` so we removed this auto-inclusion and instead changed Jest to only include `regenerator-runtime` by default, which is commonly used to support async/await in older versions of Node.js. If you need `babel-polyfill`, you can manually require it in your setup files.

## Other Improvements

* **Documentation:** Documentation is critical to share best practices and teach everyone how to write effective tests which will lead to better software. Over the last few weeks we have also expanded Jest's documentation to include a Snapshot Testing FAQ, a guide with information about how to use Jest with common JavaScript libraries as well as we documented the new features mentioned above.
* **Translations:** We are now asking for your help to [translate the Jest documentation](https://crowdin.com/project/jest) to make it easier for people to learn how to use Jest.
* **Custom Reporters:** Jest now supports custom test reporters through the `reporters` configuration option. You can finally customize the output of Jest as well as integrate it with other tools by generating reports in formats such as XML. [See documentation](https://facebook.github.io/jest/docs/en/configuration.html#reporters-array-modulename-modulename-options).
* **Codebase Health:** It was only possible iterate so quickly in Jest because we spent a significant amount of time on the health of the codebase. We were one of the early adopters of [prettier](https://github.com/prettier/prettier), we increased flow coverage significantly, forked Jasmine to improve our test runner library and we rewrote and refactored significant portions of Jest itself to set up Jest for success in the future.
* **Bugfixes:** As always, we made plenty of bugfixes in Jest. The full Changelog can be found in the [Jest repository](https://github.com/facebook/jest/blob/master/CHANGELOG.md#jest-2000).

## Talks about Jest

Recently the Jest core team and other contributors started to talk more about Jest and the experience of working on Jest at conferences:

* Rogelio Guzman did a talk about [Jest Snapshots and Beyond](https://www.youtube.com/watch?time_continue=416&v=HAuXJVI_bUs) at React Conf.
* I spoke about [Building High-Quality JavaScript Tools](https://developers.facebook.com/videos/f8-2017/building-high-quality-javascript-tools/) at Facebooks f8 conference.

*As always, this release couldn't have been possible without you, the JavaScript community. We are incredibly grateful that we get the opportunity to work on improving JavaScript testing together. If you'd like to contribute to Jest, please don't hesitate to reach out to us on [GitHub](https://github.com/facebook/jest) or on [Discord](https://discordapp.com/channels/102860784329052160/103622435865104384).*
3 changes: 2 additions & 1 deletion docs/en/Configuration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: configuration
title: Configuring package.json
title: Configuring Jest
layout: docs
category: API Reference
permalink: docs/en/configuration.html
Expand All @@ -25,6 +25,7 @@ top level so Jest will know how to find your settings:
Or through JavaScript:

```js
// jest.config.js
module.exports = {
verbose: true,
};
Expand Down
2 changes: 1 addition & 1 deletion docs/en/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ If you add a snapshot serializer in individual test files instead of to adding i
* You make the dependency explicit instead of implicit.
* You avoid limits to configuration that might cause you to eject from [create-react-app](https://github.com/facebookincubator/create-react-app).

See [configuring package.json](/jest/docs/configuration.html#snapshotserializers-array-string) for more information.
See [configuring Jest](/jest/docs/configuration.html#snapshotserializers-array-string) for more information.

### `.not`

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.0.0-rc.4",
"version": "19.0.2",
"version": "20.0.0",
"npmClient": "yarn",
"packages": [
"packages/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "babel-jest",
"description": "Jest plugin to use babel for transformation.",
"version": "19.0.0",
"version": "20.0.0",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git"
Expand All @@ -11,6 +11,6 @@
"dependencies": {
"babel-core": "^6.0.0",
"babel-plugin-istanbul": "^4.0.0",
"babel-preset-jest": "^19.0.0"
"babel-preset-jest": "^20.0.0"
}
}
Loading