Skip to content

Commit 76ca2f0

Browse files
authored
Merge branch 'master' into property-based
2 parents 102d2b8 + c15b7a5 commit 76ca2f0

File tree

250 files changed

+5871
-4122
lines changed

Some content is hidden

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

250 files changed

+5871
-4122
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module.exports = {
2020
parser: '@typescript-eslint/parser',
2121
plugins: ['@typescript-eslint/eslint-plugin'],
2222
rules: {
23+
'@typescript-eslint/array-type': ['error', 'generic'],
24+
'@typescript-eslint/ban-types': 'error',
2325
'@typescript-eslint/no-unused-vars': [
2426
'error',
2527
{argsIgnorePattern: '^_'},

.flowconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ untyped-import
1313
untyped-type-import
1414

1515
[version]
16-
^0.93.0
16+
^0.94.0
1717

1818
[options]
1919
module.name_mapper='^pretty-format$' -> '<PROJECT_ROOT>/packages/pretty-format/src/index.js'

CHANGELOG.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
- `[expect]`: Improve report when matcher fails, part 8 ([#7876](https://github.com/facebook/jest/pull/7876))
77
- `[expect]`: Improve report when matcher fails, part 9 ([#7940](https://github.com/facebook/jest/pull/7940))
88
- `[expect]`: Improve report when matcher fails, part 10 ([#7960](https://github.com/facebook/jest/pull/7960))
9+
- `[expect]`: Improve report when matcher fails, part 11 ([#8008](https://github.com/facebook/jest/pull/8008))
910
- `[pretty-format]` Support `React.memo` ([#7891](https://github.com/facebook/jest/pull/7891))
1011
- `[jest-config]` Print error information on preset normalization error ([#7935](https://github.com/facebook/jest/pull/7935))
12+
- `[jest-haste-map]` Add `skipPackageJson` option ([#7778](https://github.com/facebook/jest/pull/7778))
13+
- `[jest-get-type]` Add `isPrimitive` function ([#7708](https://github.com/facebook/jest/pull/7708))
1114

1215
### Fixes
1316

17+
- `[jest-environment-node]` Add mising globals: TextEncoder and TextDecoder ([#8022](https://github.com/facebook/jest/pull/8022))
1418
- `[jest-cli]` Fix prototype pollution vulnerability in dependency ([#7904](https://github.com/facebook/jest/pull/7904))
1519
- `[jest-cli]` Refactor `-o` and `--coverage` combined ([#7611](https://github.com/facebook/jest/pull/7611))
1620
- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652))
@@ -22,25 +26,34 @@
2226
- `[jest-transform]` Normalize config and remove unecessary checks, convert `TestUtils.js` to TypeScript ([#7801](https://github.com/facebook/jest/pull/7801))
2327
- `[jest-worker]` Fix `jest-worker` when using pre-allocated jobs ([#7934](https://github.com/facebook/jest/pull/7934))
2428
- `[jest-changed-files]` Fix `getChangedFilesFromRoots` to not return parts of the commit messages as if they were files, when the commit messages contained multiple paragraphs ([#7961](https://github.com/facebook/jest/pull/7961))
29+
- `[jest-haste-map]` Enforce uniqueness in names (mocks and haste ids) ([#8002](https://github.com/facebook/jest/pull/8002))
2530
- `[static]` Remove console log '-' on the front page
31+
- `[expect]` Fix non-object received value in toHaveProperty ([#7986](https://github.com/facebook/jest/pull/7986))
32+
- `[jest-jasmine2]`: Throw explicit error when errors happen after test is considered complete ([#8005](https://github.com/facebook/jest/pull/8005))
33+
- `[jest-circus]`: Throw explicit error when errors happen after test is considered complete ([#8005](https://github.com/facebook/jest/pull/8005))
34+
- `[expect]` Remove duck typing and obsolete browser support code when comparing DOM nodes and use DOM-Level-3 API instead ([#7995](https://github.com/facebook/jest/pull/7995))
35+
- `[jest-mock]` Adds a type check to `prototype` to allow mocks of objects with a primitive `prototype` property. ([#8040](https://github.com/facebook/jest/pull/8040))
2636

2737
### Chore & Maintenance
2838

39+
- `[jest-each]`: Refactor into multiple files with better types ([#8018](https://github.com/facebook/jest/pull/8018))
40+
- `[jest-each]`: Migrate to Typescript ([#8007](https://github.com/facebook/jest/pull/8007))
41+
- `[jest-environment-jsdom]`: Migrate to TypeScript ([#7985](https://github.com/facebook/jest/pull/8003))
2942
- `[jest-environment-node]`: Migrate to TypeScript ([#7985](https://github.com/facebook/jest/pull/7985))
3043
- `[*]`: Setup building, linting and testing of TypeScript ([#7808](https://github.com/facebook/jest/pull/7808), [#7855](https://github.com/facebook/jest/pull/7855), [#7951](https://github.com/facebook/jest/pull/7951))
3144
- `[pretty-format]`: Migrate to TypeScript ([#7809](https://github.com/facebook/jest/pull/7809), [#7809](https://github.com/facebook/jest/pull/7972))
3245
- `[diff-sequences]`: Migrate to Typescript ([#7820](https://github.com/facebook/jest/pull/7820))
3346
- `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818))
3447
- `[jest-regex-util]`: Migrate to TypeScript ([#7822](https://github.com/facebook/jest/pull/7822))
35-
- `[jest-diff]`: Migrate to TypeScript ([#7824](https://github.com/facebook/jest/pull/7824))
48+
- `[jest-diff]`: Migrate to TypeScript ([#7824](https://github.com/facebook/jest/pull/7824), [#8027](https://github.com/facebook/jest/pull/8027))
3649
- `[jest-leak-detector]`: Migrate to TypeScript ([#7825](https://github.com/facebook/jest/pull/7825))
3750
- `[jest-changed-files]`: Migrate to TypeScript ([#7827](https://github.com/facebook/jest/pull/7827))
3851
- `[jest-matcher-utils]`: Migrate to TypeScript ([#7835](https://github.com/facebook/jest/pull/7835))
3952
- `[jest-docblock]`: Migrate to TypeScript ([#7836](https://github.com/facebook/jest/pull/7836))
4053
- `[jest-serializer]`: Migrate to TypeScript ([#7841](https://github.com/facebook/jest/pull/7841))
4154
- `[jest-message-util]`: Migrate to TypeScript ([#7834](https://github.com/facebook/jest/pull/7834))
4255
- `[@jest/types]`: New package to handle shared types ([#7834](https://github.com/facebook/jest/pull/7834))
43-
- `[jest-util]`: Migrate to TypeScript ([#7844](https://github.com/facebook/jest/pull/7844))
56+
- `[jest-util]`: Migrate to TypeScript ([#7844](https://github.com/facebook/jest/pull/7844), [#8021](https://github.com/facebook/jest/pull/8021))
4457
- `[jest-watcher]`: Migrate to TypeScript ([#7843](https://github.com/facebook/jest/pull/7843))
4558
- `[jest-mock]`: Migrate to TypeScript ([#7847](https://github.com/facebook/jest/pull/7847), [#7850](https://github.com/facebook/jest/pull/7850), [#7971](https://github.com/facebook/jest/pull/7971))
4659
- `[jest-worker]`: Migrate to TypeScript ([#7853](https://github.com/facebook/jest/pull/7853))
@@ -56,12 +69,21 @@
5669
- `[@jest/transform]`: Migrate to TypeScript ([#7918](https://github.com/facebook/jest/pull/7918), [#7945](https://github.com/facebook/jest/pull/7945))
5770
- `[docs]` Add missing import to docs ([#7928](https://github.com/facebook/jest/pull/7928))
5871
- `[jest-resolve-dependencies]`: Migrate to TypeScript ([#7922](https://github.com/facebook/jest/pull/7922))
59-
- `[expect]`: Migrate to TypeScript ([#7919](https://github.com/facebook/jest/pull/7919))
72+
- `[expect]`: Migrate to TypeScript ([#7919](https://github.com/facebook/jest/pull/7919), [#8028](https://github.com/facebook/jest/pull/8028))
6073
- `[jest-circus]`: Migrate to TypeScript ([#7916](https://github.com/facebook/jest/pull/7916))
6174
- `[jest-phabricator]`: Migrate to TypeScript ([#7965](https://github.com/facebook/jest/pull/7965))
6275
- `[jest-runner]`: Migrate to TypeScript ([#7968](https://github.com/facebook/jest/pull/7968))
6376
- `[jest-runtime]`: Migrate to TypeScript ([#7964](https://github.com/facebook/jest/pull/7964), [#7988](https://github.com/facebook/jest/pull/7988))
6477
- `[@jest/fake-timers]`: Extract FakeTimers class from `jest-util` into a new separate package ([#7987](https://github.com/facebook/jest/pull/7987))
78+
- `[@jest/reporters]`: Migrate to TypeScript ([#7994](https://github.com/facebook/jest/pull/7994), [#8045](https://github.com/facebook/jest/pull/8045))
79+
- `[jest-repl]`: Migrate to TypeScript ([#8000](https://github.com/facebook/jest/pull/8000))
80+
- `[jest-validate]`: Migrate to TypeScript ([#7991](https://github.com/facebook/jest/pull/7991))
81+
- `[docs]`: Update CONTRIBUTING.md to add information about running jest with `jest-circus` locally ([#8013](https://github.com/facebook/jest/pull/8013)).
82+
- `[@jest/core]`: Migrate to TypeScript ([#7998](https://github.com/facebook/jest/pull/7998))
83+
- `[docs]` Update/Organize TestSequencer and testSchedulerHelper code comments([#7984](https://github.com/facebook/jest/pull/7984))
84+
- `[@jest/source-map]`: Extract `getCallsite` function from `jest-util` into a new separate package ([#8029](https://github.com/facebook/jest/pull/8029))
85+
- `[@jest/console]`: Extract custom `console` implementations from `jest-util` into a new separate package ([#8030](https://github.com/facebook/jest/pull/8030))
86+
- `[docs]`: Improve runAllTimers doc (it exhausts the micro-task queue) ([#8031](https://github.com/facebook/jest/pull/8031))
6587

6688
### Performance
6789

@@ -92,6 +114,7 @@
92114
- `[jest-runtime]` Exclude setup/teardown files from coverage report ([#7790](https://github.com/facebook/jest/pull/7790)
93115
- `[babel-jest]` Throw an error if `babel-jest` tries to transform a file ignored by Babel ([#7797](https://github.com/facebook/jest/pull/7797))
94116
- `[babel-plugin-jest-hoist]` Ignore TS type references when looking for out-of-scope references ([#7799](https://github.com/facebook/jest/pull/7799)
117+
- `[expect]` fixed asymmetrical equality of cyclic objects ([#7730](https://github.com/facebook/jest/pull/7730))
95118

96119
### Chore & Maintenance
97120

@@ -492,7 +515,7 @@
492515
- `[jest-jasmine2]` Add stack trace for thrown non-`Error`s ([#6008](https://github.com/facebook/jest/pull/6008))
493516
- `[jest-runtime]` Prevent modules from marking themselves as their own parent ([#5235](https://github.com/facebook/jest/issues/5235))
494517
- `[jest-mock]` Add support for auto-mocking generator functions ([#5983](https://github.com/facebook/jest/pull/5983))
495-
- `[expect]` Add support for async matchers  ([#5919](https://github.com/facebook/jest/pull/5919))
518+
- `[expect]` Add support for async matchers ([#5919](https://github.com/facebook/jest/pull/5919))
496519
- `[expect]` Suggest toContainEqual ([#5948](https://github.com/facebook/jest/pull/5953))
497520
- `[jest-config]` Export Jest's default options ([#5948](https://github.com/facebook/jest/pull/5948))
498521
- `[jest-editor-support]` Move `coverage` to `ProjectWorkspace.collectCoverage` ([#5929](https://github.com/facebook/jest/pull/5929))

CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ Time: 0.232s, estimated 1s
107107
Ran all test suites.
108108
```
109109

110+
##### Using jest-circus
111+
112+
There may be cases where you want to run jest using `jest-circus` instead of `jest-jasmine2` (which is the default runner) for integration testing. In situtations like this just set the environment variable `JEST_CIRCUS` to 1. That will configure jest to use `jest-circus`. So something like this.
113+
114+
```bash
115+
JEST_CIRCUS=1 yarn jest
116+
```
117+
110118
#### Additional Workflow for any changes made to website or docs
111119

112120
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.

docs/JestObjectAPI.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ When this API is called, all pending micro-tasks that have been queued via `proc
428428

429429
### `jest.runAllTimers()`
430430

431-
Exhausts the **macro**-task queue (i.e., all tasks queued by `setTimeout()`, `setInterval()`, and `setImmediate()`).
431+
Exhausts both the **macro**-task queue (i.e., all tasks queued by `setTimeout()`, `setInterval()`, and `setImmediate()`) and the **micro**-task queue (usually interfaced in node via `process.nextTick`).
432432

433-
When this API is called, all pending "macro-tasks" that have been queued via `setTimeout()` or `setInterval()` will be executed. Additionally if those macro-tasks themselves schedule new macro-tasks, those will be continually exhausted until there are no more macro-tasks remaining in the queue.
433+
When this API is called, all pending macro-tasks and micro-tasks will be executed. If those tasks themselves schedule new tasks, those will be continually exhausted until there are no more tasks remaining in the queue.
434434

435435
This is often useful for synchronously executing setTimeouts during a test in order to synchronously assert about some behavior that would only happen after the `setTimeout()` or `setInterval()` callbacks executed. See the [Timer mocks](TimerMocks.md) doc for more information.
436436

e2e/__tests__/__snapshots__/console.test.ts.snap

+27
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ Time: <<REPLACED>>
5050
Ran all test suites.
5151
`;
5252
53+
exports[`does not error out when using winston 1`] = ``;
54+
55+
exports[`does not error out when using winston 2`] = `
56+
PASS __tests__/console.test.js
57+
● Console
58+
59+
console.log node_modules/winston/lib/winston/transports/console.js:79
60+
{"level":"info","message":"Log message from winston"}
61+
62+
console.log node_modules/winston/lib/winston/transports/console.js:79
63+
{"message":"Info message from winston","level":"info"}
64+
65+
console.log node_modules/winston/lib/winston/transports/console.js:79
66+
{"message":"Warn message from winston","level":"warn"}
67+
68+
console.log node_modules/winston/lib/winston/transports/console.js:79
69+
{"message":"Error message from winston","level":"error"}
70+
`;
71+
72+
exports[`does not error out when using winston 3`] = `
73+
Test Suites: 1 passed, 1 total
74+
Tests: 1 passed, 1 total
75+
Snapshots: 0 total
76+
Time: <<REPLACED>>
77+
Ran all test suites.
78+
`;
79+
5380
exports[`does not print to console with --silent 1`] = ``;
5481
5582
exports[`does not print to console with --silent 2`] = `PASS __tests__/console.test.js`;

e2e/__tests__/__snapshots__/consoleAfterTeardown.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ PASS __tests__/console.test.js
1515
15 | });
1616
16 |
1717
18-
at BufferedConsole.log (../../packages/jest-util/build/BufferedConsole.js:182:10)
18+
at BufferedConsole.log (../../packages/jest-console/build/BufferedConsole.js:180:10)
1919
at log (__tests__/console.test.js:13:13)
2020
`;

e2e/__tests__/console.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import path from 'path';
89
import {wrap} from 'jest-snapshot-serializer-raw';
9-
import {extractSummary} from '../Utils';
10+
import {extractSummary, run} from '../Utils';
1011
import runJest from '../runJest';
1112

1213
test('console printing', () => {
@@ -59,3 +60,15 @@ test('the jsdom console is the same as the test console', () => {
5960
expect(wrap(rest)).toMatchSnapshot();
6061
expect(wrap(summary)).toMatchSnapshot();
6162
});
63+
64+
test('does not error out when using winston', () => {
65+
const dir = path.resolve(__dirname, '../console-winston');
66+
run('yarn', dir);
67+
const {stderr, stdout, status} = runJest(dir);
68+
const {summary, rest} = extractSummary(stderr);
69+
70+
expect(status).toBe(0);
71+
expect(wrap(stdout)).toMatchSnapshot();
72+
expect(wrap(rest)).toMatchSnapshot();
73+
expect(wrap(summary)).toMatchSnapshot();
74+
});

e2e/__tests__/detectOpenHandles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ try {
2222
}
2323
}
2424

25-
function getTextAfterTest(stderr) {
25+
function getTextAfterTest(stderr: string) {
2626
return (stderr.split(/Ran all test suites(.*)\n/)[2] || '').trim();
2727
}
2828

e2e/__tests__/failures.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../failures');
1414

15-
const normalizeDots = text => text.replace(/\.{1,}$/gm, '.');
15+
const normalizeDots = (text: string) => text.replace(/\.{1,}$/gm, '.');
1616

17-
function cleanStderr(stderr) {
17+
function cleanStderr(stderr: string) {
1818
const {rest} = extractSummary(stderr);
1919
return rest
2020
.replace(/.*(jest-jasmine2|jest-circus).*\n/g, '')
@@ -182,3 +182,12 @@ test('works with named snapshot failures', () => {
182182
wrap(result.substring(0, result.indexOf('Snapshot Summary'))),
183183
).toMatchSnapshot();
184184
});
185+
186+
test('errors after test has completed', () => {
187+
const {stderr} = runJest(dir, ['errorAfterTestComplete.test.js']);
188+
189+
expect(stderr).toMatch(
190+
/Error: Caught error after test environment was torn down/,
191+
);
192+
expect(stderr).toMatch(/Failed: "fail async"/);
193+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. 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+
'use strict';
8+
9+
const winston = require('winston');
10+
const logger = winston.createLogger({
11+
transports: [new winston.transports.Console()],
12+
});
13+
14+
test('using winston should not fail', () => {
15+
logger.log('info', 'Log message from winston');
16+
17+
logger.info('Info message from winston');
18+
19+
logger.warn('Warn message from winston');
20+
21+
logger.error('Error message from winston');
22+
});

e2e/console-winston/package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node",
4+
"verbose": false
5+
},
6+
"dependencies": {
7+
"winston": "^3.2.1"
8+
}
9+
}

0 commit comments

Comments
 (0)