Skip to content

Commit dbe54ab

Browse files
author
Przemysław Duszyński
authored
Merge branch 'master' into jestjs#7101
2 parents d23e468 + ee9fc73 commit dbe54ab

File tree

67 files changed

+2422
-98
lines changed

Some content is hidden

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

67 files changed

+2422
-98
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
- `[jest-haste-map]` [**BREAKING**] Remove support for `@providesModule` ([#6104](https://github.com/facebook/jest/pull/6104))
1313
- `[pretty-format]` Support HTMLCollection and NodeList in DOMCollection plugin ([#7125](https://github.com/facebook/jest/pull/7125))
1414
- `[jest-runtime]` Pass the normalized configuration to script transformers ([#7148](https://github.com/facebook/jest/pull/7148))
15+
- `[jest-runtime]` If `require` fails without a file extension, print all files that match with one ([#7160](https://github.com/facebook/jest/pull/7160))
16+
- `[jest-haste-map]` Make `ignorePattern` optional ([#7166](https://github.com/facebook/jest/pull/7166))
17+
- `[jest-runtime]` Remove `cacheDirectory` from `ignorePattern` for `HasteMap` if not necessary ([#7166](https://github.com/facebook/jest/pull/7166))
1518

1619
### Fixes
1720

@@ -36,10 +39,16 @@
3639
- `[jest-circus]` Better error message when a describe block is empty ([#6372](https://github.com/facebook/jest/pull/6372))
3740
- `[jest-cli]` Fix unhandled error when a bad revision is provided to `changedSince` ([#7115](https://github.com/facebook/jest/pull/7115))
3841
- `[jest-config]` Moved dynamically assigned `cwd` from `jest-cli` to default configuration in `jest-config` ([#7146](https://github.com/facebook/jest/pull/7146))
42+
- `[jest-config]` Fix `getMaxWorkers` on termux ([#7154](https://github.com/facebook/jest/pull/7154))
43+
- `[jest-runtime]` Throw an explicit error if `js` is missing from `moduleFileExtensions` ([#7160](https://github.com/facebook/jest/pull/7160))
44+
- `[jest-runtime]` Fix missing coverage when using negative glob pattern in `testMatch` ([#7170](https://github.com/facebook/jest/pull/7170))
45+
- `[*]` Ensure `maxWorkers` is at least 1 (was 0 in some cases where there was only 1 CPU) ([#7182](https://github.com/facebook/jest/pull/7182))
3946
- `[jest-cli]` Fix watch mode filename/test name filtering is not taken into account for coverage calculation with collectCoverageFrom set ([#7153](https://github.com/facebook/jest/pull/7153))
4047

48+
4149
### Chore & Maintenance
4250

51+
- `[docs]` Add synchronous test.each setup ([#7150](https://github.com/facebook/jest/pull/7150))
4352
- `[docs]` Add `this.extend` to the Custom Matchers API reference ([#7130](https://github.com/facebook/jest/pull/7130))
4453
- `[docs]` Fix default value for `coverageReporters` value in configuration docs ([#7126](https://github.com/facebook/jest/pull/7126))
4554
- `[docs]` Add link for jest-extended in expect docs ([#7078](https://github.com/facebook/jest/pull/7078))
@@ -53,8 +62,13 @@
5362
- `[*]` Bump dated dependencies ([#6978](https://github.com/facebook/jest/pull/6978))
5463
- `[scripts]` Don’t make empty subfolders for ignored files in build folder ([#7001](https://github.com/facebook/jest/pull/7001))
5564
- `[docs]` Add missing export statement in `puppeteer_environment.js` under `docs/Puppeteer.md` ([#7127](https://github.com/facebook/jest/pull/7127))
65+
- `[docs]` Removed useless expect.assertions in `TestingAsyncCode.md` ([#7131](https://github.com/facebook/jest/pull/7131))
5666
- `[docs]` Remove references to `@providesModule` which isn't supported anymore ([#7147](https://github.com/facebook/jest/pull/7147))
5767

68+
### Performance
69+
70+
- `[jest-mock]` Improve `getType` function performance. ([#7159](https://github.com/facebook/jest/pull/7159))
71+
5872
## 23.6.0
5973

6074
### Features

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ Facebook has adopted a Code of Conduct that we expect project participants to ad
183183
184184
Read our [contributing guide](CONTRIBUTING.md) to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Jest.
185185
186-
### [Good First Issues](https://github.com/facebook/jest/labels/Good%20First%20Issue%20%3Awave%3A)
186+
### [Good First Issues](https://github.com/facebook/jest/labels/%3Awave%3A%20Good%20First%20Issue)
187187
188-
To help you get your feet wet and get you familiar with our contribution process, we have a list of [good first issues](https://github.com/facebook/jest/labels/Good%20First%20Issue%20%3Awave%3A) that contain bugs which have a relatively limited scope. This is a great place to get started.
188+
To help you get your feet wet and get you familiar with our contribution process, we have a list of [good first issues](https://github.com/facebook/jest/labels/%3Awave%3A%20Good%20First%20Issue) that contain bugs which have a relatively limited scope. This is a great place to get started.
189189
190190
## Credits
191191

docs/CLI.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Forces test results output highlighting even if stdout is not a TTY.
131131

132132
### `--config=<path>`
133133

134-
Alias: `-c`. The path to a Jest config file specifying how to find and execute tests. If no `rootDir` is set in the config, the current directory is assumed to be the rootDir for the project. This can also be a JSON-encoded value which Jest will use as configuration.
134+
Alias: `-c`. The path to a Jest config file specifying how to find and execute tests. If no `rootDir` is set in the config, the directory containing the config file is assumed to be the rootDir for the project. This can also be a JSON-encoded value which Jest will use as configuration.
135135

136136
### `--coverage`
137137

docs/Configuration.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ For example, with the following configuration:
237237
"statements": 40
238238
},
239239
"./src/reducers/**/*.js": {
240-
"statements": 90,
240+
"statements": 90
241241
},
242242
"./src/api/very-important-module.js": {
243243
"branches": 100,
@@ -777,6 +777,8 @@ class CustomEnvironment extends NodeEnvironment {
777777
return super.runScript(script);
778778
}
779779
}
780+
781+
module.exports = CustomEnvironment;
780782
```
781783

782784
```js

docs/TestingAsyncCode.md

-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ For example, let's say that `fetchData`, instead of using a callback, returns a
4949

5050
```js
5151
test('the data is peanut butter', () => {
52-
expect.assertions(1);
5352
return fetchData().then(data => {
5453
expect(data).toBe('peanut butter');
5554
});
@@ -73,7 +72,6 @@ You can also use the `.resolves` matcher in your expect statement, and Jest will
7372

7473
```js
7574
test('the data is peanut butter', () => {
76-
expect.assertions(1);
7775
return expect(fetchData()).resolves.toBe('peanut butter');
7876
});
7977
```
@@ -84,7 +82,6 @@ If you expect a promise to be rejected use the `.rejects` matcher. It works anal
8482

8583
```js
8684
test('the fetch fails with an error', () => {
87-
expect.assertions(1);
8885
return expect(fetchData()).rejects.toMatch('error');
8986
});
9087
```
@@ -114,12 +111,10 @@ Of course, you can combine `async` and `await` with `.resolves` or `.rejects`.
114111

115112
```js
116113
test('the data is peanut butter', async () => {
117-
expect.assertions(1);
118114
await expect(fetchData()).resolves.toBe('peanut butter');
119115
});
120116

121117
test('the fetch fails with an error', async () => {
122-
expect.assertions(1);
123118
await expect(fetchData()).rejects.toThrow('error');
124119
});
125120
```

docs/Troubleshooting.md

+17
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ Jest takes advantage of new features added to Node 6. We recommend that you upgr
192192
193193
Make sure you are not using the `babel-plugin-istanbul` plugin. Jest wraps Istanbul, and therefore also tells Istanbul what files to instrument with coverage collection. When using `babel-plugin-istanbul`, every file that is processed by Babel will have coverage collection code, hence it is not being ignored by `coveragePathIgnorePatterns`.
194194
195+
## Defining Tests
196+
197+
Tests must be defined synchronously for Jest to be able to collect your tests.
198+
199+
As an example to show why this is the case, imagine we wrote a test like so:
200+
201+
```js
202+
// Don't do this it will not work
203+
setTimeout(() => {
204+
it('passes', () => expect(1).toBe(1));
205+
}, 0);
206+
```
207+
208+
When Jest runs your test to collect the `test`s it will not find any because we have set the definition to happen asynchronously on the next tick of the event loop.
209+
210+
_Note:_ This means when you are using `test.each` you cannot set the table asynchronously within a `beforeEach` / `beforeAll`.
211+
195212
## Still unresolved?
196213

197214
See [Help](/help.html).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`show error message when no js moduleFileExtensions 1`] = `
4+
"● Validation Error:
5+
6+
moduleFileExtensions must include 'js':
7+
but instead received:
8+
[\\"jsx\\"]
9+
Please change your configuration to include 'js'.
10+
11+
Configuration Documentation:
12+
https://jestjs.io/docs/configuration.html
13+
14+
"
15+
`;
16+
17+
exports[`show error message with matching files 1`] = `
18+
"FAIL __tests__/test.js
19+
● Test suite failed to run
20+
21+
Cannot find module './some-json-file' from 'index.js'
22+
23+
However, Jest was able to find:
24+
'./some-json-file.json'
25+
26+
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js'].
27+
28+
See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
29+
30+
> 1 | module.exports = require('./some-json-file');
31+
| ^
32+
2 |
33+
34+
at packages/jest-resolve/build/index.js:221:17
35+
at index.js:1:18
36+
37+
"
38+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
'use strict';
10+
11+
import path from 'path';
12+
import runJest from '../runJest';
13+
import {cleanup, extractSummary, writeFiles} from '../Utils';
14+
15+
const DIR = path.resolve(__dirname, '../resolve_no_extensions-no-js');
16+
17+
beforeEach(() => cleanup(DIR));
18+
afterAll(() => cleanup(DIR));
19+
20+
test('show error message with matching files', () => {
21+
const {status, stderr} = runJest('resolve_no_extensions');
22+
const {rest} = extractSummary(stderr);
23+
24+
expect(status).toBe(1);
25+
expect(rest).toMatchSnapshot();
26+
});
27+
28+
test('show error message when no js moduleFileExtensions', () => {
29+
writeFiles(DIR, {
30+
'index.jsx': `
31+
module.exports ={found: true};
32+
`,
33+
'package.json': `
34+
{
35+
"jest": {
36+
"moduleFileExtensions": ["jsx"]
37+
}
38+
}
39+
`,
40+
'test.jsx': `
41+
const m = require('../');
42+
43+
test('some test', () => {
44+
expect(m.found).toBe(true);
45+
});
46+
`,
47+
});
48+
49+
const {status, stderr} = runJest('resolve_no_extensions-no-js');
50+
51+
expect(status).toBe(1);
52+
expect(stderr).toMatchSnapshot();
53+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const m = require('../');
2+
3+
test('some test', () => {
4+
expect(m.found).toBe(true);
5+
});

e2e/resolve_no_extensions/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./some-json-file');
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"jest": {
3+
"moduleFileExtensions": [
4+
"js"
5+
]
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"found": true
3+
}

flow-typed/npm/glob_v7.1.x.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// flow-typed signature: 7c09aef8ac07163d6ef9e3f50c6bc35c
2+
// flow-typed version: a12a42a747/glob_v7.1.x/flow_>=v0.42.x
3+
4+
declare module "glob" {
5+
declare type MinimatchOptions = {|
6+
debug?: boolean,
7+
nobrace?: boolean,
8+
noglobstar?: boolean,
9+
dot?: boolean,
10+
noext?: boolean,
11+
nocase?: boolean,
12+
nonull?: boolean,
13+
matchBase?: boolean,
14+
nocomment?: boolean,
15+
nonegate?: boolean,
16+
flipNegate?: boolean
17+
|};
18+
19+
declare type Options = {|
20+
...MinimatchOptions,
21+
cwd?: string,
22+
root?: string,
23+
nomount?: boolean,
24+
mark?: boolean,
25+
nosort?: boolean,
26+
stat?: boolean,
27+
silent?: boolean,
28+
strict?: boolean,
29+
cache?: {
30+
[path: string]: boolean | "DIR" | "FILE" | $ReadOnlyArray<string>
31+
},
32+
statCache?: {
33+
[path: string]: boolean | { isDirectory(): boolean } | void
34+
},
35+
symlinks?: { [path: string]: boolean | void },
36+
realpathCache?: { [path: string]: string },
37+
sync?: boolean,
38+
nounique?: boolean,
39+
nodir?: boolean,
40+
ignore?: string | $ReadOnlyArray<string>,
41+
follow?: boolean,
42+
realpath?: boolean,
43+
absolute?: boolean
44+
|};
45+
46+
/**
47+
* Called when an error occurs, or matches are found
48+
* err
49+
* matches: filenames found matching the pattern
50+
*/
51+
declare type CallBack = (err: ?Error, matches: Array<string>) => void;
52+
53+
declare class Glob extends events$EventEmitter {
54+
constructor(pattern: string): this;
55+
constructor(pattern: string, callback: CallBack): this;
56+
constructor(pattern: string, options: Options, callback: CallBack): this;
57+
58+
minimatch: {};
59+
options: Options;
60+
aborted: boolean;
61+
cache: {
62+
[path: string]: boolean | "DIR" | "FILE" | $ReadOnlyArray<string>
63+
};
64+
statCache: {
65+
[path: string]: boolean | { isDirectory(): boolean } | void
66+
};
67+
symlinks: { [path: string]: boolean | void };
68+
realpathCache: { [path: string]: string };
69+
found: Array<string>;
70+
71+
pause(): void;
72+
resume(): void;
73+
abort(): void;
74+
}
75+
76+
declare class GlobModule {
77+
Glob: Class<Glob>;
78+
79+
(pattern: string, callback: CallBack): void;
80+
(pattern: string, options: Options, callback: CallBack): void;
81+
82+
hasMagic(pattern: string, options?: Options): boolean;
83+
sync(pattern: string, options?: Options): Array<string>;
84+
}
85+
86+
declare module.exports: GlobModule;
87+
}

jest.config.ci.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Object spread is just node 8
44
module.exports = Object.assign({}, require('./jest.config'), {
5+
coverageReporters: ['json'],
56
reporters: [
67
['jest-junit', {output: 'reports/junit/js-test-results.xml'}],
78
['jest-silent-reporter', {useDots: true}],

jest.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ module.exports = {
88
'!**/perf/**',
99
'!**/__mocks__/**',
1010
'!**/__tests__/**',
11+
'!**/build/**',
12+
'!**/vendor/**',
1113
'!e2e/**',
1214
],
13-
coverageReporters: ['json'],
1415
modulePathIgnorePatterns: [
1516
'examples/.*',
1617
'packages/.*/build',

0 commit comments

Comments
 (0)