Skip to content

Commit 75c4de6

Browse files
committed
Merge branch 'main' into 12456
2 parents f1a17c6 + fc5a39b commit 75c4de6

File tree

62 files changed

+1368
-1374
lines changed

Some content is hidden

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

62 files changed

+1368
-1374
lines changed

.eslintrc.cjs

+9-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
'eslint:recommended',
3333
'plugin:markdown/recommended',
3434
'plugin:import/errors',
35-
'plugin:eslint-comments/recommended',
35+
'plugin:@eslint-community/eslint-comments/recommended',
3636
'plugin:unicorn/recommended',
3737
'plugin:promise/recommended',
3838
'plugin:prettier/recommended',
@@ -226,6 +226,7 @@ module.exports = {
226226
'unicorn/no-static-only-class': 'off',
227227
'unicorn/prefer-number-properties': 'off',
228228
'unicorn/prefer-string-raw': 'off',
229+
'unicorn/prefer-global-this': 'off',
229230
},
230231
},
231232
// demonstration of matchers usage
@@ -347,8 +348,8 @@ module.exports = {
347348
],
348349
rules: {
349350
'@typescript-eslint/ban-types': 'off',
350-
'eslint-comments/disable-enable-pair': 'off',
351-
'eslint-comments/no-unlimited-disable': 'off',
351+
'@eslint-community/eslint-comments/disable-enable-pair': 'off',
352+
'@eslint-community/eslint-comments/no-unlimited-disable': 'off',
352353
'prefer-rest-params': 'off',
353354
'prefer-spread': 'off',
354355
'sort-keys ': 'off',
@@ -477,8 +478,11 @@ module.exports = {
477478
'default-case': 'off',
478479
'dot-notation': 'off',
479480
eqeqeq: ['error', 'smart'],
480-
'eslint-comments/disable-enable-pair': ['error', {allowWholeFile: true}],
481-
'eslint-comments/no-unused-disable': 'error',
481+
'@eslint-community/eslint-comments/disable-enable-pair': [
482+
'error',
483+
{allowWholeFile: true},
484+
],
485+
'@eslint-community/eslint-comments/no-unused-disable': 'error',
482486
'func-names': 'off',
483487
'func-style': ['off', 'declaration'],
484488
'global-require': 'off',

.github/workflows/test.yml

+1-1
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, 22.x]
18+
node-version: [16.x, 18.x, 20.x, 22.x, 23.x]
1919
name: Node v${{ matrix.node-version }}
2020
runs-on: ${{ inputs.os }}
2121

.yarn/releases/yarn-3.8.4.cjs renamed to .yarn/releases/yarn-3.8.7.cjs

+156-156
Large diffs are not rendered by default.

.yarnrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ plugins:
3333
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
3434
spec: "@yarnpkg/plugin-workspace-tools"
3535

36-
yarnPath: .yarn/releases/yarn-3.8.4.cjs
36+
yarnPath: .yarn/releases/yarn-3.8.7.cjs

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
### Fixes
5151

5252
- `[babel-plugin-jest-hoist]` Use `denylist` instead of the deprecated `blacklist` for Babel 8 support ([#14109](https://github.com/jestjs/jest/pull/14109))
53+
- `[babel-plugin-jest-hoist]` Do not rely on buggy Babel behaviour ([#15415](https://github.com/jestjs/jest/pull/15415))
5354
- `[expect]` Check error instance type for `toThrow/toThrowError` ([#14576](https://github.com/jestjs/jest/pull/14576))
5455
- `[expect]` Improve diff for failing `expect.objectContaining` ([#15038](https://github.com/jestjs/jest/pull/15038))
5556
- `[expect]` Use `Array.isArray` to check if an array is an `Array` ([#15101](https://github.com/jestjs/jest/pull/15101))
@@ -84,6 +85,7 @@
8485
- [**BREAKING**] `--testPathPattern` is now `--testPathPatterns`
8586
- [**BREAKING**] Specifying `testPathPatterns` when programmatically calling `watch` must be specified as `new TestPathPatterns(patterns)`, where `TestPathPatterns` can be imported from `@jest/pattern`
8687
- `[jest-reporters, jest-runner]` Unhandled errors without stack get correctly logged to console ([#14619](https://github.com/jestjs/jest/pull/14619))
88+
- `[jest-util]` Always load `mjs` files with `import` ([#15447](https://github.com/jestjs/jest/pull/15447))
8789
- `[jest-worker]` Properly handle a circular reference error when worker tries to send an assertion fails where either the expected or actual value is circular ([#15191](https://github.com/jestjs/jest/pull/15191))
8890
- `[jest-worker]` Properly handle a BigInt when worker tries to send an assertion fails where either the expected or actual value is BigInt ([#15191](https://github.com/jestjs/jest/pull/15191))
8991

@@ -120,6 +122,7 @@
120122
- `[docs]` Link NestJS documentation on testing with Jest ([#14940](https://github.com/jestjs/jest/pull/14940))
121123
- `[docs]` `Revised documentation for .toHaveBeenCalled()` to accurately depict its functionality. ([#14853](https://github.com/jestjs/jest/pull/14853))
122124
- `[docs]` Removed ExpressJS reference link from documentation due to dead link ([#15270](https://github.com/jestjs/jest/pull/15270))
125+
- `[docs]` Removed `Running AngularJS Tests with Jest reference` link from documentation due to dead link ([#15270](https://github.com/jestjs/jest/pull/15311))
123126

124127
## 29.7.0
125128

docs/CLI.md

+2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ jest --seed=1324
407407

408408
If this option is not specified Jest will randomly generate the value. You can use the [`--showSeed`](#--showseed) flag to print the seed in the test report summary.
409409

410+
Jest uses the seed internally for shuffling the order in which test suites are run. If the [`--randomize`](#--randomize) option is used, the seed is also used for shuffling the order of tests within each `describe` block. When dealing with flaky tests, rerunning with the same seed might help reproduce the failure.
411+
410412
:::
411413

412414
### `--selectProjects <project1> ... <projectN>`

docs/GlobalAPI.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Use `describe.each` if you keep duplicating the same test suites with different
251251
- `%$` - Number of the test case.
252252
- `%%` - single percent sign ('%'). This does not consume an argument.
253253
- Or generate unique test titles by injecting properties of test case object with `$variable`
254-
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
254+
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value` (only works for ["own" properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty), e.g. `$variable.constructor.name` wouldn't work)
255255
- You can use `$#` to inject the index of the test case
256256
- You cannot use `$variable` with the `printf` formatting except for `%%`
257257
- `fn`: `Function` the suite of tests to be run, this is the function that will receive the parameters in each row as function arguments.
@@ -305,7 +305,7 @@ describe.each([
305305
- First row of variable name column headings separated with `|`
306306
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
307307
- `name`: `String` the title of the test suite, use `$variable` to inject test data into the suite title from the tagged template expressions, and `$#` for the index of the row.
308-
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
308+
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value` (only works for ["own" properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty), e.g. `$variable.constructor.name` wouldn't work)
309309
- `fn`: `Function` the suite of tests to be run, this is the function that will receive the test data object.
310310
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
311311

@@ -574,7 +574,7 @@ test.concurrent.each([
574574
- First row of variable name column headings separated with `|`
575575
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
576576
- `name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
577-
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
577+
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value` (only works for ["own" properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty), e.g. `$variable.constructor.name` wouldn't work)
578578
- `fn`: `Function` the test to be run, this is the function that will receive the test data object, **this will have to be an asynchronous function**.
579579
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
580580

@@ -697,7 +697,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test
697697
- `%$` - Number of the test case.
698698
- `%%` - single percent sign ('%'). This does not consume an argument.
699699
- Or generate unique test titles by injecting properties of test case object with `$variable`
700-
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
700+
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value` (only works for ["own" properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty), e.g. `$variable.constructor.name` wouldn't work)
701701
- You can use `$#` to inject the index of the test case
702702
- You cannot use `$variable` with the `printf` formatting except for `%%`
703703
- `fn`: `Function` the test to be run, this is the function that will receive the parameters in each row as function arguments.
@@ -731,7 +731,7 @@ test.each([
731731
- First row of variable name column headings separated with `|`
732732
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
733733
- `name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
734-
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
734+
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value` (only works for ["own" properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty), e.g. `$variable.constructor.name` wouldn't work)
735735
- `fn`: `Function` the test to be run, this is the function that will receive the test data object.
736736
- Optionally, you can provide a `timeout` (in milliseconds) for specifying how long to wait for each row before aborting. The default timeout is 5 seconds.
737737

docs/TestingFrameworks.md

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Jest is a universal testing platform, with the ability to adapt to any JavaScrip
1717
## AngularJS
1818

1919
- [Testing an AngularJS app with Jest](https://medium.com/aya-experience/testing-an-angularjs-app-with-jest-3029a613251) by Matthieu Lux ([@Swiip](https://twitter.com/Swiip))
20-
- [Running AngularJS Tests with Jest](https://engineering.talentpair.com/running-angularjs-tests-with-jest-49d0cc9c6d26) by Ben Brandt ([@benjaminbrandt](https://twitter.com/benjaminbrandt))
2120
- [AngularJS Unit Tests with Jest Actions (Traditional Chinese)](https://dwatow.github.io/2019/08-14-angularjs/angular-jest/?fbclid=IwAR2SrqYg_o6uvCQ79FdNPeOxs86dUqB6pPKgd9BgnHt1kuIDRyRM-ch11xg) by Chris Wang ([@dwatow](https://github.com/dwatow))
2221

2322
## Angular

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ exports[`Wrong globals for environment on node <=18 print useful error for navig
1313
1414
ReferenceError: navigator is not defined
1515
16-
30 |
17-
31 | test('use navigator', () => {
18-
> 32 | const userAgent = navigator.userAgent;
16+
31 |
17+
32 | test('use navigator', () => {
18+
> 33 | const userAgent = navigator.userAgent;
1919
| ^
20-
33 |
21-
34 | console.log(userAgent);
22-
35 |
20+
34 |
21+
35 | console.log(userAgent);
22+
36 |
2323
24-
at Object.navigator (__tests__/node.js:32:21)"
24+
at Object.navigator (__tests__/node.js:33:21)"
2525
`;
2626
2727
exports[`Wrong globals for environment print useful error for document 1`] = `
@@ -83,15 +83,15 @@ exports[`Wrong globals for environment print useful error for window 1`] = `
8383
8484
ReferenceError: window is not defined
8585
86-
22 |
8786
23 | test('use window', () => {
88-
> 24 | const location = window.location;
87+
24 | // eslint-disable-next-line unicorn/prefer-global-this
88+
> 25 | const location = window.location;
8989
| ^
90-
25 |
91-
26 | console.log(location);
92-
27 |
90+
26 |
91+
27 | console.log(location);
92+
28 |
9393
94-
at Object.window (__tests__/node.js:24:20)"
94+
at Object.window (__tests__/node.js:25:20)"
9595
`;
9696
9797
exports[`Wrong globals for environment print useful error when it explodes during evaluation 1`] = `

e2e/console-jsdom/__tests__/console.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ test('can mock console.error calls from jsdom', () => {
3030

3131
function onError(event) {}
3232

33-
window.addEventListener('error', onError);
33+
globalThis.addEventListener('error', onError);
3434
fakeNode.addEventListener(evtType, callCallback, false);
3535
evt.initEvent(evtType, false, false);
3636
fakeNode.dispatchEvent(evt);
37-
window.removeEventListener('error', onError);
37+
globalThis.removeEventListener('error', onError);
3838

3939
expect(console.error).toHaveBeenCalledTimes(1);
4040
expect(console.error).toHaveBeenCalledWith(

e2e/env-test/__tests__/equivalent.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
const {isArrayBuffer} = require('util').types;
1010
const isJSDOM =
11+
// eslint-disable-next-line unicorn/prefer-global-this
1112
typeof window !== 'undefined' && typeof document !== 'undefined';
1213

1314
const skipTestJSDOM = isJSDOM ? test.skip : test;

e2e/environmentOptions/__tests__/environmentOptions.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
/*eslint-env browser */
99

1010
test('found url jestjs.io', () => {
11-
expect(window.location.href).toBe('https://jestjs.io/');
11+
expect(globalThis.location.href).toBe('https://jestjs.io/');
1212
});

e2e/esm-config/js/jest.config.js

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

8+
const displayName = await Promise.resolve('Config from js file');
9+
810
export default {
9-
displayName: 'Config from js file',
11+
displayName,
1012
testEnvironment: 'node',
1113
};

e2e/esm-config/mjs/jest.config.mjs

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

8+
const displayName = await Promise.resolve('Config from mjs file');
9+
810
export default {
9-
displayName: 'Config from mjs file',
11+
displayName,
1012
testEnvironment: 'node',
1113
};

e2e/fake-timers/do-not-fake/__tests__/doNotFake.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
'use strict';
1111

1212
const mockPerformanceMark = jest.fn();
13-
window.performance.mark = mockPerformanceMark;
13+
globalThis.performance.mark = mockPerformanceMark;
1414

1515
test('fakes all APIs', () => {
1616
jest.useFakeTimers();
1717

18-
expect(window.performance.mark).toBeUndefined();
18+
expect(globalThis.performance.mark).toBeUndefined();
1919
});
2020

2121
test('does not fake `performance` instance', () => {
2222
jest.useFakeTimers({doNotFake: ['performance']});
2323

24-
expect(window.performance.mark).toBe(mockPerformanceMark);
24+
expect(globalThis.performance.mark).toBe(mockPerformanceMark);
2525
});

e2e/native-esm/yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ __metadata:
341341
linkType: hard
342342

343343
"cross-spawn@npm:^7.0.0":
344-
version: 7.0.3
345-
resolution: "cross-spawn@npm:7.0.3"
344+
version: 7.0.6
345+
resolution: "cross-spawn@npm:7.0.6"
346346
dependencies:
347347
path-key: ^3.1.0
348348
shebang-command: ^2.0.0
349349
which: ^2.0.1
350-
checksum: 671cc7c7288c3a8406f3c69a3ae2fc85555c04169e9d611def9a675635472614f1c0ed0ef80955d5b6d4e724f6ced67f0ad1bb006c2ea643488fcfef994d7f52
350+
checksum: 8d306efacaf6f3f60e0224c287664093fa9185680b2d195852ba9a863f85d02dcc737094c6e512175f8ee0161f9b87c73c6826034c2422e39de7d6569cf4503b
351351
languageName: node
352352
linkType: hard
353353

e2e/nested-event-loop/__tests__/nestedEventLoop.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ it('can assert on errors across nested event loops', () => {
1717
throw new Error('This should be caught.');
1818
});
1919
let caught = null;
20-
window.addEventListener('error', e => {
20+
globalThis.addEventListener('error', e => {
2121
caught = e.error;
2222
});
2323
expect(() => {

e2e/override-globals/__tests__/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ describe('parent', () => {
2929
});
3030

3131
it('can override atob and btoa', () => {
32-
// eslint-disable-next-line no-restricted-globals
33-
global.atob = () => 'hello';
34-
// eslint-disable-next-line no-restricted-globals
35-
global.btoa = () => 'there';
32+
globalThis.atob = () => 'hello';
33+
globalThis.btoa = () => 'there';
3634

3735
expect(`${atob()} ${btoa()}`).toBe('hello there');
3836
});

e2e/test-environment/__tests__/environmentOptionsFromDocblock.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
/*eslint-env browser */
1212

1313
test('use jsdom and set the URL in this test file', () => {
14-
expect(window.location.href).toBe('https://jestjs.io/');
14+
expect(globalThis.location.href).toBe('https://jestjs.io/');
1515
});

e2e/wrong-env/__tests__/node.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ test('use document', () => {
2121
});
2222

2323
test('use window', () => {
24+
// eslint-disable-next-line unicorn/prefer-global-this
2425
const location = window.location;
2526

2627
console.log(location);

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@babel/preset-typescript": "^7.0.0",
1111
"@babel/register": "^7.0.0",
1212
"@crowdin/cli": "^4.0.0",
13+
"@eslint-community/eslint-plugin-eslint-comments": "^4.0.0",
1314
"@jest/globals": "workspace:*",
1415
"@jest/test-utils": "workspace:*",
1516
"@lerna-lite/cli": "^3.0.0",
@@ -33,15 +34,14 @@
3334
"eslint": "^8.8.0",
3435
"eslint-config-prettier": "^9.0.0",
3536
"eslint-import-resolver-typescript": "^3.2.5",
36-
"eslint-plugin-eslint-comments": "^3.1.2",
3737
"eslint-plugin-import": "^2.6.0",
3838
"eslint-plugin-jest": "^28.0.0",
3939
"eslint-plugin-jsdoc": "^50.0.0",
4040
"eslint-plugin-local": "link:./.eslintplugin",
4141
"eslint-plugin-markdown": "^3.0.0",
4242
"eslint-plugin-prettier": "^5.0.0",
4343
"eslint-plugin-promise": "^6.1.1",
44-
"eslint-plugin-unicorn": "^55.0.0",
44+
"eslint-plugin-unicorn": "^56.0.0",
4545
"execa": "^5.0.0",
4646
"find-process": "^1.4.1",
4747
"glob": "^10.3.10",
@@ -61,7 +61,7 @@
6161
"jest-watch-typeahead": "^2.2.0",
6262
"jquery": "^3.2.1",
6363
"js-yaml": "^4.1.0",
64-
"micromatch": "^4.0.7",
64+
"micromatch": "^4.0.8",
6565
"mock-fs": "^5.1.2",
6666
"netlify-plugin-cache": "^1.0.3",
6767
"node-notifier": "^10.0.0",
@@ -78,7 +78,7 @@
7878
"strip-json-comments": "^3.1.1",
7979
"tempy": "^1.0.0",
8080
"ts-node": "^10.5.0",
81-
"tstyche": "^2.0.0",
81+
"tstyche": "^3.0.0",
8282
"typescript": "^5.0.4",
8383
"webpack": "^5.68.0",
8484
"webpack-node-externals": "^3.0.0",
@@ -204,5 +204,5 @@
204204
"psl": "patch:psl@npm:^1.9.0#./.yarn/patches/psl-npm-1.9.0-a546edad1a.patch",
205205
"ts-node@^10.5.0": "patch:ts-node@npm:^10.5.0#./.yarn/patches/ts-node-npm-10.9.1-6c268be7f4.patch"
206206
},
207-
"packageManager": "[email protected].4"
207+
"packageManager": "[email protected].7"
208208
}

0 commit comments

Comments
 (0)