<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: [v1.35.1</li>
<li>Operating System: Windows 10</li>
<li>Browser: Chrominum</li>
<li>Other info:</li>
</ul>
<p dir="auto"><strong>Config file</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { defineConfig, devices } from '@playwright/test';
import GlobalConstant from './commons/GlobalConstant';

/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */
// require('dotenv').config();

/**
 * See https://playwright.dev/docs/test-configuration.
 */
export default defineConfig({
  testDir: './tests',
  /* Run tests in files in parallel */
  timeout: GlobalConstant.testTimeout * 1000,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: GlobalConstant.shortTimeout * 1000,
    toHaveScreenshot: {
      maxDiffPixelRatio: GlobalConstant.maxPixelDiffRatio,
      threshold: 0.3
    }
  },
  fullyParallel: true,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: GlobalConstant.workers,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: 'html',
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
    actionTimeout: GlobalConstant.mediumTimeout * 1000,
    navigationTimeout: GlobalConstant.mediumTimeout * 1000,
    /* Base URL to use in actions like `await page.goto('/')`. */
    // baseURL: 'http://127.0.0.1:3000',
    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'off',
    video: 'off',
    screenshot: 'off',
    headless: true,
    userAgent: GlobalConstant.userAgent,
    contextOptions: {
      ignoreHTTPSErrors: true,
    },
    extraHTTPHeaders: {
      'User-Agent': GlobalConstant.userAgent
    }
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'Desktop Edge',
      snapshotPathTemplate: './screenshots/{testFilePath}/{arg}-Desktop{ext}',
      use: {
        ...devices['Desktop Edge'],
        channel: 'chrome',
        browserName: 'chromium',
      },
    },

    // {
    //   name: 'firefox',
    //   use: { ...devices['Desktop Firefox'] },
    // },

    // {
    //   name: 'webkit',
    //   use: { ...devices['Desktop Safari'] },
    // },

    /* Test against mobile viewports. */
    {
      name: 'Mobile Edge',
      snapshotPathTemplate: './screenshots/{testFilePath}/{arg}-Mobile{ext}',
      use: {
        ...devices['Pixel 5'],
        channel: 'chrome',
        browserName: 'chromium',
      },
    },
    // {
    //   name: 'Mobile Safari',
    //   use: { ...devices['iPhone 12'] },
    // },

    /* Test against tablet viewports. */
    {
      name: 'Tablet Edge',
      snapshotPathTemplate: './screenshots/{testFilePath}/{arg}-Tablet{ext}',
      use: {
        ...devices['Galaxy Tab S4 landscape'],
        channel: 'chrome',
        browserName: 'chromium'
      },
    },
    // {
    //   name: 'Mobile Safari',
    //   use: { ...devices['iPhone 12'] },
    // },

    /* Test against branded browsers. */
    // {
    //   name: 'Microsoft Edge',
    //   use: { ...devices['Desktop Edge'], channel: 'msedge' },
    // },
    // {
    //   name: 'Google Chrome',
    //   use: { ..devices['Desktop Chrome'], channel: 'chrome' },
    // },
  ],

  /* Run your local dev server before starting the tests */
  // webServer: {
  //   command: 'npm run start',
  //   url: 'http://127.0.0.1:3000',
  //   reuseExistingServer: !process.env.CI,
  // },
});
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">defineConfig</span><span class="pl-kos">,</span> <span class="pl-s1">devices</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'@playwright/test'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-v">GlobalConstant</span> <span class="pl-k">from</span> <span class="pl-s">'./commons/GlobalConstant'</span><span class="pl-kos">;</span>

<span class="pl-c">/**</span>
<span class="pl-c"> * Read environment variables from file.</span>
<span class="pl-c"> * https://github.com/motdotla/dotenv</span>
<span class="pl-c"> */</span>
<span class="pl-c">// require('dotenv').config();</span>

