title: How do I save a value in global in Jest during test setup?
body: <p>I have a global setup in Jest.</p>
  
  <pre class="lang-json prettyprint-override"><code>"jest": {
      "globalSetup": "./setup.js"
    }
  </code></pre>
  
  <p>Within the setup, I have an async function which writes a session key to global</p>
  
  <pre class="lang-js prettyprint-override"><code>const axios = require('axios');
  
  async function getSessionKey() {
      const response = await axios.post("http://apiUrl", {
          username: "K",
          password: "passw0rd"
      });
      sessionKey = response.data.sessionKey;
      global.sessionKey = sessionKey;
  }
  
  module.exports = getSessionKey;
  </code></pre>
  
  <p>Whatever session key I am saving in global is not available in the test file. global.sessionKey is undefined in the below test.</p>
  
  <pre class="lang-js prettyprint-override"><code>test("create session", () =&gt; {
      expect(global.sessionKey).toBeTruthy();
  });
  </code></pre>
  
  <p>I want some way to set the sessionKey in a global object from setup file. The session key should be available before I run any of my tests.</p>