material-svelte / vite-web-test-runner-plugin

MIT License
39 stars 13 forks source link

Tests fail the first time if the build is uncached #4

Open aaronjensen opened 3 years ago

aaronjensen commented 3 years ago

I get fairly random errors when I attempt to run tests with cleared vite cache. If I refresh, it's all fine and my tests run and pass no problem.

Here's an example error:

CleanShot 2021-05-03 at 14 46 43@2x

I also sometimes see an error saying that some modules do not have a default export (like assert)

Have you seen this before? Any suggestions?

Thanks!

aaronjensen commented 3 years ago

Here's another error I see sometimes:

CleanShot 2021-05-03 at 14 55 56@2x
aaronjensen commented 3 years ago

I can fix these by including my test dependencies in optimizeDeps:

  optimizeDeps: {
    // These must be included when running tests or the first test run on an
    // uncached build will fail
    include: [
      "assert",
      "@testing-library/react",
      "@testing-library/react/dont-cleanup-after-each",
    ],
  },

So perhaps this is a vite limitation? I wonder if there's something else I'm missing...

betaboon commented 3 years ago

i have not seen that behavior before. maybe you can provide a repro?

aaronjensen commented 3 years ago

Sure, here you go... hopefully you can repro with it https://github.com/aaronjensen/vite-test-repro

betaboon commented 3 years ago

@aaronjensen thanks for the repro. i can reproduce it. i do believe this issue is due to vite. eg see this issue: https://github.com/vitejs/vite/issues/2579#issuecomment-841770842

aaronjensen commented 3 years ago

Okay, thank you. I'll just wait then.