title: How to use ES6 in a custom Jest Node Environment?
body: <p>So far I can use perfectly ES6 syntax in my tests files, but when I try to set up a custom <code>jest-enviroment</code> I'm unable to use that syntax there. And then unable to test anything.</p>
  <p>My custom jest-node-enviroment looks like:</p>
  <pre class="lang-js prettyprint-override"><code>
  const Crawler = require('../../src/parser/crawler/Crawler.js');
  
  
  const NodeEnvironment = require(&quot;jest-environment-node&quot;)
  module.exports = class Environment extends NodeEnvironment {
    async setup() {
  
      await super.setup()
  
      if (!this.global.crawler) {
        this.global.crawler = Crawler;
        await super.setup()
      }
    }
  
    async teardown() {
      await super.teardown()
    }
  
    runScript(script) {
      return super.runScript(script)
    }
  }
  
  
  </code></pre>
  <p>And then when I run the test:</p>
  <pre class="lang-sh prettyprint-override"><code>
  pkg ▶ yarn test
  yarn run v1.22.10
  $ jest
  Determining test suites to run...Setting Up Test ENV
   FAIL  test/crawler/crawler.test.js
    ● Test suite failed to run
  
      /the/path/to/the/pkg/src/parser/crawler/Crawler.js:1
      import puppeteer from 'puppeteer-core'
      ^^^^^^
  
      SyntaxError: Cannot use import statement outside a module
  
        1 | 
      &gt; 2 | const Crawler = require('../../src/parser/crawler/Crawler.js');
          |                 ^
        3 | 
        4 | 
        5 | const NodeEnvironment = require(&quot;jest-environment-node&quot;)
  
        at Object.&lt;anonymous&gt; (test/config/environment.js:2:17)
  
  Test Suites: 1 failed, 1 total
  Tests:       0 total
  Snapshots:   0 total
  Time:        0.039 s
  Ran all test suites.
  Teardown Crawler
  
  
  </code></pre>
  <p>I'm using ES6 in all my code since I have set up a <code>@babel-register</code> at booting time.
  And I would like to keep it that way.</p>
  <p>The <code>jest.config.js</code> looks like:</p>
  <pre class="lang-js prettyprint-override"><code>{
  ...
  globalSetup: &quot;./test/config/setup.js&quot;,
  globalTeardown: &quot;./test/config/teardown.js&quot;,
  testEnvironment: &quot;./test/config/environment&quot;,
  transform: {
     &quot;^.+\\.jsx?$&quot;: &quot;babel-jest&quot;
    }
  }
  </code></pre>
  <p>I have dug in the docs from Babel, Jest , and a lot of &quot;solutions to this&quot; here and on the internet but everyone talks the same, nobody talks about how to use it in a custom environment.</p>