From 2c445fb00cb5106341cfc1f8abea98f6e513d114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Nh=E1=BA=ADt=20Ho=C3=A0ng?= Date: Mon, 3 Dec 2018 21:40:44 +0700 Subject: [PATCH 1/5] Update Configuration.md --- docs/Configuration.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/Configuration.md b/docs/Configuration.md index 8cc5493f7864..f9fa21caef49 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -333,6 +333,24 @@ 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. +The global variables that are configured through `global` object can be read only in `globalTeardown`. + +```js +// setup.js +module.exports = async () => { + ... + // Set reference to mongod in order to close the server during teardown. + global.__MONGOD__ = mongod; +}; +``` + +```js +// teardown.js +module.exports = async function() { + await global.__MONGOD__.stop(); +}; +``` + ### `globalTeardown` [string] Default: `undefined` From f045327ef746910ad74da477bd13b6588bbc84eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Nh=E1=BA=ADt=20Ho=C3=A0ng?= Date: Mon, 3 Dec 2018 21:47:02 +0700 Subject: [PATCH 2/5] Update Configuration.md --- docs/Configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index f9fa21caef49..c45b104a8ad9 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -333,7 +333,7 @@ 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. -The global variables that are configured through `global` object can be read only in `globalTeardown`. +The global variables that are configured through `global` object can be read in `globalTeardown` only. ```js // setup.js From 460290a931c8a85fabea17dd9337ed98ae5c1ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Nh=E1=BA=ADt=20Ho=C3=A0ng?= Date: Mon, 17 Dec 2018 14:02:55 +0700 Subject: [PATCH 3/5] Update Configuration.md --- docs/Configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index c45b104a8ad9..820b1caa5043 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -333,7 +333,7 @@ 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. -The global variables that are configured through `global` object can be read in `globalTeardown` only. +The global variables that are configured through `global` object can be read in `globalTeardown` only, you cannot get `global` in your test suites: ```js // setup.js From 62d8722e8102db1d562801cec361d2a11dbcceb0 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 17 Dec 2018 09:52:31 +0100 Subject: [PATCH 4/5] Update Configuration.md --- docs/Configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 820b1caa5043..a241545b1cfc 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -338,7 +338,7 @@ The global variables that are configured through `global` object can be read in ```js // setup.js module.exports = async () => { - ... + // ... // Set reference to mongod in order to close the server during teardown. global.__MONGOD__ = mongod; }; From 87ed8616d6b0fb132878693a8cb943a744cdf934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 17 Dec 2018 16:05:35 +0700 Subject: [PATCH 5/5] Update Configuration.md Co-Authored-By: codeaholicguy --- docs/Configuration.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index a241545b1cfc..f13e55bcdf11 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -333,7 +333,9 @@ 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. -The global variables that are configured through `global` object can be read in `globalTeardown` only, you cannot get `global` in your test suites: +_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._ + +Example: ```js // setup.js