Skip to content

Commit 0168ce8

Browse files
authored
Added explanation on how to use custom @jest-environment to docs (#10783)
1 parent 2fa34c4 commit 0168ce8

File tree

10 files changed

+110
-0
lines changed

10 files changed

+110
-0
lines changed

docs/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind
10121012

10131013
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.
10141014

1015+
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:
1016+
1017+
```js
1018+
/**
1019+
* @jest-environment ./src/test/my-custom-environment
1020+
*/
1021+
```
1022+
10151023
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
10161024

10171025
Example:
@@ -1060,6 +1068,9 @@ module.exports = CustomEnvironment;
10601068

10611069
```js
10621070
// my-test-suite
1071+
/**
1072+
* @jest-environment ./my-custom-environment
1073+
*/
10631074
let someGlobalObject;
10641075

10651076
beforeAll(() => {

website/versioned_docs/version-22.x/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,14 @@ test('use jsdom in this test file', () => {
745745

746746
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.
747747

748+
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:
749+
750+
```js
751+
/**
752+
* @jest-environment ./src/test/my-custom-environment
753+
*/
754+
```
755+
748756
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
749757

750758
Example:
@@ -787,6 +795,9 @@ module.exports = CustomEnvironment;
787795

788796
```js
789797
// my-test-suite
798+
/**
799+
* @jest-environment ./my-custom-environment
800+
*/
790801
let someGlobalObject;
791802

792803
beforeAll(() => {

website/versioned_docs/version-23.x/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,14 @@ test('use jsdom in this test file', () => {
771771

772772
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.
773773

774+
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:
775+
776+
```js
777+
/**
778+
* @jest-environment ./src/test/my-custom-environment
779+
*/
780+
```
781+
774782
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
775783

776784
Example:
@@ -813,6 +821,9 @@ module.exports = CustomEnvironment;
813821

814822
```js
815823
// my-test-suite
824+
/**
825+
* @jest-environment ./my-custom-environment
826+
*/
816827
let someGlobalObject;
817828

818829
beforeAll(() => {

website/versioned_docs/version-24.x/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,14 @@ The class may optionally expose a `handleTestEvent` method to bind to events fir
906906

907907
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.
908908

909+
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:
910+
911+
```js
912+
/**
913+
* @jest-environment ./src/test/my-custom-environment
914+
*/
915+
```
916+
909917
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
910918

911919
Example:
@@ -954,6 +962,9 @@ module.exports = CustomEnvironment;
954962

955963
```js
956964
// my-test-suite
965+
/**
966+
* @jest-environment ./my-custom-environment
967+
*/
957968
let someGlobalObject;
958969

959970
beforeAll(() => {

website/versioned_docs/version-25.x/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind
930930

931931
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.
932932

933+
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:
934+
935+
```js
936+
/**
937+
* @jest-environment ./src/test/my-custom-environment
938+
*/
939+
```
940+
933941
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
934942

935943
Example:
@@ -978,6 +986,9 @@ module.exports = CustomEnvironment;
978986

979987
```js
980988
// my-test-suite
989+
/**
990+
* @jest-environment ./my-custom-environment
991+
*/
981992
let someGlobalObject;
982993

983994
beforeAll(() => {

website/versioned_docs/version-26.0/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind
930930

931931
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.
932932

933+
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:
934+
935+
```js
936+
/**
937+
* @jest-environment ./src/test/my-custom-environment
938+
*/
939+
```
940+
933941
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
934942

935943
Example:
@@ -978,6 +986,9 @@ module.exports = CustomEnvironment;
978986

979987
```js
980988
// my-test-suite
989+
/**
990+
* @jest-environment ./my-custom-environment
991+
*/
981992
let someGlobalObject;
982993

983994
beforeAll(() => {

website/versioned_docs/version-26.2/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind
944944

945945
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.
946946

947+
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:
948+
949+
```js
950+
/**
951+
* @jest-environment ./src/test/my-custom-environment
952+
*/
953+
```
954+
947955
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
948956

949957
Example:
@@ -992,6 +1000,9 @@ module.exports = CustomEnvironment;
9921000

9931001
```js
9941002
// my-test-suite
1003+
/**
1004+
* @jest-environment ./my-custom-environment
1005+
*/
9951006
let someGlobalObject;
9961007

9971008
beforeAll(() => {

website/versioned_docs/version-26.4/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind
975975

976976
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.
977977

978+
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:
979+
980+
```js
981+
/**
982+
* @jest-environment ./src/test/my-custom-environment
983+
*/
984+
```
985+
978986
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
979987

980988
Example:
@@ -1023,6 +1031,9 @@ module.exports = CustomEnvironment;
10231031

10241032
```js
10251033
// my-test-suite
1034+
/**
1035+
* @jest-environment ./my-custom-environment
1036+
*/
10261037
let someGlobalObject;
10271038

10281039
beforeAll(() => {

website/versioned_docs/version-26.5/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind
993993

994994
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.
995995

996+
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:
997+
998+
```js
999+
/**
1000+
* @jest-environment ./src/test/my-custom-environment
1001+
*/
1002+
```
1003+
9961004
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
9971005

9981006
Example:
@@ -1041,6 +1049,9 @@ module.exports = CustomEnvironment;
10411049

10421050
```js
10431051
// my-test-suite
1052+
/**
1053+
* @jest-environment ./my-custom-environment
1054+
*/
10441055
let someGlobalObject;
10451056

10461057
beforeAll(() => {

website/versioned_docs/version-26.6/Configuration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,14 @@ The class may optionally expose an asynchronous `handleTestEvent` method to bind
10131013

10141014
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.
10151015

1016+
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:
1017+
1018+
```js
1019+
/**
1020+
* @jest-environment ./src/test/my-custom-environment
1021+
*/
1022+
```
1023+
10161024
_Note: TestEnvironment is sandboxed. Each test suite will trigger setup/teardown in their own TestEnvironment._
10171025

10181026
Example:
@@ -1061,6 +1069,9 @@ module.exports = CustomEnvironment;
10611069

10621070
```js
10631071
// my-test-suite
1072+
/**
1073+
* @jest-environment ./my-custom-environment
1074+
*/
10641075
let someGlobalObject;
10651076

10661077
beforeAll(() => {

0 commit comments

Comments
 (0)