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

Dynamic imports started failing in 0.26.0 #2552

Closed
6 tasks done
purepear opened this issue Dec 21, 2022 · 4 comments · Fixed by #2560
Closed
6 tasks done

Dynamic imports started failing in 0.26.0 #2552

purepear opened this issue Dec 21, 2022 · 4 comments · Fixed by #2560

Comments

@purepear
Copy link

Describe the bug

I'm having problems with dynamic imports

  • everything was working in 0.25.8
  • everything is working in 0.26.2 when I run individual test files (npx vitest run individualFile.test.js)

The problem happens when I test multiple test files that have modules which dynamically import other modules:

// For example
await import(`../../${sth}/${sthElse}.js`)

The problem doesn't happen all the time - sometimes the tests pass, sometimes they fails and it's not always the exact same tests that fail. It feels like there's some sort of race condition between the workers when they start loading dynamic modules.

I made sure to await in all places

test('sth', async () => {
  // render a component that has `async created()` that load dynamic modules 

  await flushPromises() 
  await vi.dynamicImportSettled()
  
  // expect the side effects of the dynamic imports to have happened
})  

Reproduction

It's difficult to put together a reproduction because of the complexity of the project.
Any tips that would help narrow this down are welcome. 🙏

I tried creating a repro but it's still not ready - couldn't reproduce the flaky failures.

However I bumped into an interesting problem which may or may not be related:

  • starting the tests in watch mode works npx vitest
  • running the tests once hangs (CPU 100%) npx vitest run

https://stackblitz.com/edit/vitest-dynamic-imports-issues

System Info

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.34 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.19.0 - ~/.volta/tools/image/node/16.19.0/bin/node
    Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 8.19.3 - ~/.volta/tools/image/node/16.19.0/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Firefox: 107.0.1
    Safari: 16.2
  npmPackages:
    @vitejs/plugin-vue: ^3.2.0 => 3.2.0
    vite: ^3.2.5 => 3.2.5
    vitest: ^0.26.2 => 0.26.2

Used Package Manager

npm

Validations

@cexbrayat
Copy link
Contributor

We're also facing a similar issue, as @purepear, especially on CI. I tried to reproduce the issue in isolation, but it seems to be random (which confirms what happens on our CI jobs: we re-run them and they succeed).

The only tests that randomly fail are those using vi.dynamicImportSettled(), and they started failing with v0.26.0 (and are still failing with v0.26.2).

@ahnpnl
Copy link

ahnpnl commented Dec 22, 2022

I also encountered the same issue. Rolling back to 0.25.8 fixes the problem.

@sheremet-va
Copy link
Member

running the tests once hangs (CPU 100%) npx vitest run

I noticed this in stackblitz, but cannot reproduce locally. Do you also this this locally?

@purepear
Copy link
Author

purepear commented Dec 24, 2022

Hey @sheremet-va, I tested your not yet merged PR and it seems to work fine 🎉
Thank you so much!

For others having similar problems: after updating I still had to add await vi.dynamicImportSettled() in few places that were previously working without it in 0.25.8(not sure how things worked before - it looks like I forgot to await in the first place) and despite that, I still had inconsistent failures... but your PR seems to fix this flakiness (still present in 0.26.2). Looking forward to the next release :)

Re stackblitz:

I noticed this in stackblitz, but cannot reproduce locally. Do you also this this locally?

I just transferred the stackblitz code locally and it runs fine. Seem like an unrelated stackblitz-specific issue.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants