Skip to content

Commit

Permalink
Merge branch 'main' into fix/worker-threads-data-clone
Browse files Browse the repository at this point in the history
  • Loading branch information
dj-stormtrooper authored Aug 21, 2023
2 parents 76791cc + 642267f commit e0f991a
Show file tree
Hide file tree
Showing 91 changed files with 402 additions and 319 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@

### Fixes

- `[jest-core]` Fix typo in `scheduleAndRun` performance marker ([#14434](https://github.com/jestjs/jest/pull/14434))
- `[jest-runner]` Handle unsafe worker_threads structureClone with function type in matchers. ([#14436](https://github.com/jestjs/jest/pull/14436))
- `[jest-worker]` Additional error wrapper for `parentPort.postMessage` to fix unhandled `DataCloneError`. ([#14436](https://github.com/jestjs/jest/pull/14436))

### Chore & Maintenance

## 29.6.3

- `[expect, @jest/expect-utils]` `ObjectContaining` support `sumbol` as key ([#14414](https://github.com/jestjs/jest/pull/14414))
- `[expect]` Remove `@types/node` from dependencies ([#14385](https://github.com/jestjs/jest/pull/14385))
- `[jest-core]` Use workers in watch mode by default to avoid crashes ([#14059](https://github.com/facebook/jest/pull/14059) & [#14085](https://github.com/facebook/jest/pull/14085)).
- `[jest-reporters]` Update `istanbul-lib-instrument` dependency to v6. ([#14401](https://github.com/jestjs/jest/pull/14401))
- `[jest-runner]` Handle unsafe worker_threads structureClone with function type in matchers. ([#14436](https://github.com/jestjs/jest/pull/14436))
- `[jest-worker]` Additional error wrapper for `parentPort.postMessage` to fix unhandled `DataCloneError`. ([#14436](https://github.com/jestjs/jest/pull/14436))
- `[jest-mock]` Revert [#13692](https://github.com/jestjs/jest/pull/13692) as it was a breaking change ([#14429](https://github.com/jestjs/jest/pull/14429))
- `[jest-mock]` Revert [#13866](https://github.com/jestjs/jest/pull/13866) as it was a breaking change ([#14429](https://github.com/jestjs/jest/pull/14429))
- `[jest-mock]` Revert [#13867](https://github.com/jestjs/jest/pull/13867) as it was a breaking change ([#14429](https://github.com/jestjs/jest/pull/14429))
- `[@jest/reporters]` Marks Reporter's hooks as optional ([#14433](https://github.com/jestjs/jest/pull/14433))
- `[jest-runtime]` Fix dynamic ESM import module bug when loaded module through `jest.isolateModulesAsync` ([#14397](https://github.com/jestjs/jest/pull/14397))

### Chore & Maintenance

### Performance
- `[jest-changed-files, jest-circus, jest-console, @jest/core, @jest/runtime, @jest/transform]` Use `invariant` and `notEmpty` from `jest-util` rather than own internal ([#14366](https://github.com/jestjs/jest/pull/14366))

## 29.6.2

Expand Down
8 changes: 7 additions & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ Hungry for reporters? Take a look at long list of [awesome reporters](https://gi

:::

Custom reporter module must export a class that takes [`globalConfig`](https://github.com/jestjs/jest/blob/v29.2.1/packages/jest-types/src/Config.ts#L358-L422), `reporterOptions` and `reporterContext` as constructor arguments and implements at least `onRunComplete()` method (for the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/jestjs/jest/blob/main/packages/jest-reporters/src/types.ts)):
Custom reporter module must export a class that takes [`globalConfig`](https://github.com/jestjs/jest/blob/v29.2.1/packages/jest-types/src/Config.ts#L358-L422), `reporterOptions` and `reporterContext` as constructor arguments:

```js title="custom-reporter.js"
class CustomReporter {
Expand Down Expand Up @@ -1430,6 +1430,12 @@ class CustomReporter {
module.exports = CustomReporter;
```

:::note

For the full list of hooks and argument types see the `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/jestjs/jest/blob/main/packages/jest-reporters/src/types.ts).

:::

### `resetMocks` \[boolean]

Default: `false`
Expand Down
4 changes: 2 additions & 2 deletions docs/ManualMocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Scoped modules (also known as [scoped packages](https://docs.npmjs.com/cli/v6/us

:::caution

If we want to mock Node's build-in modules (e.g.: `fs` or `path`), then explicitly calling e.g. `jest.mock('path')` is **required**, because build-in modules are not mocked by default.
If we want to mock Node's built-in modules (e.g.: `fs` or `path`), then explicitly calling e.g. `jest.mock('path')` is **required**, because built-in modules are not mocked by default.

:::

Expand Down Expand Up @@ -110,7 +110,7 @@ fs.readdirSync = readdirSync;
module.exports = fs;
```

Now we write our test. In this case `jest.mock('fs')` must be called explicitly, because `fs` is Node’s build-in module:
Now we write our test. In this case `jest.mock('fs')` must be called explicitly, because `fs` is Node’s built-in module:

```javascript title="__tests__/FileSummarizer-test.js"
'use strict';
Expand Down
4 changes: 1 addition & 3 deletions docs/MockFunctionAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ Beware that `mockFn.mockClear()` will replace `mockFn.mock`, not just reset the

### `mockFn.mockReset()`

Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also removes any mocked return values or implementations.

This is useful when you want to completely reset a _mock_ back to its initial state.
Does everything that [`mockFn.mockClear()`](#mockfnmockclear) does, and also replaces the mock implementation with an empty function, returning `undefined`.

The [`resetMocks`](configuration#resetmocks-boolean) configuration option is available to reset mocks automatically before each test.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
14 | });
15 | });
at eventHandler (../../packages/jest-circus/build/eventHandler.js:140:11)
at eventHandler (../../packages/jest-circus/build/eventHandler.js:141:11)
at test (__tests__/asyncDefinition.test.js:12:5)
● Test suite failed to run
Expand All @@ -31,7 +31,7 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
15 | });
16 |
at eventHandler (../../packages/jest-circus/build/eventHandler.js:103:11)
at eventHandler (../../packages/jest-circus/build/eventHandler.js:104:11)
at afterAll (__tests__/asyncDefinition.test.js:13:5)
● Test suite failed to run
Expand All @@ -46,7 +46,7 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
20 | });
21 |
at eventHandler (../../packages/jest-circus/build/eventHandler.js:140:11)
at eventHandler (../../packages/jest-circus/build/eventHandler.js:141:11)
at test (__tests__/asyncDefinition.test.js:18:3)
● Test suite failed to run
Expand All @@ -60,6 +60,6 @@ exports[`defining tests and hooks asynchronously throws 1`] = `
20 | });
21 |
at eventHandler (../../packages/jest-circus/build/eventHandler.js:103:11)
at eventHandler (../../packages/jest-circus/build/eventHandler.js:104:11)
at afterAll (__tests__/asyncDefinition.test.js:19:3)"
`;
9 changes: 9 additions & 0 deletions e2e/__tests__/__snapshots__/isolateModulesAsync.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[`runs test with isolate modules async import 1`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Ran all test suites."
`;
20 changes: 20 additions & 0 deletions e2e/__tests__/isolateModulesAsync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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';

test('runs test with isolate modules async import', () => {
const {exitCode, stderr} = runJest('isolate-modules-async', [], {
nodeOptions: '--experimental-vm-modules --no-warnings',
});

const {summary} = extractSummary(stderr);

expect(summary).toMatchSnapshot();
expect(exitCode).toBe(0);
});
22 changes: 22 additions & 0 deletions e2e/isolate-modules-async/__tests__/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* 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 {jest} from '@jest/globals';

test('should have a fresh module state in each isolateModulesAsync context', async () => {
await jest.isolateModulesAsync(async () => {
const {getState, incState} = await import('../main.js');
expect(getState()).toBe(0);
incState();
expect(getState()).toBe(1);
});
await jest.isolateModulesAsync(async () => {
const {getState, incState} = await import('../main.js');
expect(getState()).toBe(0);
incState();
expect(getState()).toBe(1);
});
});
15 changes: 15 additions & 0 deletions e2e/isolate-modules-async/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 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.
*/
let myState = 0;

export function incState() {
myState += 1;
}

export function getState() {
return myState;
}
8 changes: 8 additions & 0 deletions e2e/isolate-modules-async/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "isolate-modules-async",
"type": "module",
"jest": {
"transform": {},
"testEnvironment": "node"
}
}
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"syncWorkspaceLock": true
}
},
"version": "29.6.2"
"version": "29.6.3"
}
2 changes: 1 addition & 1 deletion packages/babel-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "babel-jest",
"description": "Jest plugin to use babel for transformation.",
"version": "29.6.2",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-jest-hoist",
"version": "29.5.0",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-jest",
"version": "29.5.0",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/diff-sequences/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "diff-sequences",
"version": "29.4.3",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/expect-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jest/expect-utils",
"version": "29.6.2",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expect",
"version": "29.6.2",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-changed-files/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-changed-files",
"version": "29.5.0",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand All @@ -18,6 +18,7 @@
},
"dependencies": {
"execa": "^5.0.0",
"jest-util": "workspace:^",
"p-limit": "^3.1.0"
},
"engines": {
Expand Down
11 changes: 4 additions & 7 deletions packages/jest-changed-files/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import pLimit = require('p-limit');
import {isNonNullable} from 'jest-util';
import git from './git';
import hg from './hg';
import sl from './sl';
Expand All @@ -16,10 +17,6 @@ type RootPromise = ReturnType<SCMAdapter['getRoot']>;

export type {ChangedFiles, ChangedFilesPromise} from './types';

function notEmpty<T>(value: T | null | undefined): value is T {
return value != null;
}

// This is an arbitrary number. The main goal is to prevent projects with
// many roots (50+) from spawning too many processes at once.
const mutex = pLimit(5);
Expand Down Expand Up @@ -78,8 +75,8 @@ export const findRepos = async (roots: Array<string>): Promise<Repos> => {
const slRepos = await Promise.all(roots.map(findSlRoot));

return {
git: new Set(gitRepos.filter(notEmpty)),
hg: new Set(hgRepos.filter(notEmpty)),
sl: new Set(slRepos.filter(notEmpty)),
git: new Set(gitRepos.filter(isNonNullable)),
hg: new Set(hgRepos.filter(isNonNullable)),
sl: new Set(slRepos.filter(isNonNullable)),
};
};
3 changes: 2 additions & 1 deletion packages/jest-changed-files/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"rootDir": "src",
"outDir": "build"
},
"include": ["./src/**/*"]
"include": ["./src/**/*"],
"references": [{"path": "../jest-util"}]
}
2 changes: 1 addition & 1 deletion packages/jest-circus/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-circus",
"version": "29.6.2",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/eventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type {Circus} from '@jest/types';
import {invariant} from 'jest-util';
import {
injectGlobalErrorHandlers,
restoreGlobalErrorHandlers,
Expand All @@ -15,7 +16,6 @@ import {
addErrorToEachTestUnderDescribe,
describeBlockHasTests,
getTestDuration,
invariant,
makeDescribe,
makeTest,
} from './utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {AsyncLocalStorage} from 'async_hooks';
import pLimit = require('p-limit');
import {jestExpect} from '@jest/expect';
import type {Circus} from '@jest/types';
import {invariant} from 'jest-util';
import shuffleArray, {RandomNumberGenerator, rngBuilder} from './shuffleArray';
import {dispatch, getState} from './state';
import {RETRY_TIMES} from './types';
Expand All @@ -17,7 +18,6 @@ import {
getAllHooksForDescribe,
getEachHooksForTest,
getTestID,
invariant,
makeRunResult,
} from './utils';

Expand Down
10 changes: 1 addition & 9 deletions packages/jest-circus/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ErrorWithStack,
convertDescriptorToString,
formatTime,
invariant,
isPromise,
} from 'jest-util';
import {format as prettyFormat} from 'pretty-format';
Expand Down Expand Up @@ -456,15 +457,6 @@ export const addErrorToEachTestUnderDescribe = (
}
};

export function invariant(
condition: unknown,
message?: string,
): asserts condition {
if (!condition) {
throw new Error(message);
}
}

type TestDescription = {
ancestorTitles: Array<string>;
fullName: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jest-cli",
"description": "Delightful JavaScript Testing.",
"version": "29.6.2",
"version": "29.6.3",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-config",
"version": "29.6.2",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jest/console",
"version": "29.6.2",
"version": "29.6.3",
"repository": {
"type": "git",
"url": "https://github.com/jestjs/jest.git",
Expand Down
Loading

0 comments on commit e0f991a

Please sign in to comment.