Skip to content

Commit

Permalink
Merge branch 'main' into 12456
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 15, 2025
2 parents f1a17c6 + fc5a39b commit 75c4de6
Show file tree
Hide file tree
Showing 62 changed files with 1,368 additions and 1,374 deletions.
14 changes: 9 additions & 5 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
'eslint:recommended',
'plugin:markdown/recommended',
'plugin:import/errors',
'plugin:eslint-comments/recommended',
'plugin:@eslint-community/eslint-comments/recommended',
'plugin:unicorn/recommended',
'plugin:promise/recommended',
'plugin:prettier/recommended',
Expand Down Expand Up @@ -226,6 +226,7 @@ module.exports = {
'unicorn/no-static-only-class': 'off',
'unicorn/prefer-number-properties': 'off',
'unicorn/prefer-string-raw': 'off',
'unicorn/prefer-global-this': 'off',
},
},
// demonstration of matchers usage
Expand Down Expand Up @@ -347,8 +348,8 @@ module.exports = {
],
rules: {
'@typescript-eslint/ban-types': 'off',
'eslint-comments/disable-enable-pair': 'off',
'eslint-comments/no-unlimited-disable': 'off',
'@eslint-community/eslint-comments/disable-enable-pair': 'off',
'@eslint-community/eslint-comments/no-unlimited-disable': 'off',
'prefer-rest-params': 'off',
'prefer-spread': 'off',
'sort-keys ': 'off',
Expand Down Expand Up @@ -477,8 +478,11 @@ module.exports = {
'default-case': 'off',
'dot-notation': 'off',
eqeqeq: ['error', 'smart'],
'eslint-comments/disable-enable-pair': ['error', {allowWholeFile: true}],
'eslint-comments/no-unused-disable': 'error',
'@eslint-community/eslint-comments/disable-enable-pair': [
'error',
{allowWholeFile: true},
],
'@eslint-community/eslint-comments/no-unused-disable': 'error',
'func-names': 'off',
'func-style': ['off', 'declaration'],
'global-require': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]
node-version: [16.x, 18.x, 20.x, 22.x, 23.x]
name: Node v${{ matrix.node-version }}
runs-on: ${{ inputs.os }}

Expand Down
312 changes: 156 additions & 156 deletions .yarn/releases/yarn-3.8.4.cjs → .yarn/releases/yarn-3.8.7.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.8.4.cjs
yarnPath: .yarn/releases/yarn-3.8.7.cjs
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
### Fixes

- `[babel-plugin-jest-hoist]` Use `denylist` instead of the deprecated `blacklist` for Babel 8 support ([#14109](https://github.com/jestjs/jest/pull/14109))
- `[babel-plugin-jest-hoist]` Do not rely on buggy Babel behaviour ([#15415](https://github.com/jestjs/jest/pull/15415))
- `[expect]` Check error instance type for `toThrow/toThrowError` ([#14576](https://github.com/jestjs/jest/pull/14576))
- `[expect]` Improve diff for failing `expect.objectContaining` ([#15038](https://github.com/jestjs/jest/pull/15038))
- `[expect]` Use `Array.isArray` to check if an array is an `Array` ([#15101](https://github.com/jestjs/jest/pull/15101))
Expand Down Expand Up @@ -84,6 +85,7 @@
- [**BREAKING**] `--testPathPattern` is now `--testPathPatterns`
- [**BREAKING**] Specifying `testPathPatterns` when programmatically calling `watch` must be specified as `new TestPathPatterns(patterns)`, where `TestPathPatterns` can be imported from `@jest/pattern`
- `[jest-reporters, jest-runner]` Unhandled errors without stack get correctly logged to console ([#14619](https://github.com/jestjs/jest/pull/14619))
- `[jest-util]` Always load `mjs` files with `import` ([#15447](https://github.com/jestjs/jest/pull/15447))
- `[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))
- `[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))

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

## 29.7.0

Expand Down
2 changes: 2 additions & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ jest --seed=1324

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.

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.

:::

### `--selectProjects <project1> ... <projectN>`
Expand Down
10 changes: 5 additions & 5 deletions docs/GlobalAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ Use `describe.each` if you keep duplicating the same test suites with different
- `%$` - Number of the test case.
- `%%` - single percent sign ('%'). This does not consume an argument.
- Or generate unique test titles by injecting properties of test case object with `$variable`
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
- 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)
- You can use `$#` to inject the index of the test case
- You cannot use `$variable` with the `printf` formatting except for `%%`
- `fn`: `Function` the suite of tests to be run, this is the function that will receive the parameters in each row as function arguments.
Expand Down Expand Up @@ -305,7 +305,7 @@ describe.each([
- First row of variable name column headings separated with `|`
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
- `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.
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
- 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)
- `fn`: `Function` the suite of tests to be run, this is the function that will receive the test data object.
- 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.

Expand Down Expand Up @@ -574,7 +574,7 @@ test.concurrent.each([
- First row of variable name column headings separated with `|`
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
- `name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
- 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)
- `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**.
- 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.

Expand Down Expand Up @@ -697,7 +697,7 @@ Use `test.each` if you keep duplicating the same test with different data. `test
- `%$` - Number of the test case.
- `%%` - single percent sign ('%'). This does not consume an argument.
- Or generate unique test titles by injecting properties of test case object with `$variable`
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
- 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)
- You can use `$#` to inject the index of the test case
- You cannot use `$variable` with the `printf` formatting except for `%%`
- `fn`: `Function` the test to be run, this is the function that will receive the parameters in each row as function arguments.
Expand Down Expand Up @@ -731,7 +731,7 @@ test.each([
- First row of variable name column headings separated with `|`
- One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
- `name`: `String` the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
- To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
- 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)
- `fn`: `Function` the test to be run, this is the function that will receive the test data object.
- 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.

Expand Down
1 change: 0 additions & 1 deletion docs/TestingFrameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Jest is a universal testing platform, with the ability to adapt to any JavaScrip
## AngularJS

- [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))
- [Running AngularJS Tests with Jest](https://engineering.talentpair.com/running-angularjs-tests-with-jest-49d0cc9c6d26) by Ben Brandt ([@benjaminbrandt](https://twitter.com/benjaminbrandt))
- [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))

## Angular
Expand Down
26 changes: 13 additions & 13 deletions e2e/__tests__/__snapshots__/wrongEnv.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ exports[`Wrong globals for environment on node <=18 print useful error for navig
ReferenceError: navigator is not defined
30 |
31 | test('use navigator', () => {
> 32 | const userAgent = navigator.userAgent;
31 |
32 | test('use navigator', () => {
> 33 | const userAgent = navigator.userAgent;
| ^
33 |
34 | console.log(userAgent);
35 |
34 |
35 | console.log(userAgent);
36 |
at Object.navigator (__tests__/node.js:32:21)"
at Object.navigator (__tests__/node.js:33:21)"
`;
exports[`Wrong globals for environment print useful error for document 1`] = `
Expand Down Expand Up @@ -83,15 +83,15 @@ exports[`Wrong globals for environment print useful error for window 1`] = `
ReferenceError: window is not defined
22 |
23 | test('use window', () => {
> 24 | const location = window.location;
24 | // eslint-disable-next-line unicorn/prefer-global-this
> 25 | const location = window.location;
| ^
25 |
26 | console.log(location);
27 |
26 |
27 | console.log(location);
28 |
at Object.window (__tests__/node.js:24:20)"
at Object.window (__tests__/node.js:25:20)"
`;
exports[`Wrong globals for environment print useful error when it explodes during evaluation 1`] = `
Expand Down
4 changes: 2 additions & 2 deletions e2e/console-jsdom/__tests__/console.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ test('can mock console.error calls from jsdom', () => {

function onError(event) {}

window.addEventListener('error', onError);
globalThis.addEventListener('error', onError);
fakeNode.addEventListener(evtType, callCallback, false);
evt.initEvent(evtType, false, false);
fakeNode.dispatchEvent(evt);
window.removeEventListener('error', onError);
globalThis.removeEventListener('error', onError);

expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenCalledWith(
Expand Down
1 change: 1 addition & 0 deletions e2e/env-test/__tests__/equivalent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

const skipTestJSDOM = isJSDOM ? test.skip : test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
/*eslint-env browser */

test('found url jestjs.io', () => {
expect(window.location.href).toBe('https://jestjs.io/');
expect(globalThis.location.href).toBe('https://jestjs.io/');
});
4 changes: 3 additions & 1 deletion e2e/esm-config/js/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

const displayName = await Promise.resolve('Config from js file');

export default {
displayName: 'Config from js file',
displayName,
testEnvironment: 'node',
};
4 changes: 3 additions & 1 deletion e2e/esm-config/mjs/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

const displayName = await Promise.resolve('Config from mjs file');

export default {
displayName: 'Config from mjs file',
displayName,
testEnvironment: 'node',
};
6 changes: 3 additions & 3 deletions e2e/fake-timers/do-not-fake/__tests__/doNotFake.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
'use strict';

const mockPerformanceMark = jest.fn();
window.performance.mark = mockPerformanceMark;
globalThis.performance.mark = mockPerformanceMark;

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

expect(window.performance.mark).toBeUndefined();
expect(globalThis.performance.mark).toBeUndefined();
});

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

expect(window.performance.mark).toBe(mockPerformanceMark);
expect(globalThis.performance.mark).toBe(mockPerformanceMark);
});
6 changes: 3 additions & 3 deletions e2e/native-esm/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ __metadata:
linkType: hard

"cross-spawn@npm:^7.0.0":
version: 7.0.3
resolution: "cross-spawn@npm:7.0.3"
version: 7.0.6
resolution: "cross-spawn@npm:7.0.6"
dependencies:
path-key: ^3.1.0
shebang-command: ^2.0.0
which: ^2.0.1
checksum: 671cc7c7288c3a8406f3c69a3ae2fc85555c04169e9d611def9a675635472614f1c0ed0ef80955d5b6d4e724f6ced67f0ad1bb006c2ea643488fcfef994d7f52
checksum: 8d306efacaf6f3f60e0224c287664093fa9185680b2d195852ba9a863f85d02dcc737094c6e512175f8ee0161f9b87c73c6826034c2422e39de7d6569cf4503b
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion e2e/nested-event-loop/__tests__/nestedEventLoop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ it('can assert on errors across nested event loops', () => {
throw new Error('This should be caught.');
});
let caught = null;
window.addEventListener('error', e => {
globalThis.addEventListener('error', e => {
caught = e.error;
});
expect(() => {
Expand Down
6 changes: 2 additions & 4 deletions e2e/override-globals/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ describe('parent', () => {
});

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

expect(`${atob()} ${btoa()}`).toBe('hello there');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
/*eslint-env browser */

test('use jsdom and set the URL in this test file', () => {
expect(window.location.href).toBe('https://jestjs.io/');
expect(globalThis.location.href).toBe('https://jestjs.io/');
});
1 change: 1 addition & 0 deletions e2e/wrong-env/__tests__/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test('use document', () => {
});

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

console.log(location);
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@babel/preset-typescript": "^7.0.0",
"@babel/register": "^7.0.0",
"@crowdin/cli": "^4.0.0",
"@eslint-community/eslint-plugin-eslint-comments": "^4.0.0",
"@jest/globals": "workspace:*",
"@jest/test-utils": "workspace:*",
"@lerna-lite/cli": "^3.0.0",
Expand All @@ -33,15 +34,14 @@
"eslint": "^8.8.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.2.5",
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-jest": "^28.0.0",
"eslint-plugin-jsdoc": "^50.0.0",
"eslint-plugin-local": "link:./.eslintplugin",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-unicorn": "^56.0.0",
"execa": "^5.0.0",
"find-process": "^1.4.1",
"glob": "^10.3.10",
Expand All @@ -61,7 +61,7 @@
"jest-watch-typeahead": "^2.2.0",
"jquery": "^3.2.1",
"js-yaml": "^4.1.0",
"micromatch": "^4.0.7",
"micromatch": "^4.0.8",
"mock-fs": "^5.1.2",
"netlify-plugin-cache": "^1.0.3",
"node-notifier": "^10.0.0",
Expand All @@ -78,7 +78,7 @@
"strip-json-comments": "^3.1.1",
"tempy": "^1.0.0",
"ts-node": "^10.5.0",
"tstyche": "^2.0.0",
"tstyche": "^3.0.0",
"typescript": "^5.0.4",
"webpack": "^5.68.0",
"webpack-node-externals": "^3.0.0",
Expand Down Expand Up @@ -204,5 +204,5 @@
"psl": "patch:psl@npm:^1.9.0#./.yarn/patches/psl-npm-1.9.0-a546edad1a.patch",
"ts-node@^10.5.0": "patch:ts-node@npm:^10.5.0#./.yarn/patches/ts-node-npm-10.9.1-6c268be7f4.patch"
},
"packageManager": "[email protected].4"
"packageManager": "[email protected].7"
}
Loading

0 comments on commit 75c4de6

Please sign in to comment.