Skip to content

Commit

Permalink
Merge branch 'main' into chinn/relative-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 2, 2023
2 parents 3c22ef3 + 46285d8 commit 0b22568
Show file tree
Hide file tree
Showing 185 changed files with 5,616 additions and 3,888 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ module.exports = {
'e2e/failures/macros.js',
'e2e/test-in-root/*.js',
'e2e/test-match/test-suites/*',
'e2e/test-match-default/dot-spec-tests/*',
'packages/test-utils/src/ConditionalTest.ts',
],
env: {'jest/globals': true},
Expand Down Expand Up @@ -599,6 +600,7 @@ module.exports = {
'unicorn/explicit-length-check': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/numeric-separators-style': 'error',
'unicorn/prefer-default-parameters': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/template-indent': 'error',
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ concurrency:

permissions:
contents: read # to fetch code (actions/checkout)
issues: write # to create an issue and comment in it

jobs:
prepare-yarn-cache-ubuntu:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
### Features

- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369))
- `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584))
- `[@jest/core]` [**BREAKING**] Group together open handles with the same stack trace ([#13417](https://github.com/jestjs/jest/pull/13417), & [#14543](https://github.com/jestjs/jest/pull/14543))
- `[@jest/core, @jest/test-sequencer]` [**BREAKING**] Exposes `globalConfig` & `contexts` to `TestSequencer` ([#14535](https://github.com/jestjs/jest/pull/14535), & [#14543](https://github.com/jestjs/jest/pull/14543))
- `[jest-environment-jsdom]` [**BREAKING**] Upgrade JSDOM to v22 ([#13825](https://github.com/jestjs/jest/pull/13825))
- `[@jest/fake-timers]` [**BREAKING**] Upgrade `@sinonjs/fake-timers` to v11 ([#14544](https://github.com/jestjs/jest/pull/14544))
- `[@jest/schemas]` Upgrade `@sinclair/typebox` to v0.31 ([#14072](https://github.com/jestjs/jest/pull/14072))
- `[@jest/types]` `test.each()`: Accept a readonly (`as const`) table properly ([#14565](https://github.com/jestjs/jest/pull/14565))
- `[jest-snapshot]` [**BREAKING**] Add support for [Error causes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) in snapshots ([#13965](https://github.com/facebook/jest/pull/13965))
- `[jest-snapshot]` Support Prettier 3 ([#14566](https://github.com/facebook/jest/pull/14566))
- `[pretty-format]` [**BREAKING**] Do not render empty string children (`''`) in React plugin ([#14470](https://github.com/facebook/jest/pull/14470))

### Fixes

- `[babel-plugin-jest-hoist]` Use `denylist` instead of the deprecated `blacklist` for Babel 8 support ([#14109](https://github.com/jestjs/jest/pull/14109))
- `[expect]` Check error instance type for `toThrow/toThrowError` ([#14576](https://github.com/jestjs/jest/pull/14576))
- `[jest-circus]` [**BREAKING**] Prevent false test failures caused by promise rejections handled asynchronously ([#14315](https://github.com/jestjs/jest/pull/14315))
- `[jest-config]` Make sure to respect `runInBand` option ([#14578](https://github.com/facebook/jest/pull/14578))
- `[@jest/expect-utils]` Fix comparison of `DataView` ([#14408](https://github.com/jestjs/jest/pull/14408))
- `[jest-leak-detector]` Make leak-detector more aggressive when running GC ([#14526](https://github.com/jestjs/jest/pull/14526))
- `[jest-runtime]` Properly handle re-exported native modules in ESM via CJS ([#14589](https://github.com/jestjs/jest/pull/14589))
- `[jest-util]` Make sure `isInteractive` works in a browser ([#14552](https://github.com/jestjs/jest/pull/14552))
- `[pretty-format]` [**BREAKING**] Print `ArrayBuffer` and `DataView` correctly ([#14290](https://github.com/facebook/jest/pull/14290))
- `[jest-cli]` When specifying paths on the command line, only match against the relative paths of the test files ([#12519](https://github.com/facebook/jest/pull/12519))
Expand Down
4 changes: 3 additions & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, Depende
% @types/node in the root need to stay on ~14.14.45
'@types/node',
% upgrading the entire repository is a breaking change
'glob'
'glob',
% repository and snapshot
'prettier'
]).

% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
Expand Down
40 changes: 2 additions & 38 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1145,42 +1145,6 @@ Default: `'prettier'`

Sets the path to the [`prettier`](https://prettier.io/) node module used to update inline snapshots.

<details>
<summary>Prettier version 3 is not supported!</summary>

You can either pass `prettierPath: null` in your config to disable using prettier if you don't need it, or use v2 of Prettier solely for Jest.

```json title="package.json"
{
"devDependencies": {
"prettier-2": "npm:prettier@^2"
}
}
```

```js tab
/** @type {import('jest').Config} */
const config = {
prettierPath: require.resolve('prettier-2'),
};

