Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/facebook/jest into docs-tra…
Browse files Browse the repository at this point in the history
…nsform-ignore-patterns

* 'main' of https://github.com/facebook/jest: (38 commits)
  chore: update `npm` instructions in README (jestjs#11890)
  chore: force patched version of ansi-regex (jestjs#11889)
  chore: update lockfile after publish
  v27.2.1
  chore: update changelog for release
  make the syntax error message more helpful for TS users (jestjs#11807)
  fix: include path to test file in "after teardown" error (jestjs#11885)
  docs: add link to the typescript integration instructions (jestjs#11806)
  fix: properly return mocks when using jest.isolatedModules (jestjs#11882)
  chore: remove node version pinning from CI (jestjs#11866)
  chore: remove node 13 as condition in some tests (jestjs#11880)
  chore: fix typo in docs
  chore: update lockfile after publish
  v27.2.0
  chore: roll new website version
  chore: update changelog for release
  chore: update lock
  feat: support `conditions` from test environments (jestjs#11863)
  Revert "chore: remove unneeded yarn patch for react native (jestjs#11853)"
  chore: supress experimental warnings in tests
  ...
  • Loading branch information
AndrewSouthpaw committed Sep 23, 2021
2 parents fc3efc7 + da7c4a4 commit e001d80
Show file tree
Hide file tree
Showing 249 changed files with 13,672 additions and 3,401 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -12,7 +12,7 @@ aliases:
app-dir: ~/jest

orbs:
node: circleci/node@4.0.0
node: circleci/node@4.7.0

jobs:
test-node:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Expand Up @@ -3,7 +3,7 @@ name: Node CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- '**'
Expand All @@ -15,7 +15,7 @@ jobs:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'"

prepare-yarn-cache:
name: Prepare yarn cache
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -41,8 +41,9 @@ package-lock.json

*.tsbuildinfo

# https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored but nested for e2e directories
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored but nested for e2e directories
**/.yarn/*
!**/.yarn/patches
!**/.yarn/releases
!**/.yarn/plugins
!**/.yarn/sdks
Expand Down
10 changes: 5 additions & 5 deletions .yarn/releases/yarn-2.4.2.cjs → .yarn/releases/yarn-2.4.3.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Expand Up @@ -8,4 +8,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-2.4.2.cjs
yarnPath: .yarn/releases/yarn-2.4.3.cjs
45 changes: 40 additions & 5 deletions CHANGELOG.md
@@ -1,4 +1,4 @@
## master
## main

### Features

Expand All @@ -8,6 +8,41 @@

### Performance

## 27.2.1

### Features

- `[jest-transform]` Improve the unexpected token error message. ([#11807](https://github.com/facebook/jest/pull/11807))

### Fixes

- `[jest-runtime]` Fix regression when using `jest.isolateModules` and mocks ([#11882](https://github.com/facebook/jest/pull/11882))
- `[jest-runtime]` Include test name when importing modules after test has completed ([#11885](https://github.com/facebook/jest/pull/11885))
- `[jest-runtime]` Error when ESM import is used after test is torn down ([#11885](https://github.com/facebook/jest/pull/11885))

## 27.2.0

### Features

- `[jest-resolver, jest-runtime]` Pass `conditions` to custom resolvers to enable them to implement support for package.json `exports` field ([#11859](https://github.com/facebook/jest/pull/11859))
- `[jest-runtime]` Allow custom envs to specify `exportConditions` which is passed together with Jest's own conditions to custom resolvers ([#11863](https://github.com/facebook/jest/pull/11863))

### Fixes

- `[@jest/reporters]` Use async transform if available to transform files with no coverage ([#11852](https://github.com/facebook/jest/pull/11852))
- `[jest-util]` Return correct value from `process.send` stub ([#11799](https://github.com/facebook/jest/pull/11799))

## 27.1.1

### Features

- `[jest-runtime]` Add experimental, limited (and undocumented) support for mocking ECMAScript Modules ([#11818](https://github.com/facebook/jest/pull/11818))

### Fixes

- `[jest-resolver]` Support `node:` prefix when importing Node core modules with ESM ([#11817](https://github.com/facebook/jest/pull/11817))
- `[jest-types]` Export the `PrettyFormatOptions` interface ([#11801](https://github.com/facebook/jest/pull/11801))

## 27.1.0

### Features
Expand Down Expand Up @@ -2125,7 +2160,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0
- Fix inconsistent name of complex values in pretty-format ([#4001](https://github.com/facebook/jest/pull/4001))
- Fix issue mocking bound method ([#3805](https://github.com/facebook/jest/pull/3805))
- Fix jest-circus ([#4290](https://github.com/facebook/jest/pull/4290))
- Fix lint warning in master
- Fix lint warning in main

([#4132](https://github.com/facebook/jest/pull/4132))

Expand Down Expand Up @@ -2227,7 +2262,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0
- Support maxDepth option in React plugins ([#4208](https://github.com/facebook/jest/pull/4208))
- Support SVG elements in HTMLElement plugin ([#4335](https://github.com/facebook/jest/pull/4335))
- Test empty Immutable collections with {min: false} option ([#4121](https://github.com/facebook/jest/pull/4121))
- test to debug travis failure in master ([#4145](https://github.com/facebook/jest/pull/4145))
- test to debug travis failure in main ([#4145](https://github.com/facebook/jest/pull/4145))
- testPathPattern message test ([#4006](https://github.com/facebook/jest/pull/4006))
- Throw Error When Using Nested It Specs ([#4039](https://github.com/facebook/jest/pull/4039))
- Throw when moduleNameMapper points to inexistent module ([#3567](https://github.com/facebook/jest/pull/3567))
Expand Down Expand Up @@ -2417,7 +2452,7 @@ See https://jestjs.io/blog/2016/12/15/2016-in-jest
- Renamed `--jsonOutputFile` to `--outputFile`.
- Added `jest-editor-support` for vscode and Nuclide integration.
- Fixed `test.concurrent` unhandled promise rejections.
- The Jest website is now auto-deployed when merging into master.
- The Jest website is now auto-deployed when merging into main.
- Updated `testRegex` to include `test.js` and `spec.js` files.
- Fixes for `babel-plugin-jest-hoist` when using `jest.mock` with three arguments.
- The `JSON` global in `jest-environment-node` now comes from the vm context instead of the parent context.
Expand Down Expand Up @@ -2738,7 +2773,7 @@ See https://jestjs.io/blog/2016/12/15/2016-in-jest
- Fixed a memory leak with test contexts. Jest now properly cleans up test environments after each test. Added `--logHeapUsage` to log memory usage after each test. Note: this is option is meant for debugging memory leaks and might significantly slow down your test run.
- Removed `mock-modules`, `node-haste` and `mocks` virtual modules. This is a breaking change of undocumented public API. Usage of this API can safely be automatically updated through an automated codemod:
- Example: http://astexplorer.net/#/zrybZ6UvRA
- Codemod: https://github.com/cpojer/js-codemod/blob/master/transforms/jest-update.js
- Codemod: https://github.com/cpojer/js-codemod/blob/main/transforms/jest-update.js
- jscodeshift: https://github.com/facebook/jscodeshift
- Removed `navigator.onLine` and `mockSetReadOnlyProperty` from the global jsdom environment. Use `window.navigator.onLine = true;` in your test setup and `Object.defineProperty` instead.

Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -10,17 +10,17 @@ Facebook has adopted a Code of Conduct that we expect project participants to ad

All work on Jest happens directly on [GitHub](/). Both core team members and external contributors send pull requests which go through the same review process.

### `master` is unsafe
### `main` is unsafe

We will do our best to keep `master` in good shape, with tests passing at all times. But in order to move fast, we will make API changes that your application might not be compatible with. We will do our best to communicate these changes and always version appropriately so you can lock into a specific version if need be.
We will do our best to keep `main` in good shape, with tests passing at all times. But in order to move fast, we will make API changes that your application might not be compatible with. We will do our best to communicate these changes and always version appropriately so you can lock into a specific version if need be.

### Workflow and Pull Requests

The core team will be monitoring for pull requests. When we get one, we'll run some Facebook-specific integration tests on it first. From here, we'll need to get another person to sign off on the changes and then merge the pull request. For API changes we may need to fix internal uses, which could cause some delay. We'll do our best to provide updates and feedback throughout the process.

_Before_ submitting a pull request, please make sure the following is done…

1. Fork the repo and create your branch from `master`. A guide on how to fork a repository: https://help.github.com/articles/fork-a-repo/
1. Fork the repo and create your branch from `main`. A guide on how to fork a repository: https://help.github.com/articles/fork-a-repo/

Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type:

Expand Down
4 changes: 2 additions & 2 deletions README.md
@@ -1,6 +1,6 @@
<p align="center">
<a href="http://badge.fury.io/js/jest"><img src="https://badge.fury.io/js/jest.svg" alt="npm version"></a>
<a href="https://github.com/facebook/jest/blob/master/LICENSE">
<a href="https://github.com/facebook/jest/blob/main/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Jest is released under the MIT license." />
</a>
<a href="https://twitter.com/intent/follow?screen_name=fbjest"><img align="center" src="https://img.shields.io/twitter/follow/fbjest.svg?style=social&label=Follow%20@fbjest" alt="Follow on Twitter"></a>
Expand Down Expand Up @@ -89,7 +89,7 @@ Add the following section to your `package.json`:
}
```

Finally, run `yarn test` or `npm run test` and Jest will print this message:
Finally, run `yarn test` or `npm test` and Jest will print this message:

```bash
PASS ./sum.test.js
Expand Down
18 changes: 11 additions & 7 deletions docs/Configuration.md
Expand Up @@ -234,7 +234,7 @@ _Note: You can pass additional options to the istanbul reporter using the tuple
["json", ["lcov", {"projectRoot": "../../"}]]
```

For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts).
For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Config.ts).

### `coverageThreshold` \[object]

Expand Down Expand Up @@ -765,7 +765,7 @@ class MyCustomReporter {
}
```

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

### `resetMocks` \[boolean]

Expand All @@ -788,11 +788,13 @@ This option allows the use of a custom resolver. This resolver must be a node mo
```json
{
"basedir": string,
"conditions": [string],
"defaultResolver": "function(request, options)",
"extensions": [string],
"moduleDirectory": [string],
"paths": [string],
"packageFilter": "function(pkg, pkgdir)",
"pathFilter": "function(pkg, path, relativePath)",
"rootDir": [string]
}
```
Expand Down Expand Up @@ -849,6 +851,8 @@ module.exports = (request, options) => {
};
```

While Jest does not support [package `exports`](https://nodejs.org/api/packages.html#packages_package_entry_points) (beyond `main`), Jest will provide `conditions` as an option when calling custom resolvers, which can be used to implement support for `exports` in userland. Jest will pass `['import', 'default']` when running a test in ESM mode, and `['require', 'default']` when running with CJS. Additionally, custom test environments can specify an `exportConditions` method which returns an array of conditions that will be passed along with Jest's defaults.

### `restoreMocks` \[boolean]

Default: `false`
Expand Down Expand Up @@ -1067,7 +1071,7 @@ Pretty foo: Object {

To make a dependency explicit instead of implicit, you can call [`expect.addSnapshotSerializer`](ExpectAPI.md#expectaddsnapshotserializerserializer) to add a module for an individual test file instead of adding its path to `snapshotSerializers` in Jest configuration.

More about serializers API can be found [here](https://github.com/facebook/jest/tree/master/packages/pretty-format/README.md#serialize).
More about serializers API can be found [here](https://github.com/facebook/jest/tree/main/packages/pretty-format/README.md#serialize).

### `testEnvironment` \[string]

Expand All @@ -1090,7 +1094,7 @@ test('use jsdom in this test file', () => {

You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `getVmContext` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object &ndash; this will make them available in your test suites as global variables.

The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases.
The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/main/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases.

Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with its value set to an empty string. If the pragma is not present, it will not be present in the object.

Expand Down Expand Up @@ -1285,7 +1289,7 @@ function testRunner(
): Promise<TestResult>;
```

An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.ts).
An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/main/packages/jest-jasmine2/src/index.ts).

### `testSequencer` \[string]

Expand Down Expand Up @@ -1345,7 +1349,7 @@ If the value is `legacy`, the old implementation will be used as implementation

Default: `{"\\.[jt]sx?$": "babel-jest"}`

A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/master/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md).
A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/main/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md).

Examples of such compilers include:

Expand All @@ -1357,7 +1361,7 @@ You can pass configuration to a transformer like `{filePattern: ['path-to-transf

_Note: a transformer is only run once per file unless the file has changed. During the development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._

_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_
_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/main/packages/babel-jest#setup)_

A transformer must be an object with at least a `process` function, and it's also recommended to include a `getCacheKey` function. If your transformer is written in ESM you should have a default export with that object.

Expand Down
2 changes: 1 addition & 1 deletion docs/ExpectAPI.md
Expand Up @@ -151,7 +151,7 @@ A boolean to let you know this matcher was called with an `expand` option. When

#### `this.utils`

There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils).
There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/main/packages/jest-matcher-utils).

The most useful ones are `matcherHint`, `printExpected` and `printReceived` to format the error messages nicely. For example, take a look at the implementation for the `toBe` matcher:

Expand Down
2 changes: 1 addition & 1 deletion docs/JestObjectAPI.md
Expand Up @@ -672,7 +672,7 @@ jest.setTimeout(1000); // 1 second

### `jest.retryTimes()`

Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus) runner!
Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner!

Example in a test:

Expand Down
10 changes: 5 additions & 5 deletions docs/JestPlatform.md
Expand Up @@ -23,7 +23,7 @@ getChangedFilesForRoots(['./'], {
}).then(result => console.log(result.changedFiles));
```

You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-changed-files/README.md).
You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-changed-files/README.md).

## jest-diff

Expand Down Expand Up @@ -68,7 +68,7 @@ const parsed = parseWithComments(code);
console.log(parsed);
```

You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-docblock/README.md).
You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-docblock/README.md).

## jest-get-type

Expand Down Expand Up @@ -115,7 +115,7 @@ const result = validate(configByUser, {
console.log(result);
```

You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-validate/README.md).
You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-validate/README.md).

## jest-worker

Expand Down Expand Up @@ -151,7 +151,7 @@ async function main() {
main();
```

You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-worker/README.md).
You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-worker/README.md).

## pretty-format

Expand All @@ -171,4 +171,4 @@ val.array = [-0, Infinity, NaN];
console.log(prettyFormat(val));
```

You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/master/packages/pretty-format/README.md).
You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/main/packages/pretty-format/README.md).

0 comments on commit e001d80

Please sign in to comment.