Skip to content

Commit

Permalink
Merge branch 'main' into test-failing-snapshot-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledElmorsy authored Oct 2, 2023
2 parents 1b3d2bb + 46285d8 commit 8ac6139
Show file tree
Hide file tree
Showing 67 changed files with 1,783 additions and 265 deletions.
1 change: 1 addition & 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
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
### 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))
Expand All @@ -21,6 +23,7 @@
- `[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))

Expand Down
4 changes: 2 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ This does not change the exit code in the case of Jest errors (e.g. invalid conf

### `testMatch` \[array<string>]

(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 @@ -2024,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
30 changes: 15 additions & 15 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 @@ -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
14 changes: 11 additions & 3 deletions e2e/__tests__/__snapshots__/nativeEsm.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ exports[`does not enforce import assertions 1`] = `
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-missing-import-assertions.test/i."
Ran all test suites matching /native-esm-missing-import-assertions.test.js/i."
`;
exports[`on node >=16.9.0 support re-exports from CJS of dual packages 1`] = `
exports[`on node >=16.11.0 support re-exports from CJS of dual packages 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Expand All @@ -21,7 +21,15 @@ exports[`on node >=16.12.0 supports import assertions 1`] = `
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-import-assertions.test/i."
Ran all test suites matching /native-esm-import-assertions.test.js/i."
`;
exports[`properly handle re-exported native modules in ESM via CJS 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites matching /native-esm-native-module.test.js/i."
`;
exports[`runs WebAssembly (Wasm) test with native ESM 1`] = `
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ exports[`--showConfig outputs config info and exits 1`] = `
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
"**/__tests__/**/*.?([mc])[jt]s?(x)",
"**/?(*.)+(spec|test).?([mc])[jt]s?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
Expand Down
9 changes: 9 additions & 0 deletions e2e/__tests__/__snapshots__/testMatchDefault.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`testMatch should able to match file with \`?([mc])[jt]s?(x)\` by default 1`] = `
"Test Suites: 16 passed, 16 total
Tests: 16 passed, 16 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites."
`;
24 changes: 19 additions & 5 deletions e2e/__tests__/nativeEsm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ test('supports top-level await', () => {
expect(exitCode).toBe(0);
});

// minimum version supported by discord.js
onNodeVersions('>=16.9.0', () => {
// minimum version supported by discord.js is 16.9, but they use syntax from 16.11
onNodeVersions('>=16.11.0', () => {
test('support re-exports from CJS of dual packages', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
Expand Down Expand Up @@ -97,7 +97,21 @@ test('runs WebAssembly (Wasm) test with native ESM', () => {
test('does not enforce import assertions', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-missing-import-assertions.test'],
['native-esm-missing-import-assertions.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

const {summary} = extractSummary(stderr);

expect(summary).toMatchSnapshot();
expect(stdout).toBe('');
expect(exitCode).toBe(0);
});

test('properly handle re-exported native modules in ESM via CJS', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-native-module.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

Expand All @@ -113,7 +127,7 @@ onNodeVersions('>=16.12.0', () => {
test('supports import assertions', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-import-assertions.test'],
['native-esm-import-assertions.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

Expand All @@ -129,7 +143,7 @@ onNodeVersions('<16.12.0', () => {
test('syntax error for import assertions', () => {
const {exitCode, stderr, stdout} = runJest(
DIR,
['native-esm-import-assertions.test'],
['native-esm-import-assertions.test.js'],
{nodeOptions: '--experimental-vm-modules --no-warnings'},
);

Expand Down
16 changes: 16 additions & 0 deletions e2e/__tests__/testMatchDefault.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {extractSummary} from '../Utils';
import runJest from '../runJest';

it('testMatch should able to match file with `?([mc])[jt]s?(x)` by default', () => {
const result = runJest('test-match-default');
expect(result.exitCode).toBe(0);
const {summary} = extractSummary(result.stderr);
expect(summary).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import {color} from '../entry';
import type {Color} from '../types';

jest.mock('some-module', () => ({} as Partial<{}>), {virtual: true});
jest.mock('some-module', () => ({}) as Partial<{}>, {virtual: true});

jest.mock('../entry', () => {
const color: Color = 'blue';
Expand Down
12 changes: 12 additions & 0 deletions e2e/native-esm/__tests__/native-esm-native-module.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import ivm from 'isolated-vm';

test('supports native modules exported via CJS', () => {
expect(ivm).toBeDefined();
});
1 change: 1 addition & 0 deletions e2e/native-esm/__tests__/native-esm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test('should support importing node core modules', () => {
devDependencies: {
'discord.js': '14.3.0',
'iso-constants': '^0.1.2',
'isolated-vm': '^4.6.0',
yargs: '^17.5.1',
},
jest: {
Expand Down
1 change: 1 addition & 0 deletions e2e/native-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"discord.js": "14.3.0",
"iso-constants": "^0.1.2",
"isolated-vm": "^4.6.0",
"yargs": "^17.5.1"
},
"jest": {
Expand Down
Loading

0 comments on commit 8ac6139

Please sign in to comment.