Skip to content

Commit 07af9c4

Browse files
author
Maël Nison
committed
Merge remote-tracking branch 'origin/master' into mapper
2 parents 8a7b653 + 78e0893 commit 07af9c4

253 files changed

Lines changed: 18992 additions & 3294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ untyped-import
1818
untyped-type-import
1919

2020
[version]
21-
^0.75.0
21+
^0.80.0

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"request": "launch",
1010
"name": "Debug Jest with current test file",
1111
"program": "${workspaceFolder}/packages/jest-cli/bin/jest.js",
12-
"args": ["--runInBand", "${file}"]
12+
"args": ["--runInBand", "${file}"],
13+
"runtimeArgs": ["-r", "flow-remove-types/register"]
1314
}
1415
]
1516
}

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,47 @@
22

33
### Features
44

5+
- `[jest-jasmine2/jest-circus/jest-cli]` Add test.todo ([#6996](https://github.com/facebook/jest/pull/6996))
6+
- `[pretty-format]` Option to not escape strings in diff messages ([#5661](https://github.com/facebook/jest/pull/5661))
7+
- `[jest-haste-map]` Add `getFileIterator` to `HasteFS` for faster file iteration ([#7010](https://github.com/facebook/jest/pull/7010)).
8+
- `[jest-worker]` [**BREAKING**] Add functionality to call a `setup` method in the worker before the first call and a `teardown` method when ending the farm ([#7014](https://github.com/facebook/jest/pull/7014)).
9+
- `[jest-config]` [**BREAKING**] Set default `notifyMode` to `failure-change` ([#7024](https://github.com/facebook/jest/pull/7024))
10+
- `[jest-snapshot]` Enable configurable snapshot paths ([#6143](https://github.com/facebook/jest/pull/6143))
11+
12+
### Fixes
13+
14+
- `[jest-each]` Add each array validation check ([#7033](https://github.com/facebook/jest/pull/7033))
15+
- `[jest-haste-map]` [**BREAKING**] Replace internal data structures to improve performance ([#6960](https://github.com/facebook/jest/pull/6960))
16+
- `[jest-haste-map]` Use relative paths to allow remote caching ([#7020](https://github.com/facebook/jest/pull/7020))
17+
- `[jest-haste-map]` Do not visit again files with the same sha-1 ([#6990](https://github.com/facebook/jest/pull/6990))
18+
- `[jest-jasmine2]` Fix memory leak in Error objects hold by the framework ([#6965](https://github.com/facebook/jest/pull/6965))
19+
- `[jest-haste-map]` Fixed Haste whitelist generation for scoped modules on Windows ([#6980](https://github.com/facebook/jest/pull/6980))
20+
- `[jest-mock]` Fix inheritance of static properties and methods in mocks ([#7003](https://github.com/facebook/jest/pull/7003))
21+
- `[jest-mock]` Fix mocking objects without `Object.prototype` in their prototype chain ([#7003](https://github.com/facebook/jest/pull/7003))
22+
- `[jest-mock]` Check `_isMockFunction` is true rather than truthy on potential mocks ([#7017](https://github.com/facebook/jest/pull/7017))
23+
- `[jest-cli]` Update jest-cli to show git ref in message when using `changedSince` ([#7028](https://github.com/facebook/jest/pull/7028))
24+
- `[jest-jasmine2`] Fix crash when test return Promise rejected with null ([#7049](https://github.com/facebook/jest/pull/7049))
25+
- `[jest-runtime]` Check `_isMockFunction` is true rather than truthy on potential global mocks ([#7017](https://github.com/facebook/jest/pull/7017))
26+
- `[jest-jasmine]` Show proper error message from async `assert` errors ([#6821](https://github.com/facebook/jest/pull/6821))
27+
28+
### Chore & Maintenance
29+
30+
- `[docs]` Add link for jest-extended in expect docs ([#7078](https://github.com/facebook/jest/pull/7078))
31+
- `[jest-util]` Add ErrorWithStack class ([#7067](https://github.com/facebook/jest/pull/7067))
32+
- `[docs]` Document `--runTestsByPath` CLI parameter ([#7046](https://github.com/facebook/jest/pull/7046))
33+
- `[docs]` Fix babel-core installation instructions ([#6745](https://github.com/facebook/jest/pull/6745))
34+
- `[docs]` Explain how to rewrite assertions to avoid large irrelevant diff ([#6971](https://github.com/facebook/jest/pull/6971))
35+
- `[examples]` add example using Babel 7 ([#6983](https://github.com/facebook/jest/pull/6983))
36+
- `[docs]` Replace shallow equality with referential identity in `ExpectAPI.md` ([#6991](https://github.com/facebook/jest/pull/6991))
37+
- `[jest-changed-files]` Refactor to use `execa` over `child_process` ([#6987](https://github.com/facebook/jest/pull/6987))
38+
- `[*]` Bump dated dependencies ([#6978](https://github.com/facebook/jest/pull/6978))
39+
- `[scripts]` Don’t make empty subfolders for ignored files in build folder ([#7001](https://github.com/facebook/jest/pull/7001))
40+
41+
## 23.6.0
42+
43+
### Features
44+
45+
- `[jest-cli]` Add `changedSince` to allowed watch mode configs ([#6955](https://github.com/facebook/jest/pull/6955))
546
- `[babel-jest]` Add support for `babel.config.js` added in Babel 7.0.0 ([#6911](https://github.com/facebook/jest/pull/6911))
647
- `[jest-resolve]` Add support for an experimental `mapper` option (Watchman crawler only) that adds virtual files to the Haste map ([#6940](https://github.com/facebook/jest/pull/6940))
748

@@ -23,6 +64,8 @@
2364
- `[docs]` Improve the documentation regarding preset configuration ([#6864](https://github.com/facebook/jest/issues/6864))
2465
- `[docs]` Clarify usage of `--projects` CLI option ([#6872](https://github.com/facebook/jest/pull/6872))
2566
- `[docs]` Correct `failure-change` notification mode ([#6878](https://github.com/facebook/jest/pull/6878))
67+
- `[scripts]` Don’t remove node_modules from subdirectories of presets in e2e tests ([#6948](https://github.com/facebook/jest/pull/6948))
68+
- `[diff-sequences]` Double-check number of differences in tests ([#6953](https://github.com/facebook/jest/pull/6953))
2669

2770
## 23.5.0
2871

CONTRIBUTING.md

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,25 @@ _Before_ submitting a pull request, please make sure the following is done…
2424

2525
Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type:
2626

27-
```sh
28-
git clone https://github.com/<your_username>/jest
29-
cd jest
30-
git checkout -b my_branch
27+
```sh-session
28+
$ git clone https://github.com/<your_username>/jest
29+
$ cd jest
30+
$ git checkout -b my_branch
3131
```
3232

3333
Note: Replace `<your_username>` with your GitHub username
3434

35-
2. Jest uses [Yarn](https://code.facebook.com/posts/1840075619545360) for running development scripts. If you haven't already done so, please [install yarn](https://yarnpkg.com/en/docs/install).
35+
1. Jest uses [Yarn](https://code.facebook.com/posts/1840075619545360) for running development scripts. If you haven't already done so, please [install yarn](https://yarnpkg.com/en/docs/install).
36+
37+
1. Make sure you have `python` installed (v2.7 is recommended, v3.x.x is not supported). Python is required by [node-gyp](https://github.com/nodejs/node-gyp) that is used when running `yarn install`.
38+
39+
To check your version of Python and ensure it's installed you can type:
40+
41+
```sh
42+
python --version
43+
```
3644

37-
3. Run `yarn install`. On Windows: To install [Yarn](https://yarnpkg.com/en/docs/install#windows-tab) on Windows you may need to download either node.js or Chocolatey<br />
45+
1. Run `yarn install`. On Windows: To install [Yarn](https://yarnpkg.com/en/docs/install#windows-tab) on Windows you may need to download either node.js or Chocolatey<br />
3846

3947
```sh
4048
yarn install
@@ -46,35 +54,62 @@ _Before_ submitting a pull request, please make sure the following is done…
4654
yarn --version
4755
```
4856

49-
4. If you've added code that should be tested, add tests. You can use watch mode that continuously transforms changed files to make your life easier.
57+
1. If you've added code that should be tested, add tests. You can use watch mode that continuously transforms changed files to make your life easier.
5058

5159
```sh
5260
# in the background
5361
yarn run watch
5462
```
5563

56-
5. If you've changed APIs, update the documentation.
64+
1. If you've changed APIs, update the documentation.
5765

58-
6. Ensure the test suite passes via `yarn test`. To run the test suite you may need to install [Mercurial](https://www.mercurial-scm.org/) (`hg`). On macOS, this can be done using [homebrew](http://brew.sh/): `brew install hg`.
66+
1. Ensure the test suite passes via `yarn test`. To run the test suite you may need to install [Mercurial](https://www.mercurial-scm.org/) (`hg`). On macOS, this can be done using [homebrew](http://brew.sh/): `brew install hg`.
5967

60-
```sh
61-
brew install hg # maybe
62-
yarn test
68+
```sh-session
69+
$ brew install hg # maybe
70+
$ yarn test
6371
```
6472

65-
7. If you haven't already, complete the CLA.
73+
1. If you haven't already, complete the CLA.
74+
75+
#### Testing
76+
77+
Code that is written needs to be tested to ensure that it achieves the desired behaviour. Tests either fall into a unit test or an integration test.
78+
79+
##### Unit tests
80+
81+
Some of the packages within jest have a `__tests__` directory. This is where unit tests reside in. If the scope of your work only requires a unit test, this is where you will write it in. Tests here usually don't require much if any setup.
82+
83+
##### Integration tests
84+
85+
There will be situations however where the work you have done cannot be tested alone using unit tests. In situations like this, you should write an integration test for your code. The integration tests reside within the `e2e` directory. Within this directory, there is a `__tests__` directory. This is where you will write the integration test itself. The tests within this directory execute jest itself using `runJest.js` and assertions are usually made on one if not all the output of the following `status`, `stdout` and `stderr`. The other sub directories within the `e2e` directory are where you will write the files that jest will run for your integration tests. Feel free to take a look at any of the tests in the `__tests__` directory within `e2e` to have a better sense of how it is currently being done.
86+
87+
It is possible to run the integration test itself manually to inspect that the new behaviour is indeed correct. Here is a small code snippet of how to do just that. This is useful when debugging a failing test.
88+
89+
```bash
90+
$ cd e2e/clear-cache
91+
$ node ../../packages/jest-cli/bin/jest.js # It is possible to use node --inspect or ndb
92+
PASS __tests__/clear_cache.test.js
93+
✓ stub (3ms)
94+
95+
Test Suites: 1 passed, 1 total
96+
Tests: 1 passed, 1 total
97+
Snapshots: 0 total
98+
Time: 0.232s, estimated 1s
99+
Ran all test suites.
100+
```
66101

67102
#### Additional Workflow for any changes made to website or docs
68103

69104
If you are making changes to the website or documentation, test the website folder and run the server to check if your changes are being displayed accurately.
70105

71106
1. Locate to the website directory and install any website specific dependencies by typing in `yarn`. Following steps are to be followed for this purpose from the root directory.
72-
```sh
73-
cd website # Only needed if you are not already in the website directory
74-
yarn
75-
yarn start
107+
```sh-session
108+
$ cd website # Only needed if you are not already in the website directory
109+
$ yarn
110+
$ yarn start
76111
```
77-
2. You can run a development server to check if the changes you made are being displayed accurately by running `yarn start` in the website directory.
112+
1. You can run a development server to check if the changes you made are being displayed accurately by running `yarn start` in the website directory.
78113

79114
### Contributor License Agreement (CLA)
80115

@@ -86,34 +121,34 @@ In order to accept your pull request, we need you to submit a CLA. You only need
86121

87122
To link `jest` on the command line to `jest-cli/bin/jest.js` in a development build:
88123

89-
```sh
90-
cd /path/to/your/Jest_clone/packages/jest-cli
91-
yarn link
124+
```sh-session
125+
$ cd /path/to/your/Jest_clone/packages/jest-cli
126+
$ yarn link
92127
```
93128

94129
To build Jest:
95130

96-
```sh
97-
cd /path/to/your/Jest_clone
131+
```sh-session
132+
$ cd /path/to/your/Jest_clone
98133

99134
# Do one of the following:
100135

101136
# Check out a commit from another contributor, and then
102-
yarn run build
137+
$ yarn run build
103138

104139
# Or, save your changes to Jest, and then
105-
yarn test # which also builds Jest
140+
$ yarn test # which also builds Jest
106141
```
107142

108143
To run tests in another project with the development build of Jest:
109144

110-
```sh
111-
cd /path/to/another/project
145+
```sh-session
146+
$ cd /path/to/another/project
112147

113148
# link development build to the other project
114-
yarn link jest-cli
149+
$ yarn link jest-cli
115150

116-
jest [options] # run jest-cli/bin/jest.js in the development build
151+
$ jest [options] # run jest-cli/bin/jest.js in the development build
117152
```
118153

119154
- To decide whether to specify any options, see `test` under `scripts` in the `package.json` file of the other project.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<a href="#backers"><img src="https://opencollective.com/jest/backers/badge.svg" alt="Backers on Open Collective"></a>
1818
<a href="#sponsors"><img src="https://opencollective.com/jest/sponsors/badge.svg" alt="Sponsors on Open Collective"></a>
1919
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
20+
<a href="https://snyk.io/test/github/facebook/jest?targetFile=packages/jest/package.json"><img src="https://snyk.io/test/github/facebook/jest/badge.svg?targetFile=packages/jest/package.json" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/facebook/jest?targetFile=packages/jest/package.json" style="max-width:100%;"></a>
2021
</p>
2122

2223
**👩🏻‍💻 Developer Ready**: Complete and ready to set-up JavaScript testing solution. Works out of the box for any React project.
@@ -101,10 +102,10 @@ If you'd like to learn more about running `jest` through the command line, take
101102

102103
[Babel](http://babeljs.io/) is automatically handled by Jest using `babel-jest`. You don't need install anything extra for using Babel.
103104

104-
> Note: If you are using a babel version 7 then you need to install `babel-core@^7.0.0-0` and `@babel/core` with the following command:
105+
> Note: If you are using Babel version 7 then you need to install `babel-jest`, `babel-core@^7.0.0-bridge.0` and `@babel/core` with the following command:
105106
>
106107
> ```bash
107-
> yarn add --dev 'babel-core@^7.0.0-0' @babel/core
108+
> yarn add --dev babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime
108109
> ```
109110
110111
Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file in your project's root folder. For example, if you are using ES6 and [React.js](https://reactjs.org) with the [`babel-preset-env`](https://babeljs.io/docs/plugins/preset-env/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:

TestUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const DEFAULT_GLOBAL_CONFIG: GlobalConfig = {
4040
noStackTrace: false,
4141
nonFlagArgs: [],
4242
notify: false,
43-
notifyMode: 'always',
43+
notifyMode: 'failure-change',
4444
onlyChanged: false,
4545
onlyFailures: false,
4646
outputFile: null,
@@ -102,6 +102,7 @@ const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
102102
setupTestFrameworkScriptFile: null,
103103
skipFilter: false,
104104
skipNodeResolution: false,
105+
snapshotResolver: null,
105106
snapshotSerializers: [],
106107
testEnvironment: 'node',
107108
testEnvironmentOptions: {},

docs/CLI.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a
227227

228228
Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.
229229

230+
### `--runTestsByPath`
231+
232+
Run only the tests that were specified with their exact paths.
233+
234+
_Note: The default regex matching works fine on small runs, but becomes slow if provided with multiple patterns and/or against a lot of tests. This option replaces the regex matching logic and by that optimizes the time it takes Jest to filter specific test files_
235+
230236
### `--setupTestFrameworkScriptFile=<file>`
231237

232238
The path to a module that runs some code to configure or set up the testing framework before each test. Beware that files imported by the setup script will not be mocked during testing.

docs/Configuration.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ Activates notifications for test results.
393393

394394
### `notifyMode` [string]
395395

396-
Default: `always`
396+
Default: `failure-change`
397397

398398
Specifies notification mode. Requires `notify: true`.
399399

@@ -642,6 +642,29 @@ If you want this path to be [relative to the root directory of your project](#ro
642642

643643
For example, Jest ships with several plug-ins to `jasmine` that work by monkey-patching the jasmine API. If you wanted to add even more jasmine plugins to the mix (or if you wanted some custom, project-wide matchers for example), you could do so in this module.
644644

645+
### `snapshotResolver` [string]
646+
647+
Default: `undefined`
648+
649+
The path to a module that can resolve test<->snapshot path. This config option lets you customize where Jest stores that snapshot files on disk.
650+
651+
Example snapshot resolver module:
652+
653+
```js
654+
// my-snapshot-resolver-module
655+
module.exports = {
656+
// resolves from test to snapshot path
657+
resolveSnapshotPath: (testPath, snapshotExtension) =>
658+
testPath.replace('__tests__', '__snapshots__') + snapshotExtension,
659+
660+
// resolves from snapshot to test path
661+
resolveTestPath: (snapshotFilePath, snapshotExtension) =>
662+
snapshotFilePath
663+
.replace('__snapshots__', '__tests__')
664+
.slice(0, -snapshotExtension.length),
665+
};
666+
```
667+
645668
### `snapshotSerializers` [array<string>]
646669

647670
Default: `[]`
@@ -896,7 +919,7 @@ A map from regular expressions to paths to transformers. A transformer is a modu
896919

897920
Examples of such compilers include [Babel](https://babeljs.io/), [TypeScript](http://www.typescriptlang.org/) and [async-to-gen](http://github.com/leebyron/async-to-gen#jest).
898921

899-
_Note: a transformer is only ran once per file unless the file has changed. During development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._
922+
_Note: a transformer is only run once per file unless the file has changed. During development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._
900923

901924
_Note: if you are using the `babel-jest` transformer and want to use an additional code preprocessor, keep in mind that when "transform" is overwritten in any way the `babel-jest` is not loaded automatically anymore. If you want to use it to compile JavaScript code it has to be explicitly defined. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_
902925

0 commit comments

Comments
 (0)