module.exports = config;
```

```ts tab
import type {Config} from 'jest';

const config: Config = {
prettierPath: require.resolve('prettier-2'),
};

export default config;
```

We hope to support Prettier v3 seamlessly out of the box in a future version of Jest. See [this](https://github.com/jestjs/jest/issues/14305) tracking issue.

</details>

### `projects` \[array&lt;string | ProjectConfig&gt;]

Default: `undefined`
Expand Down Expand Up @@ -2036,7 +2000,7 @@ This does not change the exit code in the case of Jest errors (e.g. invalid conf

### `testMatch` \[array&lt;string&gt;]

(default: `[ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]`)
(default: `[ "**/__tests__/**/*.?([mc])[jt]s?(x)", "**/?(*.)+(spec|test).?([mc])[jt]s?(x)" ]`)

The glob patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`.

Expand All @@ -2060,7 +2024,7 @@ These pattern strings match against the full path. Use the `<rootDir>` string to

### `testRegex` \[string | array&lt;string&gt;]

Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$`
Default: `(/__tests__/.*|(\\.|/)(test|spec))\\.[mc]?[jt]sx?$`

The pattern or patterns Jest uses to detect test files. By default it looks for `.js`, `.jsx`, `.ts` and `.tsx` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.js` or `Component.spec.js`). It will also find files called `test.js` or `spec.js`. See also [`testMatch` [array&lt;string&gt;]](#testmatch-arraystring), but note that you cannot specify both options.

Expand Down
2 changes: 1 addition & 1 deletion docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ The type declaration of the matcher can live in a `.d.ts` file or in an imported

:::tip

Instead of importing `toBeWithinRange` module to the test file, you can enable the matcher for all tests by moving the `expect.extend` call to a [`setupFilesAfterEnv`](Configuration.md/#setupfilesafterenv-array) script:
Instead of importing `toBeWithinRange` module to the test file, you can enable the matcher for all tests by moving the `expect.extend` call to a [`setupFilesAfterEnv`](Configuration.md#setupfilesafterenv-array) script:

```js
import {expect} from '@jest/globals';
Expand Down
32 changes: 16 additions & 16 deletions docs/GlobalAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe.each([
});
```

#### 2. `` describe.each`table`(name, fn, timeout) ``
#### 2. ``describe.each`table`(name, fn, timeout)``

- `table`: `Tagged Template Literal`
- First row of variable name column headings separated with `|`
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('my other beverage', () => {

### `describe.only.each(table)(name, fn)`

Also under the aliases: `fdescribe.each(table)(name, fn)` and `` fdescribe.each`table`(name, fn) ``
Also under the aliases: `fdescribe.each(table)(name, fn)` and ``fdescribe.each`table`(name, fn)``

Use `describe.only.each` if you want to only run specific tests suites of data driven tests.

Expand All @@ -379,7 +379,7 @@ test('will not be run', () => {
});
```

#### `` describe.only.each`table`(name, fn) ``
#### ``describe.only.each`table`(name, fn)``

```js
describe.only.each`
Expand Down Expand Up @@ -424,7 +424,7 @@ Using `describe.skip` is often a cleaner alternative to temporarily commenting o

### `describe.skip.each(table)(name, fn)`

Also under the aliases: `xdescribe.each(table)(name, fn)` and `` xdescribe.each`table`(name, fn) ``
Also under the aliases: `xdescribe.each(table)(name, fn)` and ``xdescribe.each`table`(name, fn)``

Use `describe.skip.each` if you want to stop running a suite of data driven tests.

Expand All @@ -448,7 +448,7 @@ test('will be run', () => {
});
```

#### `` describe.skip.each`table`(name, fn) ``
#### ``describe.skip.each`table`(name, fn)``

```js
describe.skip.each`
Expand Down Expand Up @@ -525,7 +525,7 @@ test.concurrent('subtraction 2 numbers', async () => {

:::tip

Use the [`maxConcurrency`](Configuration.md/#maxconcurrency-number) configuration option to prevent Jest from executing more than the specified amount of tests at the same time.
Use the [`maxConcurrency`](Configuration.md#maxconcurrency-number) configuration option to prevent Jest from executing more than the specified amount of tests at the same time.

:::

Expand Down Expand Up @@ -566,7 +566,7 @@ test.concurrent.each([
});
```

#### 2. `` test.concurrent.each`table`(name, fn, timeout) ``
#### 2. ``test.concurrent.each`table`(name, fn, timeout)``

- `table`: `Tagged Template Literal`
- First row of variable name column headings separated with `|`
Expand Down Expand Up @@ -613,7 +613,7 @@ test('will not be run', () => {
});
```

#### `` test.only.each`table`(name, fn) ``
#### ``test.only.each`table`(name, fn)``

```js
test.concurrent.only.each`
Expand Down Expand Up @@ -654,7 +654,7 @@ test('will be run', () => {
});
```

#### `` test.concurrent.skip.each`table`(name, fn) ``
#### ``test.concurrent.skip.each`table`(name, fn)``

```js
test.concurrent.skip.each`
Expand All @@ -673,7 +673,7 @@ test('will be run', () => {

### `test.each(table)(name, fn, timeout)`

Also under the alias: `it.each(table)(name, fn)` and `` it.each`table`(name, fn) ``
Also under the alias: `it.each(table)(name, fn)` and ``it.each`table`(name, fn)``

Use `test.each` if you keep duplicating the same test with different data. `test.each` allows you to write the test once and pass data in.

Expand Down Expand Up @@ -722,7 +722,7 @@ test.each([
});
```

#### 2. `` test.each`table`(name, fn, timeout) ``
#### 2. ``test.each`table`(name, fn, timeout)``

- `table`: `Tagged Template Literal`
- First row of variable name column headings separated with `|`
Expand Down Expand Up @@ -779,7 +779,7 @@ test.failing('it is equal', () => {

### `test.failing.each(name, fn, timeout)`

Also under the alias: `it.failing.each(table)(name, fn)` and `` it.failing.each`table`(name, fn) ``
Also under the alias: `it.failing.each(table)(name, fn)` and ``it.failing.each`table`(name, fn)``

:::note

Expand Down Expand Up @@ -851,7 +851,7 @@ Usually you wouldn't check code using `test.only` into source control - you woul

### `test.only.each(table)(name, fn)`

Also under the aliases: `it.only.each(table)(name, fn)`, `fit.each(table)(name, fn)`, `` it.only.each`table`(name, fn) `` and `` fit.each`table`(name, fn) ``
Also under the aliases: `it.only.each(table)(name, fn)`, `fit.each(table)(name, fn)`, ``it.only.each`table`(name, fn)`` and ``fit.each`table`(name, fn)``

Use `test.only.each` if you want to only run specific tests with different test data.

Expand All @@ -873,7 +873,7 @@ test('will not be run', () => {
});
```

#### `` test.only.each`table`(name, fn) ``
#### ``test.only.each`table`(name, fn)``

```js
test.only.each`
Expand Down Expand Up @@ -914,7 +914,7 @@ You could comment the test out, but it's often a bit nicer to use `test.skip` be

### `test.skip.each(table)(name, fn)`

Also under the aliases: `it.skip.each(table)(name, fn)`, `xit.each(table)(name, fn)`, `xtest.each(table)(name, fn)`, `` it.skip.each`table`(name, fn) ``, `` xit.each`table`(name, fn) `` and `` xtest.each`table`(name, fn) ``
Also under the aliases: `it.skip.each(table)(name, fn)`, `xit.each(table)(name, fn)`, `xtest.each(table)(name, fn)`, ``it.skip.each`table`(name, fn)``, ``xit.each`table`(name, fn)`` and ``xtest.each`table`(name, fn)``

Use `test.skip.each` if you want to stop running a collection of data driven tests.

Expand All @@ -936,7 +936,7 @@ test('will be run', () => {
});
```

#### `` test.skip.each`table`(name, fn) ``
#### ``test.skip.each`table`(name, fn)``

```js
test.skip.each`
Expand Down
6 changes: 3 additions & 3 deletions docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,17 @@ Returns the `jest` object for chaining.

:::tip

Writing tests in TypeScript? Use the [`jest.Mocked`](MockFunctionAPI.md/#jestmockedsource) utility type or the [`jest.mocked()`](MockFunctionAPI.md/#jestmockedsource-options) helper method to have your mocked modules typed.
Writing tests in TypeScript? Use the [`jest.Mocked`](MockFunctionAPI.md#jestmockedsource) utility type or the [`jest.mocked()`](MockFunctionAPI.md#jestmockedsource-options) helper method to have your mocked modules typed.

:::

### `jest.Mocked<Source>`

See [TypeScript Usage](MockFunctionAPI.md/#jestmockedsource) chapter of Mock Functions page for documentation.
See [TypeScript Usage](MockFunctionAPI.md#jestmockedsource) chapter of Mock Functions page for documentation.

### `jest.mocked(source, options?)`

See [TypeScript Usage](MockFunctionAPI.md/#jestmockedsource-options) chapter of Mock Functions page for documentation.
See [TypeScript Usage](MockFunctionAPI.md#jestmockedsource-options) chapter of Mock Functions page for documentation.

### `jest.unmock(moduleName)`

Expand Down
2 changes: 1 addition & 1 deletion docs/MockFunctionAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ afterEach(() => {
});

test('renders correctly with a given date', () => {
spiedDateNow = setDateNow(1482363367071);
spiedDateNow = setDateNow(1_482_363_367_071);
// ...

expect(spiedDateNow).toHaveBeenCalledTimes(1);
Expand Down
2 changes: 1 addition & 1 deletion docs/MockFunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ const otherObj = {

## Mock Names

You can optionally provide a name for your mock functions, which will be displayed instead of `'jest.fn()'` in the test error output. Use [`.mockName()`](MockFunctionAPI.md/#mockfnmocknamename) if you want to be able to quickly identify the mock function reporting an error in your test output.
You can optionally provide a name for your mock functions, which will be displayed instead of `'jest.fn()'` in the test error output. Use [`.mockName()`](MockFunctionAPI.md#mockfnmocknamename) if you want to be able to quickly identify the mock function reporting an error in your test output.

```javascript
const myMockFn = jest
Expand Down
2 changes: 1 addition & 1 deletion docs/SnapshotTesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Your tests should be deterministic. Running the same tests multiple times on a c
For example, if you have a [Clock](https://github.com/jestjs/jest/blob/main/examples/snapshot/Clock.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run:

```js
Date.now = jest.fn(() => 1482363367071);
Date.now = jest.fn(() => 1_482_363_367_071);
```

Now, every time the snapshot test case runs, `Date.now()` will return `1482363367071` consistently. This will result in the same snapshot being generated for this component regardless of when the test is run.
Expand Down
2 changes: 1 addition & 1 deletion docs/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Most commonly this is being caused by conflicting Promise implementations. Consi
If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout`

```js
jest.setTimeout(10000); // 10 second timeout
jest.setTimeout(10_000); // 10 second timeout
```

## Watchman Issues
Expand Down
2 changes: 1 addition & 1 deletion docs/UpgradingToJest29.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import TypeScriptExamplesNote from './_TypeScriptExamplesNote.md';

### `jest.mocked()`

The [`jest.mocked()`](MockFunctionAPI.md/#jestmockedsource-options) helper method now wraps types of deep members of passed object by default. If you have used the method with `true` as the second argument, remove it to avoid type errors:
The [`jest.mocked()`](MockFunctionAPI.md#jestmockedsource-options) helper method now wraps types of deep members of passed object by default. If you have used the method with `true` as the second argument, remove it to avoid type errors:

```diff
- const mockedObject = jest.mocked(someObject, true);
Expand Down
6 changes: 3 additions & 3 deletions e2e/__tests__/__snapshots__/detectOpenHandles.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ exports[`prints out info about open handlers from inside tests 1`] = `
7 |
8 | test('something', () => {
> 9 | setTimeout(() => {}, 30000);
> 9 | setTimeout(() => {}, 30_000);
| ^
10 | expect(true).toBe(true);
11 | });
Expand All @@ -54,7 +54,7 @@ exports[`prints out info about open handlers from lifecycle functions with a \`d
7 |
8 | beforeAll(done => {
> 9 | setTimeout(() => {}, 10000);
> 9 | setTimeout(() => {}, 10_000);
| ^
10 | done();
11 | });
Expand All @@ -70,7 +70,7 @@ exports[`prints out info about open handlers from tests with a \`done\` callback
7 |
8 | test('something', done => {
> 9 | setTimeout(() => {}, 10000);
> 9 | setTimeout(() => {}, 10_000);
| ^
10 | expect(true).toBe(true);
11 | done();
Expand Down
Loading

0 comments on commit 0b22568

Please sign in to comment.