title: How to use a Global Variable in Jest
body: <p>I've got my Yarn <code>package.json</code> set up like this, where I create a global variable called <code>localPath</code>.</p>
  
  <pre><code>{
    "jest": {
      "globals": {
        "localPath": "Users/alex/Git/mytodolist"
      }
    }
  }
  </code></pre>
  
  <p>Then, in one of my spec tests, I run</p>
  
  <pre><code>console.log(localPath)
  </code></pre>
  
  <p>but get this error.</p>
  
  <pre><code>ReferenceError: localPath is not defined
  
        5 | 
      &gt; 6 |   console.log(localPath)
  </code></pre>
  
  <p>Does anyone know how to call the global variable you set up? I can only find articles on creating the variable, but not on how to call it.</p>
  
  <p>Source: <a href="https://jestjs.io/docs/en/configuration#globals-object" rel="nofollow noreferrer">https://jestjs.io/docs/en/configuration#globals-object</a></p>
  
  <p>Edit: Thanks to @slideshowp2 for the correct answer below. Turns out I didn't need to use a global variable in the end, as you can dynamically grab the execution path at run time. However, this will certainly be useful in the future.</p>
  
  <pre class="lang-js prettyprint-override"><code>beforeAll(async () =&gt; {
    await page.goto('file:///'+process.cwd()+'/index.html')
  })
  </code></pre>