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

usage with vitest? #2

Closed
evertbouw opened this issue Nov 1, 2022 · 4 comments
Closed

usage with vitest? #2

evertbouw opened this issue Nov 1, 2022 · 4 comments

Comments

@evertbouw
Copy link

evertbouw commented Nov 1, 2022

Trying this plugin in a prototype project and I get Error: React refresh preamble was not loaded. Something is wrong. while trying to run vitest. There is no need to have refresh during test ofc so should I just swap for the regular React plugin for test?

this does work

import { swcReactRefresh } from 'vite-plugin-swc-react-refresh';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig((env) => ({
  plugins: [
    env.mode === 'test' ? react() : swcReactRefresh(),
  ],
  esbuild: { jsx: 'automatic' },
  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: ['./src/setupTests.ts'],
  },
}));
@ArnaudBarre
Copy link
Member

I think I should just omit the refresh wrapper in test mode.

The babel plugin always insert the refresh wrapper but inside if (import.meta.hot) { so it's not executed in test mode.

I currently working on adding a caching option, so maybe the second option is simpler. Should be fixed later today

@quolpr
Copy link

quolpr commented Oct 5, 2023

@ArnaudBarre hey! Could we disable refresh mode but for vitest browser mode? https://vitest.dev/guide/browser.html

@ArnaudBarre
Copy link
Member

Should be the case in the latest version I think. @sheremet-va does config.server.hmr === false with browser mode?

@sheremet-va
Copy link
Member

Should be the case in the latest version I think. @sheremet-va does config.server.hmr === false with browser mode?

Yes, it should be disabled unless other plugins enable it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants