Skip to content

Commit

Permalink
docs: clean up globalSetup / globalTeardown documentation (#12455)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Feb 22, 2022
1 parent 34308ae commit 356b3b0
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions docs/Configuration.md
Expand Up @@ -448,31 +448,29 @@ Note that, if you specify a global reference value (like an object or array) her

Default: `undefined`

This option allows the use of a custom global setup module which exports an async function that is triggered once before all test suites. This function gets Jest's `globalConfig` object as a parameter.
This option allows the use of a custom global setup module, which must export a function (it can be sync or async). The function will be triggered once before all test suites and it will receive two arguments: Jest's [`globalConfig`](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L282) and [`projectConfig`](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L347).

_Note: A global setup module configured in a project (using multi-project runner) will be triggered only when you run at least one test from this project._

_Note: Any global variables that are defined through `globalSetup` can only be read in `globalTeardown`. You cannot retrieve globals defined here in your test suites._

_Note: While code transformation is applied to the linked setup-file, Jest will **not** transform any code in `node_modules`. This is due to the need to load the actual transformers (e.g. `babel` or `typescript`) to perform transformation._

\_Note: User can access Jest [global config](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L282) and [project config](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L347) as arguments for the function.

Example:

```js title="setup.js"
// can be synchronous
module.exports = async (globalConfig, projectConfig) => {
// ...
// Can access and use Jest global config and project config
module.exports = async function (globalConfig, projectConfig) {
console.log(globalConfig.testPathPattern);
console.log(projectConfig.cache);

// Set reference to mongod in order to close the server during teardown.
globalThis.__MONGOD__ = mongod;
};
```

```js title="teardown.js"
module.exports = async function (globalConfig, projectConfig) {
// Can access and use Jest global config and project config
console.log(globalConfig.testPathPattern);
console.log(projectConfig.cache);

await globalThis.__MONGOD__.stop();
};
```
Expand All @@ -481,14 +479,12 @@ module.exports = async function (globalConfig, projectConfig) {

Default: `undefined`

This option allows the use of a custom global teardown module which exports an async function that is triggered once after all test suites. This function gets Jest's `globalConfig` object as a parameter.
This option allows the use of a custom global teardown module which must export a function (it can be sync or async). The function will be triggered once after all test suites and it will receive two arguments: Jest's [`globalConfig`](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L282) and [`projectConfig`](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L347).

_Note: A global teardown module configured in a project (using multi-project runner) will be triggered only when you run at least one test from this project._

_Note: The same caveat concerning transformation of `node_modules` as for `globalSetup` applies to `globalTeardown`._

\_Note: User can access Jest [global config](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L282) and [project config](https://github.com/facebook/jest/blob/main/packages/jest-types/src/Config.ts#L347) as arguments for the function.

### `haste` \[object]

Default: `undefined`
Expand Down

0 comments on commit 356b3b0

Please sign in to comment.