Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added explanation on how to use custom @jest-environment to docs #10783

Merged
merged 1 commit into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -1060,6 +1068,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-22.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,14 @@ 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 `runScript` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -787,6 +795,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-23.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,14 @@ 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 `runScript` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -813,6 +821,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-24.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,14 @@ The class may optionally expose a `handleTestEvent` method to bind to events fir

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -954,6 +962,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-25.x/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -978,6 +986,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-26.0/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -978,6 +986,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-26.2/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -992,6 +1000,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-26.4/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -1023,6 +1031,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-26.5/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -1041,6 +1049,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down
11 changes: 11 additions & 0 deletions website/versioned_docs/version-26.6/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind

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.

To use this class as your custom environment, refer to it by its full path within the project. For example, if your class is stored in `my-custom-environment.js` in some subfolder of your project, then the annotation might looke like this:

```js
/**
* @jest-environment ./src/test/my-custom-environment
*/
```

_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._

Example:
Expand Down Expand Up @@ -1061,6 +1069,9 @@ module.exports = CustomEnvironment;

```js
// my-test-suite
/**
* @jest-environment ./my-custom-environment
*/
let someGlobalObject;

beforeAll(() => {
Expand Down