title: How to use ESM tests with jest?
body: <p><strong>My setup</strong></p>
  <ul>
  <li>Node v14.16.0</li>
  <li>I have one test file that contains a simple test written with ESM modules (<code>import</code>).</li>
  <li>In <code>package.json</code> I have a script (following <a href="https://jestjs.io/docs/ecmascript-modules" rel="noreferrer">Jest documentation</a> adapted to Windows): <code>&quot;test&quot;: &quot;set \&quot;NODE_OPTIONS=--experimental-vm-modules\&quot; &amp;&amp; npx jest&quot;</code></li>
  <li>My tests are run w/ <code>npm run test</code> (the script above)</li>
  </ul>
  <p><strong>My goal:</strong> Run the ESM tests using jest.</p>
  <p><strong>My attempts:</strong></p>
  <h2>(1) CommonJS App w/ .js test</h2>
  <ul>
  <li><code>package.json</code> contains <code>&quot;type&quot;: &quot;commonjs&quot;</code></li>
  <li>Test file named <code>test.js</code></li>
  <li>Error: <code>SyntaxError: Cannot use import statement outside a module</code> (This is expected because the test is being run as a commonjs file.)</li>
  </ul>
  <h2>(2) CommonJS App w/ .mjs test</h2>
  <ul>
  <li><code>package.json</code> contains <code>&quot;type&quot;: &quot;commonjs&quot;</code></li>
  <li>Test file named <code>test.mjs</code></li>
  <li>Error: <code>No tests found</code> (Jest isn't finding the file?)</li>
  </ul>
  <h2>(3) ESM App w/ .js or .mjs</h2>
  <ul>
  <li><code>package.json</code> now has <code>&quot;type&quot;: &quot;module&quot;</code></li>
  <li>Test file named <code>test.mjs</code> or <code>test.js</code></li>
  <li>Error: <code>ReferenceError: module is not defined at ...jest.config.js:6:1</code></li>
  </ul>
  <h2>(4) CommonJS App and CommonJS test</h2>
  <ul>
  <li><code>package.json</code> contains <code>&quot;type&quot;: &quot;commonjs&quot;</code></li>
  <li>Test file named <code>test.js</code> but using the commonjs <code>require</code> syntax (and without the ESM modules I'd like to include); Note that <strong>this is not what I want</strong>, but included just to show there's nothing wrong with the test itself.</li>
  <li>Test runs fine and passes</li>
  </ul>