Skip to content

Commit

Permalink
Merge branch 'main' into v8-coverage-perf
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Sep 30, 2022
2 parents f7996e7 + 3c31dd6 commit 7ca3578
Show file tree
Hide file tree
Showing 54 changed files with 218 additions and 151 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Expand Up @@ -333,7 +333,7 @@ module.exports = {
parserOptions: {
sourceType: 'module',
},
plugins: ['import'],
plugins: ['import', 'jsdoc'],
rules: {
'accessor-pairs': ['warn', {setWithoutGet: true}],
'block-scoped-var': 'off',
Expand Down Expand Up @@ -390,6 +390,7 @@ module.exports = {
},
],
'init-declarations': 'off',
'jsdoc/check-alignment': 'error',
'lines-around-comment': 'off',
'max-depth': 'off',
'max-nested-callbacks': 'off',
Expand Down
11 changes: 9 additions & 2 deletions CHANGELOG.md
Expand Up @@ -10,17 +10,24 @@

- `[jest-runner]` Do not instrument v8 coverage data if coverage should not be collected [#13282](https://github.com/facebook/jest/pull/13282)

## 29.1.2

### Fixes

- `[expect, @jest/expect]` Revert buggy inference of argument types for `*CalledWith` and `*ReturnedWith` matchers introduced in 29.1.0 ([#13339](https://github.com/facebook/jest/pull/13339))
- `[jest-worker]` Add missing dependency on `jest-util` ([#13341](https://github.com/facebook/jest/pull/13341))

## 29.1.1

### Fixes

- `[jest-mock]` Revert ([#13145](https://github.com/facebook/jest/pull/13145))
- `[jest-mock]` Revert [#13145](https://github.com/facebook/jest/pull/13145) which broke mocking of transpiled ES modules

## 29.1.0

### Features

- `[expect, @jest/expect]` support type inference for function parameters in `CalledWith` assertions ([#13268](https://github.com/facebook/jest/pull/13268))
- `[expect, @jest/expect]` Support type inference for function parameters in `CalledWith` assertions ([#13268](https://github.com/facebook/jest/pull/13268))
- `[expect, @jest/expect]` Infer type of `*ReturnedWith` matchers argument ([#13278](https://github.com/facebook/jest/pull/13278))
- `[@jest/environment, jest-runtime]` Allow `jest.requireActual` and `jest.requireMock` to take a type argument ([#13253](https://github.com/facebook/jest/pull/13253))
- `[@jest/environment]` Allow `jest.mock` and `jest.doMock` to take a type argument ([#13254](https://github.com/facebook/jest/pull/13254))
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -8,5 +8,5 @@
"syncWorkspaceLock": true
}
},
"version": "29.1.1"
"version": "29.1.2"
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -38,6 +38,7 @@
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-jest": "^26.1.0",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-local": "^1.0.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-prettier": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/package.json
@@ -1,7 +1,7 @@
{
"name": "babel-jest",
"description": "Jest plugin to use babel for transformation.",
"version": "29.1.0",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/expect-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@jest/expect-utils",
"version": "29.1.0",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
3 changes: 1 addition & 2 deletions packages/expect/__typetests__/expect.test.ts
Expand Up @@ -16,8 +16,7 @@ import {
} from 'expect';
import type * as jestMatcherUtils from 'jest-matcher-utils';

type M = Matchers<void, unknown>;
type N = Matchers<void>;
type M = Matchers<void>;

expectError(() => {
type E = Matchers;
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/package.json
@@ -1,6 +1,6 @@
{
"name": "expect",
"version": "29.1.0",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
46 changes: 19 additions & 27 deletions packages/expect/src/types.ts
Expand Up @@ -94,9 +94,9 @@ export interface BaseExpect {
}

export type Expect = {
<T = unknown>(actual: T): Matchers<void, T> &
Inverse<Matchers<void, T>> &
PromiseMatchers<T>;
<T = unknown>(actual: T): Matchers<void> &
Inverse<Matchers<void>> &
PromiseMatchers;
} & BaseExpect &
AsymmetricMatchers &
Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;
Expand All @@ -118,38 +118,36 @@ export interface AsymmetricMatchers {
stringMatching(sample: string | RegExp): AsymmetricMatcher;
}

type PromiseMatchers<T = unknown> = {
type PromiseMatchers = {
/**
* Unwraps the reason of a rejected promise so any other matcher can be chained.
* If the promise is fulfilled the assertion fails.
*/
rejects: Matchers<Promise<void>> & Inverse<Matchers<Promise<void>, T>>;
rejects: Matchers<Promise<void>> & Inverse<Matchers<Promise<void>>>;
/**
* Unwraps the value of a fulfilled promise so any other matcher can be chained.
* If the promise is rejected the assertion fails.
*/
resolves: Matchers<Promise<void>> & Inverse<Matchers<Promise<void>, T>>;
resolves: Matchers<Promise<void>> & Inverse<Matchers<Promise<void>>>;
};

type EnsureFunctionLike<T> = T extends (...args: any) => any ? T : never;

export interface Matchers<R extends void | Promise<void>, T = unknown> {
export interface Matchers<R extends void | Promise<void>> {
/**
* Ensures the last call to a mock function was provided specific args.
*/
lastCalledWith(...expected: Parameters<EnsureFunctionLike<T>>): R;
lastCalledWith(...expected: Array<unknown>): R;
/**
* Ensure that the last call to a mock function has returned a specified value.
*/
lastReturnedWith(expected: ReturnType<EnsureFunctionLike<T>>): R;
lastReturnedWith(expected: unknown): R;
/**
* Ensure that a mock function is called with specific arguments on an Nth call.
*/
nthCalledWith(nth: number, ...expected: Parameters<EnsureFunctionLike<T>>): R;
nthCalledWith(nth: number, ...expected: Array<unknown>): R;
/**
* Ensure that the nth call to a mock function has returned a specified value.
*/
nthReturnedWith(nth: number, expected: ReturnType<EnsureFunctionLike<T>>): R;
nthReturnedWith(nth: number, expected: unknown): R;
/**
* Checks that a value is what you expect. It calls `Object.is` to compare values.
* Don't use `toBe` with floating-point numbers.
Expand All @@ -166,7 +164,7 @@ export interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Ensure that a mock function is called with specific arguments.
*/
toBeCalledWith(...expected: Parameters<EnsureFunctionLike<T>>): R;
toBeCalledWith(...expected: Array<unknown>): R;
/**
* Using exact equality with floating point numbers is a bad idea.
* Rounding means that intuitive things fail.
Expand Down Expand Up @@ -249,25 +247,22 @@ export interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Ensure that a mock function is called with specific arguments.
*/
toHaveBeenCalledWith(...expected: Parameters<EnsureFunctionLike<T>>): R;
toHaveBeenCalledWith(...expected: Array<unknown>): R;
/**
* Ensure that a mock function is called with specific arguments on an Nth call.
*/
toHaveBeenNthCalledWith(
nth: number,
...expected: Parameters<EnsureFunctionLike<T>>
): R;
toHaveBeenNthCalledWith(nth: number, ...expected: Array<unknown>): R;
/**
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
* to test what arguments it was last called with.
*/
toHaveBeenLastCalledWith(...expected: Parameters<EnsureFunctionLike<T>>): R;
toHaveBeenLastCalledWith(...expected: Array<unknown>): R;
/**
* Use to test the specific value that a mock function last returned.
* If the last call to the mock function threw an error, then this matcher will fail
* no matter what value you provided as the expected return value.
*/
toHaveLastReturnedWith(expected: ReturnType<EnsureFunctionLike<T>>): R;
toHaveLastReturnedWith(expected: unknown): R;
/**
* Used to check that an object has a `.length` property
* and it is set to a certain numeric value.
Expand All @@ -278,10 +273,7 @@ export interface Matchers<R extends void | Promise<void>, T = unknown> {
* If the nth call to the mock function threw an error, then this matcher will fail
* no matter what value you provided as the expected return value.
*/
toHaveNthReturnedWith(
nth: number,
expected: ReturnType<EnsureFunctionLike<T>>,
): R;
toHaveNthReturnedWith(nth: number, expected: unknown): R;
/**
* Use to check if property at provided reference keyPath exists for an object.
* For checking deeply nested properties in an object you may use dot notation or an array containing
Expand Down Expand Up @@ -311,7 +303,7 @@ export interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Use to ensure that a mock function returned a specific value.
*/
toHaveReturnedWith(expected: ReturnType<EnsureFunctionLike<T>>): R;
toHaveReturnedWith(expected: unknown): R;
/**
* Check that a string matches a regular expression.
*/
Expand All @@ -333,7 +325,7 @@ export interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Ensure that a mock function has returned a specified value at least once.
*/
toReturnWith(expected: ReturnType<EnsureFunctionLike<T>>): R;
toReturnWith(expected: unknown): R;
/**
* Use to test that objects have the same types as well as structure.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/package.json
@@ -1,6 +1,6 @@
{
"name": "jest-circus",
"version": "29.1.1",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/package.json
@@ -1,7 +1,7 @@
{
"name": "jest-cli",
"description": "Delightful JavaScript Testing.",
"version": "29.1.1",
"version": "29.1.2",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/package.json
@@ -1,6 +1,6 @@
{
"name": "jest-config",
"version": "29.1.1",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-console/package.json
@@ -1,6 +1,6 @@
{
"name": "@jest/console",
"version": "29.1.0",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/package.json
@@ -1,7 +1,7 @@
{
"name": "@jest/core",
"description": "Delightful JavaScript Testing.",
"version": "29.1.1",
"version": "29.1.2",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-create-cache-key-function/package.json
@@ -1,6 +1,6 @@
{
"name": "@jest/create-cache-key-function",
"version": "29.1.0",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-diff/package.json
@@ -1,6 +1,6 @@
{
"name": "jest-diff",
"version": "29.1.0",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/package.json
@@ -1,6 +1,6 @@
{
"name": "jest-each",
"version": "29.1.0",
"version": "29.1.2",
"description": "Parameterised tests for Jest",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-jsdom/package.json
@@ -1,6 +1,6 @@
{
"name": "jest-environment-jsdom",
"version": "29.1.1",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment-node/package.json
@@ -1,6 +1,6 @@
{
"name": "jest-environment-node",
"version": "29.1.1",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment/package.json
@@ -1,6 +1,6 @@
{
"name": "@jest/environment",
"version": "29.1.1",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
42 changes: 21 additions & 21 deletions packages/jest-environment/src/index.ts
Expand Up @@ -184,27 +184,27 @@ export interface Jest {
options?: {virtual?: boolean},
): Jest;
/**
* Returns the actual module instead of a mock, bypassing all checks on
* whether the module should receive a mock implementation or not.
*
* @example
```js
jest.mock('../myModule', () => {
// Require the original module to not be mocked...
const originalModule = jest.requireActual('../myModule');
return {
__esModule: true, // Use it when dealing with esModules
...originalModule,
getRandom: jest.fn().mockReturnValue(10),
};
});
const getRandom = require('../myModule').getRandom;
getRandom(); // Always returns 10
```
*/
* Returns the actual module instead of a mock, bypassing all checks on
* whether the module should receive a mock implementation or not.
*
* @example
* ```js
* jest.mock('../myModule', () => {
* // Require the original module to not be mocked...
* const originalModule = jest.requireActual('../myModule');
*
* return {
* __esModule: true, // Use it when dealing with esModules
* ...originalModule,
* getRandom: jest.fn().mockReturnValue(10),
* };
* });
*
* const getRandom = require('../myModule').getRandom;
*
* getRandom(); // Always returns 10
* ```
*/
requireActual<T = unknown>(moduleName: string): T;
/**
* Wraps types of the `source` object and its deep members with type definitions
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-expect/package.json
@@ -1,6 +1,6 @@
{
"name": "@jest/expect",
"version": "29.1.0",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-expect/src/types.ts
Expand Up @@ -29,7 +29,7 @@ type Inverse<Matchers> = {
not: Matchers;
};

type JestMatchers<R extends void | Promise<void>, T> = Matchers<R, T> &
type JestMatchers<R extends void | Promise<void>, T> = Matchers<R> &
SnapshotMatchers<R, T>;

type PromiseMatchers<T = unknown> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-fake-timers/package.json
@@ -1,6 +1,6 @@
{
"name": "@jest/fake-timers",
"version": "29.1.1",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-globals/package.json
@@ -1,6 +1,6 @@
{
"name": "@jest/globals",
"version": "29.1.1",
"version": "29.1.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git",
Expand Down

0 comments on commit 7ca3578

Please sign in to comment.