Skip to content

Commit 46e5ec5

Browse files
committed
Merge branch 'master' into fix-coverage
2 parents ea3084d + 7743c09 commit 46e5ec5

File tree

471 files changed

+1384
-623
lines changed

Some content is hidden

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

471 files changed

+1384
-623
lines changed

.eslintrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = {
4646
},
4747
},
4848
{
49-
files: ['scripts/**/*', 'integration_tests/**/*'],
49+
files: ['scripts/**/*', 'integration-tests/**/*'],
5050
rules: {
5151
'babel/func-params-comma-dangle': 0,
5252
'unicorn/filename-case': 0,
@@ -83,11 +83,11 @@ module.exports = {
8383
},
8484
},
8585
{
86-
excludedFiles: 'integration_tests/__tests__/**/*',
86+
excludedFiles: 'integration-tests/__tests__/**/*',
8787
files: [
8888
'examples/**/*',
8989
'scripts/**/*',
90-
'integration_tests/*/**/*',
90+
'integration-tests/*/**/*',
9191
'website/*/**/*',
9292
'eslint_import_resolver.js',
9393
],
@@ -105,7 +105,7 @@ module.exports = {
105105
},
106106
{
107107
files: [
108-
'integration_tests/__tests__/**/*',
108+
'integration-tests/__tests__/**/*',
109109
'packages/babel-jest/**/*.test.js',
110110
'packages/babel-plugin-jest-hoist/**/*.test.js',
111111
'packages/babel-preset-jest/**/*.test.js',
@@ -127,7 +127,7 @@ module.exports = {
127127
files: [
128128
'website/**',
129129
'**/__tests__/**',
130-
'integration_tests/**',
130+
'integration-tests/**',
131131
'**/pretty-format/perf/**',
132132
],
133133
rules: {

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*~
55
/examples/*/node_modules/
66

7-
/integration_tests/*/node_modules
8-
/integration_tests/transform/*/coverage
9-
/integration_tests/transform/*/node_modules
7+
/integration-tests/*/node_modules
8+
/integration-tests/transform/*/coverage
9+
/integration-tests/transform/*/node_modules
1010

1111
/node_modules
1212

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,47 @@
11
## master
22

3+
### Fixes
4+
5+
* `[jest-cli]` Fix `EISDIR` when a directory is passed as an argument to `jest`.
6+
([#5317](https://github.com/facebook/jest/pull/5317))
7+
8+
## jest 22.1.0
9+
10+
### Features
11+
12+
* `[jest-cli]` Make Jest exit without an error when no tests are found in the
13+
case of `--lastCommit`, `--findRelatedTests`, or `--onlyChanged` options
14+
having been passed to the CLI
15+
16+
### Fixes
17+
* `[jest-cli]` Use `import-local` to support global Jest installations.
18+
([#5304](https://github.com/facebook/jest/pull/5304))
19+
* `[jest-runner]` Fix memory leak in coverage reporting
20+
([#5289](https://github.com/facebook/jest/pull/5289))
21+
* `[docs]` Update mention of the minimal version of node supported [#4947](https://github.com/facebook/jest/issues/4947)
22+
* `[jest-cli]` Fix missing newline in console message ([#5308](https://github.com/facebook/jest/pull/5308))
23+
* `[jest-cli]` `--lastCommit` and `--changedFilesWithAncestor` now take effect
24+
even when `--onlyChanged` is not specified. ([#5307](https://github.com/facebook/jest/pull/5307))
25+
26+
### Chore & Maintenance
27+
28+
* `[filenames]` Standardize folder names under `integration-tests/`
29+
([#5298](https://github.com/facebook/jest/pull/5298))
30+
31+
## jest 22.0.6
32+
33+
### Fixes
34+
35+
* `[jest-jasmine2]` Fix memory leak in snapshot reporting
36+
([#5279](https://github.com/facebook/jest/pull/5279))
37+
* `[jest-config]` Fix breaking change in `--testPathPattern`
38+
([#5269](https://github.com/facebook/jest/pull/5269))
39+
40+
### Fixes
41+
42+
* `[docs]` Document caveat with mocks, Enzyme, snapshots and React 16
43+
([#5258](https://github.com/facebook/jest/issues/5258))
44+
345
## jest 22.0.5
446

547
### Fixes
@@ -32,6 +74,8 @@
3274
([#5154](https://github.com/facebook/jest/pull/5154))
3375
* `[jest-jasmine2]` Support generator functions as specs.
3476
([#5166](https://github.com/facebook/jest/pull/5166))
77+
* `[jest-jasmine2]` Allow `spyOn` with getters and setters.
78+
([#5107](https://github.com/facebook/jest/pull/5107))
3579
* `[jest-config]` Allow configuration objects inside `projects` array
3680
([#5176](https://github.com/facebook/jest/pull/5176))
3781
* `[expect]` Add support to `.toHaveProperty` matcher to accept the keyPath

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ accurately.
9595
```sh
9696
cd website # Only needed if you are not already in the website directory
9797
yarn
98-
yarn test
98+
yarn start
9999
```
100100
2. You can run a development server to check if the changes you made are being
101101
displayed accurately by running `yarn start` in the website directory.

README.md

Lines changed: 68 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@
55

66
🃏 Delightful JavaScript Testing
77

8-
- **👩🏻‍💻 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.
8+
- **👩🏻‍💻 Easy Setup**: Complete and easy to set-up JavaScript testing solution. Works out of the box for any React project.
99

10-
- **🏃🏽 Instant Feedback**: Failed tests run first. Fast interactive mode can switch between running all tests or only test files related to changed files.
10+
- **🏃🏽 Instant Feedback**: Fast interactive watch mode runs only test files related to changed files and is optimized to give signal quickly.
1111

12-
- **📸 Snapshot Testing**: Jest can [capture snapshots](http://facebook.github.io/jest/docs/en/snapshot-testing.html) of React trees or other serializable values to simplify testing.
12+
- **📸 Snapshot Testing**: Capture snapshots of React trees or other serializable values to simplify testing and to analyze how state changes over time.
1313

1414
## Getting Started
1515

1616
<!-- generated_getting_started_start -->
17-
Install Jest using `npm`:
17+
18+
Install Jest using [`npm`](https://www.npmjs.com/):
1819

1920
```
2021
npm install --save-dev jest
2122
```
2223

23-
Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a `sum.js` file:
24+
Or via [`yarn`](https://yarnpkg.com/en/package/jest):
25+
26+
```
27+
yarn add --dev jest
28+
```
29+
30+
Let's get started by writing a test for a hypothetical function that adds two
31+
numbers. First, create a `sum.js` file:
2432

2533
```javascript
2634
function sum(a, b) {
@@ -58,33 +66,51 @@ PASS ./sum.test.js
5866

5967
**You just successfully wrote your first test using Jest!**
6068

61-
This test used `expect` and `toBe` to test that two values were exactly identical. To learn about the other things that Jest can test, see [Using Matchers](https://facebook.github.io/jest/docs/en/using-matchers.html).
69+
This test used `expect` and `toBe` to test that two values were exactly
70+
identical. To learn about the other things that Jest can test, see
71+
[Using Matchers](https://facebook.github.io/jest/docs/using-matchers.html).
6272

6373
## Running from command line
6474

65-
You can run Jest directly from the CLI (if it's globally available in your `PATH`, e.g. by `npm install -g jest`) with variety of useful options.
75+
You can run Jest directly from the CLI (if it's globally available in your
76+
`PATH`, e.g. by `npm install -g jest`) with variety of useful options.
6677

67-
Here's how to run Jest on files matching `my-test`, using `config.json` as a configuration file and display a native OS notification after the run:
78+
Here's how to run Jest on files matching `my-test`, using `config.json` as a
79+
configuration file and display a native OS notification after the run:
6880

6981
```bash
7082
jest my-test --notify --config=config.json
7183
```
7284

73-
If you'd like to learn more about running `jest` through the command line, take a look at the [Jest CLI Options](https://facebook.github.io/jest/docs/en/cli.html) page.
85+
If you'd like to learn more about running `jest` through the command line, take
86+
a look at the [Jest CLI Options](https://facebook.github.io/jest/docs/cli.html) page.
7487

7588
## Additional Configuration
7689

7790
### Using Babel
7891

79-
To use [Babel](http://babeljs.io/), install the `babel-jest` and `regenerator-runtime` packages:
92+
To use [Babel](http://babeljs.io/), install the `babel-jest` and
93+
`regenerator-runtime` packages:
8094

8195
```
82-
npm install --save-dev jest babel-jest regenerator-runtime
96+
npm install --save-dev babel-jest babel-core regenerator-runtime
8397
```
8498

85-
*Note: Explicitly installing `regenerator-runtime` is not needed if you use `npm` 3 or 4 or Yarn*
99+
> Note: If you are using a babel version 7 then you need to install `babel-jest`
100+
> with the following command:
101+
>
102+
> ```
103+
> npm install --save-dev babel-jest 'babel-core@^7.0.0-0' @babel/core regenerator-runtime
104+
> ```
105+
106+
_Note: Explicitly installing `regenerator-runtime` is not needed if you use
107+
`npm` 3 or 4 or Yarn_
86108
87-
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://facebook.github.io/react/) with the [`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
109+
Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file
110+
in your project's root folder. For example, if you are using ES6 and
111+
[React.js](https://facebook.github.io/react/) with the
112+
[`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and
113+
[`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
88114
89115
```json
90116
{
@@ -94,11 +120,30 @@ Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file
94120
95121
You are now set up to use all ES6 features and React specific syntax.
96122

97-
> Note: If you are using a more complicated Babel configuration, using Babel's `env` option,
98-
keep in mind that Jest will automatically define `NODE_ENV` as `test`.
99-
It will not use `development` section like Babel does by default when no `NODE_ENV` is set.
123+
> Note: If you are using a more complicated Babel configuration, using Babel's
124+
> `env` option, keep in mind that Jest will automatically define `NODE_ENV` as
125+
> `test`. It will not use `development` section like Babel does by default when
126+
> no `NODE_ENV` is set.
127+
128+
> Note: If you've turned off transpilation of ES2015 modules with the option
129+
> `{ "modules": false }`, you have to make sure to turn this on in your test
130+
> environment.
131+
132+
```json
133+
{
134+
"presets": [["es2015", {"modules": false}], "react"],
135+
"env": {
136+
"test": {
137+
"presets": [["es2015"], "react"]
138+
}
139+
}
140+
}
141+
```
100142

101-
> Note: `babel-jest` is automatically installed when installing Jest and will automatically transform files if a babel configuration exists in your project. To avoid this behavior, you can explicitly reset the `transform` configuration option:
143+
> Note: `babel-jest` is automatically installed when installing Jest and will
144+
> automatically transform files if a babel configuration exists in your project.
145+
> To avoid this behavior, you can explicitly reset the `transform` configuration
146+
> option:
102147
103148
```json
104149
// package.json
@@ -111,36 +156,15 @@ It will not use `development` section like Babel does by default when no `NODE_E
111156

112157
### Using webpack
113158

114-
Jest can be used in projects that use [webpack](https://webpack.github.io/) to manage assets, styles, and compilation. webpack does offer some unique challenges over other tools. Refer to the [webpack guide](https://facebook.github.io/jest/docs/en/webpack.html) to get started.
159+
Jest can be used in projects that use [webpack](https://webpack.github.io/) to
160+
manage assets, styles, and compilation. webpack does offer some unique
161+
challenges over other tools. Refer to the [webpack guide](Webpack.md) to get
162+
started.
115163

116164
### Using TypeScript
117165

118-
To use TypeScript in your tests, install the `ts-jest` package and the types for Jest.
119-
120-
```
121-
npm install --save-dev jest ts-jest @types/jest
122-
```
123-
124-
then modify your `package.json` so the `jest` section looks something like:
125-
126-
```json
127-
{
128-
"jest": {
129-
"transform": {
130-
"^.+\\.tsx?$": "ts-jest"
131-
},
132-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
133-
"moduleFileExtensions": [
134-
"ts",
135-
"tsx",
136-
"js",
137-
"jsx",
138-
"json",
139-
"node"
140-
]
141-
}
142-
}
143-
```
166+
To use TypeScript in your tests you can use
167+
[ts-jest](https://github.com/kulshekhar/ts-jest).
144168
<!-- generated_getting_started_end -->
145169

146170
## Documentation

docs/CLI.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ CLI options take precedence over values from the
8585
When you run `jest` with an argument, that argument is treated as a regular
8686
expression to match against files in your project. It is possible to run test
8787
suites by providing a pattern. Only the files that the pattern matches will be
88-
picked up and executed. Note: depending on your terminal, you may need to quote
89-
this argument: `jest "my.*(complex)?pattern"`.
88+
picked up and executed. Depending on your terminal, you may need to quote this
89+
argument: `jest "my.*(complex)?pattern"`. On Windows, you will need to use `/`
90+
as a path separator or escape `\` as `\\`.
9091

9192
### `--bail`
9293

@@ -104,8 +105,8 @@ If you want to inspect the cache, use `--showConfig` and look at the
104105

105106
### `--changedFilesWithAncestor`
106107

107-
When used together with `--onlyChanged` or `--watch`, it runs tests related to
108-
the current changes and the changes made in the last commit.
108+
Runs tests related to the current changes and the changes made in the last
109+
commit. Behaves similarly to `--onlyChanged`.
109110

110111
### `--ci`
111112

@@ -187,8 +188,8 @@ Write test results to a file when the `--json` option is also specified.
187188

188189
### `--lastCommit`
189190

190-
When used together with `--onlyChanged`, it will run all tests affected by file
191-
changes in the last commit made.
191+
Run all tests affected by file changes in the last commit made. Behaves
192+
similarly to `--onlyChanged`.
192193

193194
### `--listTests`
194195

@@ -276,7 +277,8 @@ Note that `column` is 0-indexed while `line` is not.
276277
### `--testPathPattern=<regex>`
277278

278279
A regexp pattern string that is matched against all tests paths before executing
279-
the test.
280+
the test. On Windows, you will need to use `/` as a path separator or escape `\`
281+
as `\\`.
280282

281283
### `--testRunner=<path>`
282284

docs/Configuration.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ For example, the following would create a global `__DEV__` variable set to
295295

296296
Note that, if you specify a global reference value (like an object or array)
297297
here, and some code mutates that value in the midst of running a test, that
298-
mutation will _not_ be persisted across test runs for other test files.
298+
mutation will _not_ be persisted across test runs for other test files. In
299+
addition the `globals` object must be json-serializable, so it can't be used
300+
to specify global functions. For that you should use `setupFiles`.
299301

300302
### `globalSetup` [string]
301303

@@ -330,7 +332,7 @@ Both inline source maps and source maps returned directly from a transformer are
330332
supported. Source map URLs are not supported because Jest may not be able to
331333
locate them. To return source maps from a transformer, the `process` function
332334
can return an object like the following. The `map` property may either be the
333-
source map object, or the source map object as a JSON string.
335+
source map object, or the source map object as a string.
334336

335337
```js
336338
return {

docs/JestObjectAPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ Executes only the macro task queue (i.e. all tasks queued by `setTimeout()` or
310310

311311
When this API is called, all timers are advanced by `msToRun` milliseconds. All
312312
pending "macro-tasks" that have been queued via `setTimeout()` or
313-
`setInterval()`, and would be executed within this timeframe will be executed.
313+
`setInterval()`, and would be executed within this time frame will be executed.
314314
Additionally if those macro-tasks schedule new macro-tasks that would be
315315
executed within the same time frame, those will be executed until there are no
316316
more macro-tasks remaining in the queue, that should be run within `msToRun`

docs/JestPlatform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ module.exports = {
157157
async function main() {
158158
const worker = new Worker(require.resolve('./heavy-task.js'));
159159

160-
// run 2 tasks in parellel with different arguments
160+
// run 2 tasks in parallel with different arguments
161161
const results = await Promise.all([
162162
worker.myHeavyTask({foo: 'bar'}),
163163
worker.myHeavyTask({bar: 'foo'}),

docs/SnapshotTesting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ which reviewers can study your changes better.
166166

167167
### Does snapshot testing only work with React components?
168168

169-
[React](TutorialReacte.md) and [React Native](TutorialReactNative.md) components
169+
[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components
170170
are a good use case for snapshot testing. However, snapshots can capture any
171171
serializable value and should be used anytime the goal is testing whether the
172172
output is correct. The Jest repository contains many examples of testing the
173173
output of Jest itself, the output of Jest's assertion library as well as log
174174
messages from various parts of the Jest codebase. See an example of
175-
[snapshotting CLI output](https://github.com/facebook/jest/blob/master/integration_tests/__tests__/console.test.js)
175+
[snapshotting CLI output](https://github.com/facebook/jest/blob/master/integration-tests/__tests__/console.test.js)
176176
in the Jest repo.
177177

178178
### What's the difference between snapshot testing and visual regression testing?

0 commit comments

Comments
 (0)