Skip to content

Commit d6b7af0

Browse files
authored
Merge branch 'main' into feat/additional-perf-stats
2 parents 0291093 + 544a4b8 commit d6b7af0

File tree

208 files changed

+4828
-5754
lines changed

Some content is hidden

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

208 files changed

+4828
-5754
lines changed

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ workflows:
5858
name: test-node-partial-<< matrix.node-version >>
5959
matrix:
6060
parameters:
61-
# For some reason, v20 fails to run yarn install…
62-
node-version: ['16', '18']
61+
node-version: ['16', '18', '20', '21']
6362
- test-jest-jasmine

.eslintrc.cjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ module.exports = {
4646
rules: {
4747
'@typescript-eslint/array-type': ['error', {default: 'generic'}],
4848
'@typescript-eslint/ban-types': 'error',
49+
'@typescript-eslint/consistent-type-imports': [
50+
'error',
51+
{fixStyle: 'inline-type-imports', disallowTypeAnnotations: false},
52+
],
53+
'@typescript-eslint/no-import-type-side-effects': 'error',
4954
'@typescript-eslint/no-inferrable-types': 'error',
5055
'@typescript-eslint/no-unused-vars': [
5156
'error',
@@ -278,6 +283,16 @@ module.exports = {
278283
'no-restricted-imports': 'off',
279284
},
280285
},
286+
{
287+
files: ['examples/angular/**/*'],
288+
rules: {
289+
// Angular DI for some reason doesn't work with type imports
290+
'@typescript-eslint/consistent-type-imports': [
291+
'error',
292+
{prefer: 'no-type-imports', disallowTypeAnnotations: false},
293+
],
294+
},
295+
},
281296
{
282297
files: 'packages/**/*.ts',
283298
rules: {
@@ -416,6 +431,7 @@ module.exports = {
416431
'handle-callback-err': 'off',
417432
'id-length': 'off',
418433
'id-match': 'off',
434+
'import/no-duplicates': 'error',
419435
'import/no-extraneous-dependencies': [
420436
'error',
421437
{

.github/workflows/nodejs.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- uses: actions/checkout@v4
3838
with:
3939
persist-credentials: false
40-
- uses: actions/setup-node@v3
40+
- uses: actions/setup-node@v4
4141
with:
4242
node-version: lts/*
4343
cache: yarn
@@ -63,7 +63,7 @@ jobs:
6363
- uses: actions/checkout@v4
6464
with:
6565
persist-credentials: false
66-
- uses: actions/setup-node@v3
66+
- uses: actions/setup-node@v4
6767
with:
6868
node-version: lts/*
6969
cache: yarn
@@ -85,7 +85,7 @@ jobs:
8585
- uses: actions/checkout@v4
8686
with:
8787
persist-credentials: false
88-
- uses: actions/setup-node@v3
88+
- uses: actions/setup-node@v4
8989
with:
9090
node-version: lts/*
9191
cache: yarn
@@ -112,7 +112,7 @@ jobs:
112112
- uses: actions/checkout@v4
113113
with:
114114
persist-credentials: false
115-
- uses: actions/setup-node@v3
115+
- uses: actions/setup-node@v4
116116
with:
117117
node-version: lts/*
118118
cache: yarn
@@ -165,7 +165,7 @@ jobs:
165165
with:
166166
persist-credentials: false
167167
- name: Use Node.js LTS
168-
uses: actions/setup-node@v3
168+
uses: actions/setup-node@v4
169169
with:
170170
node-version: lts/*
171171
cache: yarn
@@ -190,7 +190,7 @@ jobs:
190190
with:
191191
persist-credentials: false
192192
- name: Use Node.js LTS
193-
uses: actions/setup-node@v3
193+
uses: actions/setup-node@v4
194194
with:
195195
node-version: lts/*
196196
cache: yarn

.github/workflows/prepare-cache.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
persist-credentials: false
1919

20-
- uses: actions/setup-node@v3
20+
- uses: actions/setup-node@v4
2121
with:
2222
node-version: lts/*
2323
cache: yarn

.github/workflows/test-nightly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
persist-credentials: false
2323
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v3
24+
uses: actions/setup-node@v4
2525
with:
2626
node-version: 21-nightly
2727
cache: yarn
@@ -48,7 +48,7 @@ jobs:
4848
with:
4949
persist-credentials: false
5050
- name: Use Node.js LTS
51-
uses: actions/setup-node@v3
51+
uses: actions/setup-node@v4
5252
with:
5353
node-version: 21-nightly
5454
cache: yarn

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
node-version: [16.x, 18.x, 20.x]
18+
node-version: [16.x, 18.x, 20.x, 21.x]
1919
name: Node v${{ matrix.node-version }}
2020
runs-on: ${{ inputs.os }}
2121

@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
persist-credentials: false
2626
- name: Use Node.js ${{ matrix.node-version }}
27-
uses: actions/setup-node@v3
27+
uses: actions/setup-node@v4
2828
with:
2929
node-version: ${{ matrix.node-version }}
3030
cache: yarn
@@ -47,7 +47,7 @@ jobs:
4747
with:
4848
persist-credentials: false
4949
- name: Use Node.js LTS
50-
uses: actions/setup-node@v3
50+
uses: actions/setup-node@v4
5151
with:
5252
node-version: lts/*
5353
cache: yarn

CHANGELOG.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- `[jest-circus, jest-expect, jest-snapshot]` Pass `test.failing` tests when containing failing snapshot matchers ([#14313](https://github.com/jestjs/jest/pull/14313))
2626
- `[jest-config]` Make sure to respect `runInBand` option ([#14578](https://github.com/facebook/jest/pull/14578))
2727
- `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408))
28+
- `[@jest/expect-utils]` [**BREAKING**] exclude non-enumerable in object matching ([#14670](https://github.com/jestjs/jest/pull/14670))
2829
- `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526))
2930
- `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589))
3031
- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552))
@@ -36,15 +37,22 @@
3637

3738
### Performance
3839

39-
- `[*]` [**BREAKING**] Bundle all of Jest's modules into `index.js` ([#12348](https://github.com/jestjs/jest/pull/12348) & [#14550](https://github.com/jestjs/jest/pull/14550))
40+
- `[*]` [**BREAKING**] Bundle all of Jest's modules into `index.js` ([#12348](https://github.com/jestjs/jest/pull/12348), [#14550](https://github.com/jestjs/jest/pull/14550) & [#14661](https://github.com/jestjs/jest/pull/14661))
4041

4142
### Chore & Maintenance
4243

4344
- `[*]` [**BREAKING**] Drop support for Node.js versions 14 and 19 ([#14460](https://github.com/jestjs/jest/pull/14460))
4445
- `[*]` [**BREAKING**] Drop support for `[email protected]`, minimum version is now `5.0` ([#14542](https://github.com/facebook/jest/pull/14542))
4546
- `[*]` Depend on exact versions of monorepo dependencies instead of `^` range ([#14553](https://github.com/facebook/jest/pull/14553))
47+
- `[*]` [**BREAKING**] Add ESM wrapper for all of Jest's modules ([#14661](https://github.com/jestjs/jest/pull/14661))
48+
- `[docs]` Fix typos in `CHANGELOG.md` and `packages/jest-validate/README.md` ([#14640](https://github.com/jestjs/jest/pull/14640))
49+
- `[docs]` Don't use alias matchers in docs ([#14631](https://github.com/facebook/jest/pull/14631))
4650
- `[babel-jest, babel-preset-jest]` [**BREAKING**] Increase peer dependency of `@babel/core` to `^7.11` ([#14109](https://github.com/jestjs/jest/pull/14109))
51+
- `[expect]` [**BREAKING**] Remove `.toBeCalled()`, `.toBeCalledTimes()`, `.toBeCalledWith()`, `.lastCalledWith()`, `.nthCalledWith()`, `.toReturn()`, `.toReturnTimes()`, `.toReturnWith()`, `.lastReturnedWith()`, `.nthReturnedWith()` and `.toThrowError()` matcher aliases ([#14632](https://github.com/facebook/jest/pull/14632))
4752
- `[jest-cli, jest-config, @jest/types]` [**BREAKING**] Remove deprecated `--init` argument ([#14490](https://github.com/jestjs/jest/pull/14490))
53+
- `[jest-config, @jest/core, jest-util]` Upgrade `ci-info` ([#14655](https://github.com/jestjs/jest/pull/14655))
54+
- `[jest-mock]` [**BREAKING**] Remove `MockFunctionMetadataType`, `MockFunctionMetadata` and `SpyInstance` types ([#14621](https://github.com/jestjs/jest/pull/14621))
55+
- `[jest-transform]` Upgrade `write-file-atomic` ([#14274](https://github.com/jestjs/jest/pull/14274))
4856

4957
## 29.7.0
5058

@@ -634,7 +642,7 @@
634642

635643
### Fixes
636644

637-
- `[*]` Use `sha256` instead of `md5` as hashing algortihm for compatibility with FIPS systems ([#12722](https://github.com/facebook/jest/pull/12722))
645+
- `[*]` Use `sha256` instead of `md5` as hashing algorithm for compatibility with FIPS systems ([#12722](https://github.com/facebook/jest/pull/12722))
638646
- `[babel-jest]` [**BREAKING**] Pass `rootDir` as `root` in Babel's options ([#12689](https://github.com/facebook/jest/pull/12689))
639647
- `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346))
640648
- `[expect]` Throw useful error if `expect.extend` is called with invalid matchers ([#12488](https://github.com/facebook/jest/pull/12488))
@@ -1441,7 +1449,7 @@
14411449
- `[*]` Upgrade to chalk@4 ([#9752](https://github.com/facebook/jest/pull/9752))
14421450
- `[*]` Remove usage of `realpath-native` ([#9952](https://github.com/facebook/jest/pull/9952))
14431451
- `[docs]` Fix example reference implementation to use Jest with Phabricator ([#8662](https://github.com/facebook/jest/pull/8662))
1444-
- `[docs]` Added default compiler to tranform ([#8583](https://github.com/facebook/jest/pull/8583))
1452+
- `[docs]` Added default compiler to transform ([#8583](https://github.com/facebook/jest/pull/8583))
14451453
- `[docs]` Updated Testing Frameworks guide with React; make it generic ([#9106](https://github.com/facebook/jest/pull/9106))
14461454
- `[expect, jest-mock, pretty-format]` [**BREAKING**] Remove `build-es5` from package ([#9945](https://github.com/facebook/jest/pull/9945))
14471455
- `[@jest/fake-timers, @jest/environment]` [**BREAKING**] Rename `LolexFakeTimers` to `ModernFakeTimers` ([#9960](https://github.com/facebook/jest/pull/9960))
@@ -3481,7 +3489,7 @@ See <https://jestjs.io/blog/2016/12/15/2016-in-jest>
34813489
- Added `--watchAll`, made `--watch` interactive and added the ability to update snapshots and select test patterns in watch mode.
34823490
- Jest uses verbose mode when running a single test file.
34833491
- Console messages are now buffered and printed along with the test results.
3484-
- Fix `testEnvironment` resolution to prefer `jest-environment-{name}` instead of `{name}` only. This prevents a module colision when using `jsdom` as test environment.
3492+
- Fix `testEnvironment` resolution to prefer `jest-environment-{name}` instead of `{name}` only. This prevents a module collision when using `jsdom` as test environment.
34853493
- `moduleNameMapper` now uses a resolution algorithm.
34863494
- Improved performance for small test runs.
34873495
- Improved API documentation.
@@ -3620,7 +3628,7 @@ See <https://jestjs.io/blog/2016/12/15/2016-in-jest>
36203628
- Clear the terminal window when using `--watch`.
36213629
- By default, `--watch` will now only runs tests related to changed files. `--watch=all` can be used to run all tests on file system changes.
36223630
- Debounce `--watch` re-runs to not trigger test runs during a branch switch in version control.
3623-
- Added `jest.fn()` and `jest.fn(implementation)` as convenient shorcuts for `jest.genMockFunction()` and `jest.genMockFunction().mockImplementation()`.
3631+
- Added `jest.fn()` and `jest.fn(implementation)` as convenient shortcuts for `jest.genMockFunction()` and `jest.genMockFunction().mockImplementation()`.
36243632
- Added an `automock` option to turn off automocking globally.
36253633
- Added a "no tests found" message if no tests can be found.
36263634
- Jest sets `process.NODE_ENV` to `test` unless otherwise specified.

docs/ExpectAPI.md

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ Although the `.toBe` matcher **checks** referential identity, it **reports** a d
144144

145145
### `.toHaveBeenCalled()`
146146

147-
Also under the alias: `.toBeCalled()`
148-
149147
Use `.toHaveBeenCalledWith` to ensure that a mock function was called with specific arguments. The arguments are checked with the same algorithm that `.toEqual` uses.
150148

151149
For example, let's say you have a `drinkAll(drink, flavour)` function that takes a `drink` function and applies it to all available beverages. You might want to check that `drink` gets called for `'lemon'`, but not for `'octopus'`, because `'octopus'` flavour is really weird and why would anything be octopus-flavoured? You can do that with this test suite:
@@ -174,8 +172,6 @@ describe('drinkAll', () => {
174172

175173
### `.toHaveBeenCalledTimes(number)`
176174

177-
Also under the alias: `.toBeCalledTimes(number)`
178-
179175
Use `.toHaveBeenCalledTimes` to ensure that a mock function got called exact number of times.
180176

181177
For example, let's say you have a `drinkEach(drink, Array<flavor>)` function that takes a `drink` function and applies it to array of passed beverages. You might want to check that drink function was called exact number of times. You can do that with this test suite:
@@ -190,8 +186,6 @@ test('drinkEach drinks each drink', () => {
190186

191187
### `.toHaveBeenCalledWith(arg1, arg2, ...)`
192188

193-
Also under the alias: `.toBeCalledWith()`
194-
195189
Use `.toHaveBeenCalledWith` to ensure that a mock function was called with specific arguments. The arguments are checked with the same algorithm that `.toEqual` uses.
196190

197191
For example, let's say that you can register a beverage with a `register` function, and `applyToAll(f)` should apply the function `f` to all registered beverages. To make sure this works, you could write:
@@ -208,8 +202,6 @@ test('registration applies correctly to orange La Croix', () => {
208202

209203
### `.toHaveBeenLastCalledWith(arg1, arg2, ...)`
210204

211-
Also under the alias: `.lastCalledWith(arg1, arg2, ...)`
212-
213205
If you have a mock function, you can use `.toHaveBeenLastCalledWith` to test what arguments it was last called with. For example, let's say you have a `applyToAllFlavors(f)` function that applies `f` to a bunch of flavors, and you want to ensure that when you call it, the last flavor it operates on is `'mango'`. You can write:
214206

215207
```js
@@ -222,8 +214,6 @@ test('applying to all flavors does mango last', () => {
222214

223215
### `.toHaveBeenNthCalledWith(nthCall, arg1, arg2, ....)`
224216

225-
Also under the alias: `.nthCalledWith(nthCall, arg1, arg2, ...)`
226-
227217
If you have a mock function, you can use `.toHaveBeenNthCalledWith` to test what arguments it was nth called with. For example, let's say you have a `drinkEach(drink, Array<flavor>)` function that applies `f` to a bunch of flavors, and you want to ensure that when you call it, the first flavor it operates on is `'lemon'` and the second one is `'octopus'`. You can write:
228218

229219
```js
@@ -243,8 +233,6 @@ The nth argument must be positive integer starting from 1.
243233

244234
### `.toHaveReturned()`
245235

246-
Also under the alias: `.toReturn()`
247-
248236
If you have a mock function, you can use `.toHaveReturned` to test that the mock function successfully returned (i.e., did not throw an error) at least one time. For example, let's say you have a mock `drink` that returns `true`. You can write:
249237

250238
```js
@@ -259,8 +247,6 @@ test('drinks returns', () => {
259247

260248
### `.toHaveReturnedTimes(number)`
261249

262-
Also under the alias: `.toReturnTimes(number)`
263-
264250
Use `.toHaveReturnedTimes` to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times. Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
265251

266252
For example, let's say you have a mock `drink` that returns `true`. You can write:
@@ -278,8 +264,6 @@ test('drink returns twice', () => {
278264

279265
### `.toHaveReturnedWith(value)`
280266

281-
Also under the alias: `.toReturnWith(value)`
282-
283267
Use `.toHaveReturnedWith` to ensure that a mock function returned a specific value.
284268

285269
For example, let's say you have a mock `drink` that returns the name of the beverage that was consumed. You can write:
@@ -297,8 +281,6 @@ test('drink returns La Croix', () => {
297281

298282
### `.toHaveLastReturnedWith(value)`
299283

300-
Also under the alias: `.lastReturnedWith(value)`
301-
302284
Use `.toHaveLastReturnedWith` to test the specific value that a mock function last returned. If the last call to the mock function threw an error, then this matcher will fail no matter what value you provided as the expected return value.
303285

304286
For example, let's say you have a mock `drink` that returns the name of the beverage that was consumed. You can write:
@@ -318,8 +300,6 @@ test('drink returns La Croix (Orange) last', () => {
318300

319301
### `.toHaveNthReturnedWith(nthCall, value)`
320302

321-
Also under the alias: `.nthReturnedWith(nthCall, value)`
322-
323303
Use `.toHaveNthReturnedWith` to test the specific value that a mock function returned for the nth call. If the nth call to the mock function threw an error, then this matcher will fail no matter what value you provided as the expected return value.
324304

325305
For example, let's say you have a mock `drink` that returns the name of the beverage that was consumed. You can write:
@@ -782,8 +762,6 @@ describe('the La Croix cans on my desk', () => {
782762

783763
### `.toThrow(error?)`
784764

785-
Also under the alias: `.toThrowError(error?)`
786-
787765
Use `.toThrow` to test that a function throws when it is called. For example, if we want to test that `drinkFlavor('octopus')` throws, because octopus flavor is too disgusting to drink, we could write:
788766

789767
```js
@@ -888,7 +866,7 @@ Check out the section on [Inline Snapshots](SnapshotTesting.md#inline-snapshots)
888866

889867
### `expect.anything()`
890868

891-
`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument:
869+
`expect.anything()` matches anything but `null` or `undefined`. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument:
892870

893871
```js
894872
test('map calls its argument with a non-null argument', () => {
@@ -900,7 +878,7 @@ test('map calls its argument with a non-null argument', () => {
900878

901879
### `expect.any(constructor)`
902880

903-
`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number:
881+
`expect.any(constructor)` matches anything that was created with the given constructor or if it's a primitive that is of the passed type. You can use it inside `toEqual` or `toHaveBeenCalledWith` instead of a literal value. For example, if you want to check that a mock function is called with a number:
904882

905883
```js
906884
class Cat {}
@@ -931,7 +909,7 @@ test('randocall calls its callback with a number', () => {
931909

932910
You can use it instead of a literal value:
933911

934-
- in `toEqual` or `toBeCalledWith`
912+
- in `toEqual` or `toHaveBeenCalledWith`
935913
- to match a property in `objectContaining` or `toMatchObject`
936914

937915
```js
@@ -1063,7 +1041,7 @@ describe('not.stringContaining', () => {
10631041

10641042
You can use it instead of a literal value:
10651043

1066-
- in `toEqual` or `toBeCalledWith`
1044+
- in `toEqual` or `toHaveBeenCalledWith`
10671045
- to match an element in `arrayContaining`
10681046
- to match a property in `objectContaining` or `toMatchObject`
10691047

docs/MockFunctionAPI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ export function setDateNow(now: number): jest.Spied<typeof Date.now> {
736736
```
737737

738738
```ts
739-
import {afterEach, expect, jest, test} from '@jest/globals';
739+
import {afterEach, expect, type jest, test} from '@jest/globals';
740740
import {setDateNow} from './__utils__/setDateNow';
741741

742742
let spiedDateNow: jest.Spied<typeof Date.now> | undefined = undefined;

0 commit comments

Comments
 (0)