<p dir="auto"><strong>Context:</strong></p>
<ul dir="auto">
<li>Playwright Version: 1.27.0</li>
<li>Operating System: Mac</li>
<li>Node.js version: 16 LTS</li>
<li>Browser: All</li>
</ul>


<p dir="auto"><strong>Code Snippet</strong></p>
<p dir="auto">I couldn't get it working in CodeSandbox but please see the reproduction <a href="https://github.com/harry-gocity/playwright-import">here</a> (or try a <a href="https://codesandbox.io/s/github/harry-gocity/playwright-import" rel="nofollow">sandbox</a>)</p>
<ol dir="auto">
<li>run <code class="notranslate">npx playwright test</code>- the test should pass</li>
<li>uncomment <code class="notranslate">import {testData} from '../mockData'</code> in the <code class="notranslate">repro.test.ts</code> file</li>
<li>run the test again</li>
</ol>
<p dir="auto"><strong>Describe the bug</strong></p>
<p dir="auto">The test will fail on the second run with an error, event though the import that is causing the error in <code class="notranslate">mockData.ts</code> is not used by the playwright test itself. This also appears when our <code class="notranslate">mockData.ts</code> file imports types from other files, and in going to those files playwright evaluates module level js that would not normally be run (e.g. outside of NextJs runtime). We don't see this behaviour with jest when running unit tests.</p>
<p dir="auto">We have a general mock data file that is used across our unit/integration/e2e tests, which contains info such as dummy card details, mock redux state, pretend user details etc. Importing anything from this file in our playwright tests seems to result in playwright evaluating every single import in that file rather than just using what it needs.</p>
<p dir="auto">There is a similar issue here (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1413379382" data-permission-text="Title is private" data-url="https://github.com/microsoft/playwright/issues/18150" data-hovercard-type="issue" data-hovercard-url="/microsoft/playwright/issues/18150/hovercard" href="https://github.com/microsoft/playwright/issues/18150">#18150</a>) which relates to using experimental components and not being able to import anything other than components. We aren't using component testing, and either way I would consider the <code class="notranslate">mockData</code> file to essentially be our helper in that scenario.</p>
<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: v1.31.2</li>
<li>Operating System: macos 13.2.1</li>
<li>Browser: Chrome</li>
<li>Other info:</li>
</ul>
<h3 dir="auto">Source code</h3>
<p dir="auto"><strong>Test file (self-contained)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const { chromium } = require(&quot;playwright-core&quot;);

(async () =&gt; {
  const browser = await chromium.connectOverCDP(`http://localhost:12345`);
  const contexts = browser.contexts();
  // BUG: I expect more than 1 if I have more than 1 chrome profiles open
  console.log(`contexts`, contexts.length);
})();"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span> chromium <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"playwright-core"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-kos">(</span><span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-k">const</span> <span class="pl-s1">browser</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">chromium</span><span class="pl-kos">.</span><span class="pl-en">connectOverCDP</span><span class="pl-kos">(</span><span class="pl-s">`http://localhost:12345`</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">const</span> <span class="pl-s1">contexts</span> <span class="pl-c1">=</span> <span class="pl-s1">browser</span><span class="pl-kos">.</span><span class="pl-en">contexts</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-c">// BUG: I expect more than 1 if I have more than 1 chrome profiles open</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`contexts`</span><span class="pl-kos">,</span> <span class="pl-s1">contexts</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I provided exact source code that allows reproducing the issue locally.</li>
</ul>
<p dir="auto"><strong>Steps</strong></p>
<ul dir="auto">
<li>Ensure that your chrome is launched with CDP port enabled at 12345</li>
<li>There are more than 1 chrome profiles open</li>
<li>Run the code above</li>
</ul>
<p dir="auto"><strong>Expected</strong></p>
<ul dir="auto">
<li>Log should print the number of open chrome profiles</li>
</ul>
<p dir="auto"><strong>Actual</strong></p>
<ul dir="auto">
<li>Log always prints 1</li>
</ul>