Skip to content

Commit 589c9dc

Browse files
authored
Merge branch 'main' into uncaught-rejection-fix
2 parents ff43936 + 95f4969 commit 589c9dc

42 files changed

Lines changed: 409 additions & 140 deletions

Some content is hidden

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

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
steps:
5050
- checkout
5151
- node/install:
52-
lts: true
52+
node-version: '14'
5353
install-npm: false
5454
- node/install-packages: *install
5555
- run:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
### Features
44

5+
- `[jest-core]` Add support for `testResultsProcessor` written in ESM ([#12006](https://github.com/facebook/jest/pull/12006))
6+
- `[jest-diff, pretty-format]` Add `compareKeys` option for custom sorting of object keys ([#11992](https://github.com/facebook/jest/pull/11992))
7+
58
### Fixes
69

710
- `[expect]` Allow again `expect.Matchers` generic with single value ([#11986](https://github.com/facebook/jest/pull/11986))
811
- `[jest-circus, jest-jasmine2]` Avoid false concurrent test failures due to unhandled promise rejections ([#11987](https://github.com/facebook/jest/pull/11987))
12+
- `[jest-core]` Incorrect detection of open ZLIB handles ([#12022](https://github.com/facebook/jest/pull/12022))
913
- `[jest-environment-jsdom]` Add `@types/jsdom` dependency ([#11999](https://github.com/facebook/jest/pull/11999))
14+
- `[jest-transform]` Improve error and warning messages ([#11998](https://github.com/facebook/jest/pull/11998))
1015

1116
### Chore & Maintenance
1217

docs/CodeTransformation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ If you override the `transform` configuration option `babel-jest` will no longer
1919

2020
## Writing custom transformers
2121

22-
You can write you own transformer. The API of a transformer is as follows:
22+
You can write your own transformer. The API of a transformer is as follows:
2323

2424
```ts
2525
interface SyncTransformer<OptionType = unknown> {
@@ -124,7 +124,7 @@ type TransformedSource =
124124
// RawSourceMap comes from [`source-map`](https://github.com/mozilla/source-map/blob/0.6.1/source-map.d.ts#L6-L12)
125125
```
126126

127-
As can be seen, only `process` is mandatory to implement, although we highly recommend implementing `getCacheKey` as well, so we don't waste resources transpiling the same source file when we can read its previous result from disk. You can use [`@jest/create-cache-key-function`](https://www.npmjs.com/package/@jest/create-cache-key-function) to help implement it.
127+
As can be seen, only `process` or `processAsync` is mandatory to implement, although we highly recommend implementing `getCacheKey` as well, so we don't waste resources transpiling the same source file when we can read its previous result from disk. You can use [`@jest/create-cache-key-function`](https://www.npmjs.com/package/@jest/create-cache-key-function) to help implement it.
128128

129129
Note that [ECMAScript module](ECMAScriptModules.md) support is indicated by the passed in `supports*` options. Specifically `supportsDynamicImport: true` means the transformer can return `import()` expressions, which is supported by both ESM and CJS. If `supportsStaticESM: true` it means top level `import` statements are supported and the code will be interpreted as ESM and not CJS. See [Node's docs](https://nodejs.org/api/esm.html#esm_differences_between_es_modules_and_commonjs) for details on the differences.
130130

docs/JestObjectAPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ test('plays audio', () => {
556556

557557
### `jest.clearAllMocks()`
558558

559-
Clears the `mock.calls` and `mock.instances` properties of all mocks. Equivalent to calling [`.mockClear()`](MockFunctionAPI.md#mockfnmockclear) on every mocked function.
559+
Clears the `mock.calls`, `mock.instances` and `mock.results` properties of all mocks. Equivalent to calling [`.mockClear()`](MockFunctionAPI.md#mockfnmockclear) on every mocked function.
560560

561561
Returns the `jest` object for chaining.
562562

docs/MockFunctionAPI.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,16 @@ mockFn.mock.instances[1] === b; // true
8181

8282
### `mockFn.mockClear()`
8383

84-
Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls) and [`mockFn.mock.instances`](#mockfnmockinstances) arrays.
84+
Resets all information stored in the [`mockFn.mock.calls`](#mockfnmockcalls), [`mockFn.mock.instances`](#mockfnmockinstances) and [`mockFn.mock.results`](#mockfnmockresults) arrays. Often this is useful when you want to clean up a mocks usage data between two assertions.
8585

86-
Often this is useful when you want to clean up a mocks usage data between two assertions.
87-
88-
Beware that `mockClear` will replace `mockFn.mock`, not just [`mockFn.mock.calls`](#mockfnmockcalls) and [`mockFn.mock.instances`](#mockfnmockinstances). You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data.
89-
90-
The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests.
86+
Beware that `mockClear` will replace `mockFn.mock`, not just these three properties! You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data. The [`clearMocks`](configuration#clearmocks-boolean) configuration option is available to clear mocks automatically between tests.
9187

9288
### `mockFn.mockReset()`
9389

9490
Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also removes any mocked return values or implementations.
9591

9692
This is useful when you want to completely reset a _mock_ back to its initial state. (Note that resetting a _spy_ will result in a function with no return value).
9793

98-
Beware that `mockReset` will replace `mockFn.mock`, not just [`mockFn.mock.calls`](#mockfnmockcalls) and [`mockFn.mock.instances`](#mockfnmockinstances). You should, therefore, avoid assigning `mockFn.mock` to other variables, temporary or not, to make sure you don't access stale data.
99-
10094
### `mockFn.mockRestore()`
10195

10296
Does everything that [`mockFn.mockReset()`](#mockfnmockreset) does, and also restores the original (non-mocked) implementation.

e2e/__tests__/testResultsProcessor.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*/
77

88
import * as path from 'path';
9+
import {onNodeVersions} from '@jest/test-utils';
910
import {json as runWithJson} from '../runJest';
1011

11-
test('testNamePattern', () => {
12+
test('testResultsProcessor', () => {
1213
const processorPath = path.resolve(
1314
__dirname,
1415
'../test-results-processor/processor.js',
@@ -19,3 +20,18 @@ test('testNamePattern', () => {
1920
]);
2021
expect(json.processed).toBe(true);
2122
});
23+
24+
// The versions where vm.Module exists and commonjs with "exports" is not broken
25+
onNodeVersions('>=12.16.0', () => {
26+
test('testResultsProcessor written in ESM', () => {
27+
const processorPath = path.resolve(
28+
__dirname,
29+
'../test-results-processor/processor.mjs',
30+
);
31+
const {json} = runWithJson('test-results-processor', [
32+
'--json',
33+
`--testResultsProcessor=${processorPath}`,
34+
]);
35+
expect(json.processed).toBe(true);
36+
});
37+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
8+
export default function (results) {
9+
results.processed = true;
10+
return results;
11+
}

packages/jest-circus/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const TEST_TIMEOUT_SYMBOL = Symbol.for(
2121
) as unknown as 'TEST_TIMEOUT_SYMBOL';
2222

2323
declare global {
24-
module NodeJS {
24+
namespace NodeJS {
2525
interface Global {
2626
STATE_SYM_SYMBOL: Circus.State;
2727
RETRY_TIMES_SYMBOL: string;

packages/jest-core/src/__tests__/collectHandles.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {promises as dns} from 'dns';
1010
import http from 'http';
1111
import {PerformanceObserver} from 'perf_hooks';
12+
import zlib from 'zlib';
1213
import collectHandles from '../collectHandles';
1314

1415
describe('collectHandles', () => {
@@ -52,6 +53,20 @@ describe('collectHandles', () => {
5253
);
5354
});
5455

56+
it('should not collect the ZLIB open handle', async () => {
57+
const handleCollector = collectHandles();
58+
59+
const decompressed = zlib.inflateRawSync(
60+
Buffer.from('cb2a2d2e5128492d2ec9cc4b0700', 'hex'),
61+
);
62+
63+
const openHandles = await handleCollector();
64+
65+
expect(openHandles).not.toContainEqual(
66+
expect.objectContaining({message: 'ZLIB'}),
67+
);
68+
});
69+
5570
it('should collect handles opened in test functions with `done` callbacks', done => {
5671
const handleCollector = collectHandles();
5772
const server = http.createServer((_, response) => response.end('ok'));

packages/jest-core/src/collectHandles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default function collectHandles(): HandleCollectionResult {
7171
type === 'ELDHISTOGRAM' ||
7272
type === 'PerformanceObserver' ||
7373
type === 'RANDOMBYTESREQUEST' ||
74-
type === 'DNSCHANNEL'
74+
type === 'DNSCHANNEL' ||
75+
type === 'ZLIB'
7576
) {
7677
return;
7778
}

0 commit comments

Comments
 (0)