<span class="pl-c">/**</span>
<span class="pl-c"> * See https://playwright.dev/docs/test-configuration.</span>
<span class="pl-c"> */</span>
<span class="pl-k">export</span> <span class="pl-k">default</span> <span class="pl-en">defineConfig</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-c1">testDir</span>: <span class="pl-s">'./tests'</span><span class="pl-kos">,</span>
  <span class="pl-c">/* Run tests in files in parallel */</span>
  <span class="pl-c1">timeout</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">testTimeout</span> <span class="pl-c1">*</span> <span class="pl-c1">1000</span><span class="pl-kos">,</span>
  <span class="pl-c1">expect</span>: <span class="pl-kos">{</span>
    <span class="pl-c">/**</span>
<span class="pl-c">     * Maximum time expect() should wait for the condition to be met.</span>
<span class="pl-c">     * For example in `await expect(locator).toHaveText();`</span>
<span class="pl-c">     */</span>
    <span class="pl-c1">timeout</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">shortTimeout</span> <span class="pl-c1">*</span> <span class="pl-c1">1000</span><span class="pl-kos">,</span>
    <span class="pl-c1">toHaveScreenshot</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">maxDiffPixelRatio</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">maxPixelDiffRatio</span><span class="pl-kos">,</span>
      <span class="pl-c1">threshold</span>: <span class="pl-c1">0.3</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c1">fullyParallel</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
  <span class="pl-c">/* Fail the build on CI if you accidentally left test.only in the source code. */</span>
  <span class="pl-c1">forbidOnly</span>: <span class="pl-c1">!</span><span class="pl-c1">!</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">CI</span><span class="pl-kos">,</span>
  <span class="pl-c">/* Retry on CI only */</span>
  <span class="pl-c1">retries</span>: <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">CI</span> ? <span class="pl-c1">2</span> : <span class="pl-c1">0</span><span class="pl-kos">,</span>
  <span class="pl-c">/* Opt out of parallel tests on CI. */</span>
  <span class="pl-c1">workers</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">workers</span><span class="pl-kos">,</span>
  <span class="pl-c">/* Reporter to use. See https://playwright.dev/docs/test-reporters */</span>
  <span class="pl-c1">reporter</span>: <span class="pl-s">'html'</span><span class="pl-kos">,</span>
  <span class="pl-c">/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */</span>
  <span class="pl-c1">use</span>: <span class="pl-kos">{</span>
    <span class="pl-c">/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */</span>
    <span class="pl-c1">actionTimeout</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">mediumTimeout</span> <span class="pl-c1">*</span> <span class="pl-c1">1000</span><span class="pl-kos">,</span>
    <span class="pl-c1">navigationTimeout</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">mediumTimeout</span> <span class="pl-c1">*</span> <span class="pl-c1">1000</span><span class="pl-kos">,</span>
    <span class="pl-c">/* Base URL to use in actions like `await page.goto('/')`. */</span>
    <span class="pl-c">// baseURL: 'http://127.0.0.1:3000',</span>
    <span class="pl-c">/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */</span>
    <span class="pl-c1">trace</span>: <span class="pl-s">'off'</span><span class="pl-kos">,</span>
    <span class="pl-c1">video</span>: <span class="pl-s">'off'</span><span class="pl-kos">,</span>
    <span class="pl-c1">screenshot</span>: <span class="pl-s">'off'</span><span class="pl-kos">,</span>
    <span class="pl-c1">headless</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-c1">userAgent</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">userAgent</span><span class="pl-kos">,</span>
    <span class="pl-c1">contextOptions</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">ignoreHTTPSErrors</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">extraHTTPHeaders</span>: <span class="pl-kos">{</span>
      <span class="pl-s">'User-Agent'</span>: <span class="pl-v">GlobalConstant</span><span class="pl-kos">.</span><span class="pl-c1">userAgent</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>

  <span class="pl-c">/* Configure projects for major browsers */</span>
  <span class="pl-c1">projects</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">{</span>
      <span class="pl-c1">name</span>: <span class="pl-s">'Desktop Edge'</span><span class="pl-kos">,</span>
      <span class="pl-c1">snapshotPathTemplate</span>: <span class="pl-s">'./screenshots/{testFilePath}/{arg}-Desktop{ext}'</span><span class="pl-kos">,</span>
      <span class="pl-c1">use</span>: <span class="pl-kos">{</span>
        ...<span class="pl-s1">devices</span><span class="pl-kos">[</span><span class="pl-s">'Desktop Edge'</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-c1">channel</span>: <span class="pl-s">'chrome'</span><span class="pl-kos">,</span>
        <span class="pl-c1">browserName</span>: <span class="pl-s">'chromium'</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-c">// {</span>
    <span class="pl-c">//   name: 'firefox',</span>
    <span class="pl-c">//   use: { ...devices['Desktop Firefox'] },</span>
    <span class="pl-c">// },</span>

    <span class="pl-c">// {</span>
    <span class="pl-c">//   name: 'webkit',</span>
    <span class="pl-c">//   use: { ...devices['Desktop Safari'] },</span>
    <span class="pl-c">// },</span>

    <span class="pl-c">/* Test against mobile viewports. */</span>
    <span class="pl-kos">{</span>
      <span class="pl-c1">name</span>: <span class="pl-s">'Mobile Edge'</span><span class="pl-kos">,</span>
      <span class="pl-c1">snapshotPathTemplate</span>: <span class="pl-s">'./screenshots/{testFilePath}/{arg}-Mobile{ext}'</span><span class="pl-kos">,</span>
      <span class="pl-c1">use</span>: <span class="pl-kos">{</span>
        ...<span class="pl-s1">devices</span><span class="pl-kos">[</span><span class="pl-s">'Pixel 5'</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-c1">channel</span>: <span class="pl-s">'chrome'</span><span class="pl-kos">,</span>
        <span class="pl-c1">browserName</span>: <span class="pl-s">'chromium'</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-c">// {</span>
    <span class="pl-c">//   name: 'Mobile Safari',</span>
    <span class="pl-c">//   use: { ...devices['iPhone 12'] },</span>
    <span class="pl-c">// },</span>

    <span class="pl-c">/* Test against tablet viewports. */</span>
    <span class="pl-kos">{</span>
      <span class="pl-c1">name</span>: <span class="pl-s">'Tablet Edge'</span><span class="pl-kos">,</span>
      <span class="pl-c1">snapshotPathTemplate</span>: <span class="pl-s">'./screenshots/{testFilePath}/{arg}-Tablet{ext}'</span><span class="pl-kos">,</span>
      <span class="pl-c1">use</span>: <span class="pl-kos">{</span>
        ...<span class="pl-s1">devices</span><span class="pl-kos">[</span><span class="pl-s">'Galaxy Tab S4 landscape'</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
        <span class="pl-c1">channel</span>: <span class="pl-s">'chrome'</span><span class="pl-kos">,</span>
        <span class="pl-c1">browserName</span>: <span class="pl-s">'chromium'</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c">// {</span>
    <span class="pl-c">//   name: 'Mobile Safari',</span>
    <span class="pl-c">//   use: { ...devices['iPhone 12'] },</span>
    <span class="pl-c">// },</span>

    <span class="pl-c">/* Test against branded browsers. */</span>
    <span class="pl-c">// {</span>
    <span class="pl-c">//   name: 'Microsoft Edge',</span>
    <span class="pl-c">//   use: { ...devices['Desktop Edge'], channel: 'msedge' },</span>
    <span class="pl-c">// },</span>
    <span class="pl-c">// {</span>
    <span class="pl-c">//   name: 'Google Chrome',</span>
    <span class="pl-c">//   use: { ..devices['Desktop Chrome'], channel: 'chrome' },</span>
    <span class="pl-c">// },</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>

  <span class="pl-c">/* Run your local dev server before starting the tests */</span>
  <span class="pl-c">// webServer: {</span>
  <span class="pl-c">//   command: 'npm run start',</span>
  <span class="pl-c">//   url: 'http://127.0.0.1:3000',</span>
  <span class="pl-c">//   reuseExistingServer: !process.env.CI,</span>
  <span class="pl-c">// },</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Steps</strong></p>
<ul dir="auto">
<li>Run the test with command line for all of projects: desktop, mobile, tablet</li>
<li>Check result</li>
</ul>
<p dir="auto"><strong>Expected</strong></p>
<p dir="auto">With the first running, it should show error below:<br>
"Error: A snapshot doesn't exist at xxxxxx" for all three projects (correct behaviour)</p>
<p dir="auto"><strong>Actual</strong></p>
<p dir="auto">It only shows "Error: A snapshot doesn't exist at xxxxxx" for desktop and mobile project.<br>
With tablet project, it do not capture screenshot for tablet and in test-results folder, it generate three files:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;xxx-actual.png
xxx-diff.png
xxx-previous.png&quot;"><pre class="notranslate"><code class="notranslate">"xxx-actual.png
xxx-diff.png
xxx-previous.png"
</code></pre></div>
<p dir="auto">I do not know where did the "xxx-previous.png" image comming from? As I run visual comparison many times, from the second running, it should generate three files instead.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;xxx-actual.png
xxx-diff.png
xxx-expected.png&quot;"><pre class="notranslate"><code class="notranslate">"xxx-actual.png
xxx-diff.png
xxx-expected.png"
</code></pre></div>
<h3 dir="auto">System info</h3>
<ul dir="auto">
<li>Playwright Version: v1.33</li>
<li>Operating System: Windows, Ubuntu22</li>
<li>Browser: All</li>
<li>Other info:</li>
</ul>
<h3 dir="auto">Source code</h3>
<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">Sorry, but I deviated a bit from the issue template.<br>
So, I am interested in page.unroute method.<br>
I had a look at the playwright tests<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/microsoft/playwright/blob/52feff39b3fedfb1eb7a6ff1b33e53a50d114fe7/tests/page/page-route.spec.ts#L42">playwright/tests/page/page-route.spec.ts</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 42
      in
      <a data-pjax="true" class="commit-tease-sha" href="/microsoft/playwright/commit/52feff39b3fedfb1eb7a6ff1b33e53a50d114fe7">52feff3</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L42" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="42"></td>
          <td id="LC42" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-en">it</span><span class="pl-kos">(</span><span class="pl-s">'should unroute'</span><span class="pl-kos">,</span> <span class="pl-k">async</span> <span class="pl-kos">(</span><span class="pl-kos">{</span> page<span class="pl-kos">,</span> server <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<br>
what I see it is only tested with strings as url.<br>
What I want to achieve is to unroute registered routes after each test.<br>
We are using regex for that.<p></p>
<p dir="auto">In our POM<br>
we have this</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="registerRoutes(page: Page): Promise&lt;void&gt; {
        return page.route(/(test\.local\/)|(domain2)/, this.testRouteHandler.bind(this));
    }

    async destroy(): Promise&lt;void&gt; {
        await this.page.unroute(/(test\.local\/)|(domain2)/);
    }"><pre class="notranslate"><span class="pl-en">registerRoutes</span><span class="pl-kos">(</span><span class="pl-s1">page</span>: <span class="pl-smi">Page</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-s1">page</span><span class="pl-kos">.</span><span class="pl-en">route</span><span class="pl-kos">(</span><span class="pl-pds"><span class="pl-c1">/</span><span class="pl-kos">(</span>test<span class="pl-cce">\.</span>local<span class="pl-cce">\/</span><span class="pl-kos">)</span><span class="pl-c1">|</span><span class="pl-kos">(</span>domain2<span class="pl-kos">)</span><span class="pl-c1">/</span></span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">testRouteHandler</span><span class="pl-kos">.</span><span class="pl-en">bind</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">)</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-s1">destroy</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-k">await</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">page</span><span class="pl-kos">.</span><span class="pl-en">unroute</span><span class="pl-kos">(</span><span class="pl-pds"><span class="pl-c1">/</span><span class="pl-kos">(</span>test<span class="pl-cce">\.</span>local<span class="pl-cce">\/</span><span class="pl-kos">)</span><span class="pl-c1">|</span><span class="pl-kos">(</span>domain2<span class="pl-kos">)</span><span class="pl-c1">/</span></span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span></pre></div>
<p dir="auto">Looking at the implementation in pw<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/microsoft/playwright/blob/52feff39b3fedfb1eb7a6ff1b33e53a50d114fe7/packages/playwright-core/src/client/page.ts#L460">playwright/packages/playwright-core/src/client/page.ts</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 460
      in
      <a data-pjax="true" class="commit-tease-sha" href="/microsoft/playwright/commit/52feff39b3fedfb1eb7a6ff1b33e53a50d114fe7">52feff3</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L460" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="460"></td>
          <td id="LC460" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">async</span> <span class="pl-en">unroute</span><span class="pl-kos">(</span><span class="pl-s1">url</span>: <span class="pl-smi">URLMatch</span><span class="pl-kos">,</span> <span class="pl-s1">handler</span>?: <span class="pl-smi">RouteHandlerCallback</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
<br>
it compares urls by  strict equality, and then filters out page._routes.<br>
So I guess for pure regexes it wont work.<br>
What I did is that I saved the url regex into an instance field, so I can pass in a reference<br>
Like this:<p></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="readonly routeUrl = /(test\.local\/)|(domain2)/;
registerRoutes(page: Page): Promise&lt;void&gt; {
        return page.route(this.routeUrl, this.testRouteHandler.bind(this));
    }

    async destroy(): Promise&lt;void&gt; {
        await this.page.unroute(this.routeUrl);
    }"><pre class="notranslate"><span class="pl-k">readonly</span> <span class="pl-s1">routeUrl</span> <span class="pl-c1">=</span> <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-kos">(</span>test<span class="pl-cce">\.</span>local<span class="pl-cce">\/</span><span class="pl-kos">)</span><span class="pl-c1">|</span><span class="pl-kos">(</span>domain2<span class="pl-kos">)</span><span class="pl-c1">/</span></span><span class="pl-kos">;</span>
<span class="pl-en">registerRoutes</span><span class="pl-kos">(</span><span class="pl-s1">page</span>: <span class="pl-smi">Page</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-s1">page</span><span class="pl-kos">.</span><span class="pl-en">route</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">routeUrl</span><span class="pl-kos">,</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">testRouteHandler</span><span class="pl-kos">.</span><span class="pl-en">bind</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">)</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-s1">destroy</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">Promise</span><span class="pl-kos">&lt;</span><span class="pl-smi"><span class="pl-k">void</span></span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-k">await</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">page</span><span class="pl-kos">.</span><span class="pl-en">unroute</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">routeUrl</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span></pre></div>
<p dir="auto">After awaiting the destroy method, page object still has a length of one in _routes, and points to the registered handlers.<br>
Our goal is to get rid for all registered routes on the page in destroy method.<br>
How to achieve it in regex?<br>
can unroute also return a new length or something, or a boolean that confirms that routes are indeed unregistered?</p>
<p dir="auto">Another thing we have is that sometimes there is a request in route handler that takes some time, and eventually throws<br>
It happens that at that time another test is running, and route handler from previous test throws in another test, and then urelated test fails.</p>
<p dir="auto">What I thought is to collect pending promises from route handles into a local array on POM instance, since we use POM as a fixture, and after <code class="notranslate">use(POMfixture)</code> to await that all promises from that array are resolved before fixture can be teared down.<br>
Not sure if you guys have a better advice on how to approach it?</p>