Skip to content

Commit cddd949

Browse files
authored
Merge branch 'main' into patch
2 parents bf0e377 + bc26cd7 commit cddd949

File tree

98 files changed

+5397
-4698
lines changed

Some content is hidden

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

98 files changed

+5397
-4698
lines changed

.github/workflows/close-stale.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Close stale issues and PRs'
22
on:
33
schedule:
4-
- cron: '*/10 * * * *'
4+
- cron: '0 * * * *'
55

66
permissions:
77
issues: write # to close stale issues (actions/stale)

CHANGELOG.md

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

33
### Features
44

5+
- `[jest-cli]` Include type definitions to generated config files ([#14078](https://github.com/facebook/jest/pull/14078))
6+
- `[jest-config]` Allow loading `jest.config.cts` files ([#14070](https://github.com/facebook/jest/pull/14070))
57
- `[jest-snapshot]` Support arrays as property matchers ([#14025](https://github.com/facebook/jest/pull/14025))
68

79
### Fixes
810

911
- `[jest-config]` Handle frozen config object ([#14054](https://github.com/facebook/jest/pull/14054))
10-
- `[jest-config]` Allow loading `jest.config.cts` files ([#14070](https://github.com/facebook/jest/pull/14070))
12+
- `[jest-core]` Always use workers in watch mode to avoid crashes ([#14059](https://github.com/facebook/jest/pull/14059)).
1113
- `[jest-environment-jsdom, jest-environment-node]` Fix assignment of `customExportConditions` via `testEnvironmentOptions` when custom env subclass defines a default value ([#13989](https://github.com/facebook/jest/pull/13989))
1214
- `[jest-matcher-utils]` Fix copying value of inherited getters ([#14007](https://github.com/facebook/jest/pull/14007))
1315
- `[jest-mock]` Tweak typings to allow `jest.replaceProperty()` replace methods ([#14008](https://github.com/facebook/jest/pull/14008))
16+
- `[jest-mock]` Improve user input validation and error messages of `spyOn` and `replaceProperty` methods ([#14087](https://github.com/facebook/jest/pull/14087))
17+
- `[jest-runtime]` Bind `jest.isolateModulesAsync` to `this` ([#14083](https://github.com/facebook/jest/pull/14083))
1418
- `[jest-snapshot]` Fix a potential bug when not using prettier and improve performance ([#14036](https://github.com/facebook/jest/pull/14036))
1519
- `[@jest/transform]` Do not instrument `.json` modules ([#14048](https://github.com/facebook/jest/pull/14048))
1620

1721
### Chore & Maintenance
1822

1923
- `[docs]` Updated documentation for the `--runTestsByPath` CLI command ([#14004](https://github.com/facebook/jest/pull/14004))
2024
- `[docs]` Updated documentation regarding the synchronous fallback when asynchronous code transforms are unavailable ([#14056](https://github.com/facebook/jest/pull/14056))
25+
- `[docs]` Update jest statistics of use and downloads in website Index.
2126

2227
### Performance
2328

docs/JestObjectAPI.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -1039,30 +1039,42 @@ Use the [`--showSeed`](CLI.md#--showseed) flag to print the seed in the test rep
10391039

10401040
Returns `true` if test environment has been torn down.
10411041

1042-
### `jest.retryTimes(numRetries, options)`
1042+
### `jest.retryTimes(numRetries, options?)`
10431043

1044-
Runs failed tests n-times until they pass or until the max number of retries is exhausted. `options` are optional. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! This must live at the top-level of a test file or in a describe block. Retries _will not_ work if `jest.retryTimes()` is called in a `beforeEach` or a `test` block.
1045-
1046-
Example in a test:
1044+
Runs failed tests n-times until they pass or until the max number of retries is exhausted.
10471045

10481046
```js
10491047
jest.retryTimes(3);
1048+
10501049
test('will fail', () => {
10511050
expect(true).toBe(false);
10521051
});
10531052
```
10541053

1055-
If `logErrorsBeforeRetry` is enabled, Jest will log the error(s) that caused the test to fail to the console, providing visibility on why a retry occurred.
1054+
If `logErrorsBeforeRetry` option is enabled, error(s) that caused the test to fail will be logged to the console.
10561055

10571056
```js
10581057
jest.retryTimes(3, {logErrorsBeforeRetry: true});
1058+
10591059
test('will fail', () => {
10601060
expect(true).toBe(false);
10611061
});
10621062
```
10631063

10641064
Returns the `jest` object for chaining.
10651065

1066+
:::caution
1067+
1068+
`jest.retryTimes()` must be declared at the top level of a test file or in a `describe` block.
1069+
1070+
:::
1071+
1072+
:::info
1073+
1074+
This function is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner.
1075+
1076+
:::
1077+
10661078
### `jest.setTimeout(timeout)`
10671079

10681080
Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called.

docs/SnapshotTesting.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Once you're finished, Jest will give you a summary before returning back to watc
106106

107107
Inline snapshots behave identically to external snapshots (`.snap` files), except the snapshot values are written automatically back into the source code. This means you can get the benefits of automatically generated snapshots without having to switch to an external file to make sure the correct value was written.
108108

109-
**Example:**
109+
Example:
110110

111111
First, you write a test, calling `.toMatchInlineSnapshot()` with no arguments:
112112

docs/TutorialReact.md

+2-33
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ React 16 triggers these warnings due to how it checks element types, and the moc
209209
210210
### DOM Testing
211211
212-
If you'd like to assert, and manipulate your rendered components you can use [react-testing-library](https://github.com/kentcdodds/react-testing-library), [Enzyme](https://enzymejs.github.io/enzyme/), or React's [TestUtils](https://reactjs.org/docs/test-utils.html). The following two examples use react-testing-library and Enzyme.
212+
If you'd like to assert, and manipulate your rendered components you can use [@testing-library/react](https://github.com/testing-library/react-testing-library), [Enzyme](https://enzymejs.github.io/enzyme/), or React's [TestUtils](https://reactjs.org/docs/test-utils.html). The following example use `@testing-library/react`.
213213

214-
#### react-testing-library
214+
#### @testing-library/react
215215

216216
```bash npm2yarn
217217
npm install --save-dev @testing-library/react
@@ -261,37 +261,6 @@ it('CheckboxWithLabel changes the text after click', () => {
261261
262262
The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/main/examples/react-testing-library).
263263
264-
#### Enzyme
265-
266-
```bash npm2yarn
267-
npm install --save-dev enzyme
268-
```
269-
270-
If you are using a React version below 15.5.0, you will also need to install `react-addons-test-utils`.
271-
272-
Let's rewrite the test from above using Enzyme instead of react-testing-library. We use Enzyme's [shallow renderer](https://enzymejs.github.io/enzyme/docs/api/shallow.html) in this example.
273-
274-
```tsx title="__tests__/CheckboxWithLabel-test.js"
275-
import Enzyme, {shallow} from 'enzyme';
276-
import Adapter from 'enzyme-adapter-react-16';
277-
import CheckboxWithLabel from '../CheckboxWithLabel';
278-
279-
Enzyme.configure({adapter: new Adapter()});
280-
281-
it('CheckboxWithLabel changes the text after click', () => {
282-
// Render a checkbox with label in the document
283-
const checkbox = shallow(<CheckboxWithLabel labelOn="On" labelOff="Off" />);
284-
285-
expect(checkbox.text()).toBe('Off');
286-
287-
checkbox.find('input').simulate('change');
288-
289-
expect(checkbox.text()).toBe('On');
290-
});
291-
```
292-
293-
The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/main/examples/enzyme).
294-
295264
### Custom transformers
296265
297266
If you need more advanced functionality, you can also build your own transformer. Instead of using `babel-jest`, here is an example of using `@babel/core`:

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
1616
14 | });
1717
15 | });
1818
19-
at eventHandler (../../packages/jest-circus/build/eventHandler.js:134:11)
19+
at eventHandler (../../packages/jest-circus/build/eventHandler.js:140:11)
2020
at test (__tests__/asyncDefinition.test.js:12:5)
2121
2222
● Test suite failed to run
@@ -31,7 +31,7 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
3131
15 | });
3232
16 |
3333
34-
at eventHandler (../../packages/jest-circus/build/eventHandler.js:97:11)
34+
at eventHandler (../../packages/jest-circus/build/eventHandler.js:103:11)
3535
at afterAll (__tests__/asyncDefinition.test.js:13:5)
3636
3737
● Test suite failed to run
@@ -46,7 +46,7 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
4646
20 | });
4747
21 |
4848
49-
at eventHandler (../../packages/jest-circus/build/eventHandler.js:134:11)
49+
at eventHandler (../../packages/jest-circus/build/eventHandler.js:140:11)
5050
at test (__tests__/asyncDefinition.test.js:18:3)
5151
5252
● Test suite failed to run
@@ -60,6 +60,6 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
6060
20 | });
6161
21 |
6262
63-
at eventHandler (../../packages/jest-circus/build/eventHandler.js:97:11)
63+
at eventHandler (../../packages/jest-circus/build/eventHandler.js:103:11)
6464
at afterAll (__tests__/asyncDefinition.test.js:19:3)"
6565
`;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ FAIL __tests__/worksWithConcurrentMode.test.js
4646
15 | });
4747
16 |
4848
49-
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:166:11)
49+
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:176:11)
5050
at Suite.failing (__tests__/worksWithConcurrentMode.test.js:13:17)
5151
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)
5252
@@ -80,7 +80,7 @@ FAIL __tests__/worksWithConcurrentOnlyMode.test.js
8080
15 | });
8181
16 |
8282
83-
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:166:11)
83+
at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:176:11)
8484
at Suite.failing (__tests__/worksWithConcurrentOnlyMode.test.js:13:22)
8585
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)
8686
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`all 3 test files should complete 1`] = `
4+
"Test Suites: 1 failed, 2 passed, 3 total
5+
Tests: 2 passed, 2 total
6+
Snapshots: 0 total
7+
Time: <<REPLACED>>
8+
Ran all test suites."
9+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
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+
import {extractSummary} from '../Utils';
9+
import runJest from '../runJest';
10+
11+
it('all 3 test files should complete', () => {
12+
const result = runJest('worker-restart-before-send');
13+
const {summary} = extractSummary(result.stderr);
14+
expect(summary).toMatchSnapshot();
15+
});

0 commit comments

Comments
 (0)