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

"Vite unexpectedly reloaded a test" warning whilst running Vitest #7333

Closed
6 tasks done
DG-DylD opened this issue Jan 22, 2025 · 2 comments
Closed
6 tasks done

"Vite unexpectedly reloaded a test" warning whilst running Vitest #7333

DG-DylD opened this issue Jan 22, 2025 · 2 comments

Comments

@DG-DylD
Copy link

DG-DylD commented Jan 22, 2025

Describe the bug

I am running my node and browser tests within Vitest using this configuration (vitest.config.ts):

import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    workspace: [
      // * Add a workspace for node tests (e.g. unit tests)
      {
        test: {
          include: ['src/**/*.node.{test,spec}.ts'],
          name: 'node',
          environment: 'node',
        },
      },
      // * Add a workspace for browser tests (e.g. integration tests)
      {
        test: {
          setupFiles: ['./tests/setup.browser.ts'],
          include: ['src/**/*.browser.{test,spec}.tsx'],
          browser: {
            enabled: true,
            provider: 'playwright',
            instances: [{ name: 'browser', browser: 'chromium' }],
          },
        },
      },
    ],
  },
});

My Vite configuration (vite.config.ts) is the following:

import { defineConfig } from 'vite';
import viteReact from '@vitejs/plugin-react';
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';

export default defineConfig({
  plugins: [TanStackRouterVite(), viteReact()],
  server: {
    open: true,
    port: 3000,
  },
});

I am running this script locally in VSCode and within Github actions: vitest run --browser.headless and getting the following output.

RUN  v3.0.3
✓  node  src/**/*.node.test.ts (1 test) 4ms
[vite] (client) ✨ new dependencies optimized: react/jsx-dev-runtime
[vite] (client) ✨ optimized dependencies changed. reloading
[vitest] Vite unexpectedly reloaded a test. This may cause tests to fail, lead to flaky behaviour or duplicated test runs.
For a stable experience, please add mentioned dependencies to your config's `optimizeDeps.include` field manually.
✓  browser  src/**/*.browser.test.tsx (2 tests) 193ms
Test Files  2 passed (2)
Tests  3 passed (3)
Duration  11.85s (transform 93ms, setup 3.60s, collect 4.00s, tests 197ms, environment 0ms, prepare 2.61s)

As you can see, I am getting a warning about react/jsx-dev-runtime, but after adding this to the optimizeDeps.include in vite.config.ts and vitest.config.ts, not at the same time, but separately, it does not cause the warning to go away.

I have tried to read the about the dependency pre-bundling here: https://vite.dev/guide/dep-pre-bundling.html, but with my lack of knowledge in this area, it wasn't able to provide enough to help me figure out what could be happening.

If anyone could give me a solution or even just a step in the right direction to get there, that would be much appreciated :)

Reproduction

I think the above is enough for now - can provide more information if need be.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 14.98 GB / 31.62 GB
Binaries:
    Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.8.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.4.0 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
    Edge: Chromium (131.0.2903.146)
    Internet Explorer: 11.0.19041.4355
npmPackages:
    @vitejs/plugin-react: ^4.3.4 => 4.3.4
    @vitest/browser: ^3.0.3 => 3.0.3
    vite: ^6.0.11 => 6.0.11
    vitest: ^3.0.3 => 3.0.3

Used Package Manager

npm

Validations

Copy link

Hello @DG-DylD. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@DG-DylD
Copy link
Author

DG-DylD commented Jan 24, 2025

There is definitely an issue with my specific configuration, albeit with my configuration or the packages themselves, but I could not get a StackBlitz working, so this will not be able to be taken any further, so closing this issue.

@DG-DylD DG-DylD closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants