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

Vitest is stuck in a loop when using browser mode and calling location.reload() in afterAll callback #6439

Open
6 tasks done
andreatiled opened this issue Sep 2, 2024 · 2 comments
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@andreatiled
Copy link

Describe the bug

As the title describes, i'm using Vitest in browser mode and i'm calling location.reload() in afterAll callback:

afterAll(async () => {
  await myUnloadMethod()
  location.reload()
})

The reason of calling location.reload() is to ensure that after all tests in the file ran, the next tests will execute in a clean environment as if we just loaded the page

Reproduction

Can't seem to get StackBlitz work with Vitest in browser mode

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M2 Pro
    Memory: 171.42 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.18.2/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
    pnpm: 8.9.2 - ~/.nvm/versions/node/v18.18.2/bin/pnpm
  Browsers:
    Brave Browser: 128.1.69.153
    Chrome: 128.0.6613.114
    Edge: 128.0.2739.54
    Firefox Nightly: 130.0a1
    Safari: 17.5
    Safari Technology Preview: 18.0
  npmPackages:
    @vitejs/plugin-basic-ssl: ^1.1.0 => 1.1.0 
    @vitest/browser: ^2.0.5 => 2.0.5 
    @vitest/coverage-istanbul: ^2.0.5 => 2.0.5 
    vite: ^5.4.2 => 5.4.2 
    vitest: ^2.0.5 => 2.0.5

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

The reason of calling location.reload() is to ensure that after all tests in the file ran, the next tests will execute in a clean environment as if we just loaded the page

What do you mean? Vitest tests run in isolated environments.

@sheremet-va sheremet-va added p2-to-be-discussed Enhancement under consideration (priority) and removed pending triage labels Sep 6, 2024
@sheremet-va
Copy link
Member

So, it looks like this can only happen if the reload happens in the last test because we remove previous iframes. This also happens outside of Vitest's test lifecycle because onFinished was already called and we reported all test results. The reporter still prints test results after "FAIL"/"SUCCESS" footer, but we don't have any mechanism to report behaviour that happens after onFinished is called. I wonder if this should be resolved with the new reporter API.

@sheremet-va sheremet-va added p2-edge-case Bug, but has workaround or limited in scope (priority) and removed p2-to-be-discussed Enhancement under consideration (priority) labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
Status: Approved
Development

No branches or pull requests

2 participants