Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rerunning vitest with browser mode no longer works since vitest 1.0.0 #4713

Closed
6 tasks done
nicojs opened this issue Dec 9, 2023 · 4 comments · Fixed by #4715
Closed
6 tasks done

Rerunning vitest with browser mode no longer works since vitest 1.0.0 #4713

nicojs opened this issue Dec 9, 2023 · 4 comments · Fixed by #4715
Labels
feat: browser Issues and PRs related to the browser runner p3-significant High priority enhancement (priority)

Comments

@nicojs
Copy link
Contributor

nicojs commented Dec 9, 2023

Describe the bug

StrykerJS uses the programmatic API. For example:

process.env.NODE_ENV = "test";
import { createVitest } from "vitest/node";
const vitest = await createVitest("test", { watch: false });
await vitest.start();
vitest.state.filesMap.clear();
await vitest.start();
await vitest.close();

This works without browser mode and did work in browser mode until [email protected], but no longer in [email protected]

Reproduction

Using this script:

import { createVitest } from "vitest/node";
process.env.NODE_ENV = "test";

const vitest = await createVitest("test", { watch: false });
await vitest.start();
vitest.state.filesMap.clear();
await vitest.start();
await vitest.close();

With this config:

import { defineConfig } from 'vitest/config';
export default defineConfig({
  test: {
    globals: true,
    browser: {
      enabled: true,
      name: 'chromium',
      provider: 'playwright',
      headless: true,
    },
  },
});

I expect (v1.0.0-beta.6):

 RUN  v1.0.0-beta.6 /home/nicojs/github/vitest-browser
      Browser runner started at http://localhost:5173

 ✓ src/math.component.spec.ts (1)
   ✓ my-math (1)
     ✓ should add A + B

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  10:51:10
   Duration  970ms (transform 0ms, setup 0ms, collect 18ms, tests 11ms, environment 0ms, prepare 0ms)


 RUN  v1.0.0-beta.6 /home/nicojs/github/vitest-browser
      Browser runner started at http://localhost:5173

 ✓ src/math.component.spec.ts (1)
   ✓ my-math (1)
     ✓ should add A + B

But I get (v1.0.0 and v1.0.2):

 RUN  v1.0.2 /home/nicojs/github/vitest-browser
      Browser runner started at http://localhost:5173

 ✓ src/math.component.spec.ts (1)
   ✓ my-math (1)
     ✓ should add A + B

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  10:55:29
   Duration  901ms (transform 0ms, setup 0ms, collect 11ms, tests 8ms, environment 0ms, prepare 0ms)


 RUN  v1.0.2 /home/nicojs/github/vitest-browser
      Browser runner started at http://localhost:5173


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: page.goto: Target page, context or browser has been closed
Call log:
  - navigating to "http://localhost:5173/?path=src%2Fmath.component.spec.ts&id=src%2Fmath.component.spec.ts", waiting until "load"

 ❯ PlaywrightBrowserProvider.openPage node_modules/@vitest/browser/dist/providers.js:41:23
 ❯ runTests node_modules/vitest/dist/vendor/node.hPXN4l9e.js:3577:9
 ❯ Object.runWorkspaceTests node_modules/vitest/dist/vendor/node.hPXN4l9e.js:3596:7

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 Test Files  no tests
      Tests  no tests
     Errors  1 error
   Start at  10:55:29
   Duration  12ms (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)

See this zip for reproduction: vitest-browser.zip

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
    Memory: 3.56 GB / 15.49 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
    pnpm: 8.9.2 - ~/.nvm/versions/node/v18.18.0/bin/pnpm
  Browsers:
    Chrome: 118.0.5993.117
  npmPackages:
    @vitest/browser: ^1.0.2 => 1.0.2 
    vitest: ^1.0.2 => 1.0.2

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Dec 9, 2023

Interesting! I am not able to reproduce the error with your reproduction (M1 Air). Maybe some kind of race condition? 🤔

@sheremet-va
Copy link
Member

Oh, wait, I didn't update Vitest there 🤦🏻

@sheremet-va
Copy link
Member

sheremet-va commented Dec 9, 2023

Looks like this is the PR that caused it: #4623

But the actual error is that inside the provider we close the page, but we don't remove the reference to it. But when we do that, we get another bug 🤷🏻

@sheremet-va sheremet-va added bug p3-significant High priority enhancement (priority) feat: browser Issues and PRs related to the browser runner and removed pending triage labels Dec 9, 2023
@AriPerkkio
Copy link
Member

AriPerkkio commented Dec 9, 2023

Oops, didn't see this coming up while implementing #4623.

@nicojs it might be good idea to add stryker-mutator/stryker-js into Vitest Ecosystem CI so that we would see this kind of issues before releasing. There are not yet that many JS API utilizers out there yet.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner p3-significant High priority enhancement (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants