nabla / vite-plugin-eslint

Plugs ESLint into Vite dev server
MIT License
122 stars 4 forks source link

[vitest] any way to disable this when running in test env (e.g. with vitest) #14

Open ortonomy opened 1 year ago

ortonomy commented 1 year ago

I see all the eslint plugin output in my testing runs which is distracting...

ArnaudBarre commented 1 year ago

Yeah maybe this can always be disable in test env.

For now, you can update your config to disable the plugin manually

export default defineConfig((env) => ({
  plugins: [
    env.mode !== 'test' && eslintPlugin()
  ],
daliborfilus commented 4 months ago

This plugin hangs with vitest 1.6 when running in vitest run, resulting in the message:

...
close timed out after 10000ms
Tests closed successfully but something prevents Vite server from exiting
You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reporters

When I enabled the hanging-process reporter, one of the processes was this:

# WORKER
node:internal/async_hooks:202                                                                                                                        
node:internal/worker:214                                                                                                                             
file:///.../node_modules/@nabla/vite-plugin-eslint/src/index.mjs:25                     
file:///.../node_modules/vitest/node_modules/vite/dist/node/chunks/dep-B8QpfTwU.js:51091
file:///.../node_modules/vitest/node_modules/vite/dist/node/chunks/dep-B8QpfTwU.js:53832

When I removed the eslintPlugin() from plugins, it doesn't hang. Thank you for the workaround, although in my case, the correct usage was this (vite.config.js):

import eslintPlugin from '@nabla/vite-plugin-eslint';
import { defineConfig } from 'vite';

export default ({ mode }) => {
  return defineConfig({
    plugins: [mode !== 'test' && eslintPlugin()],
    test: {
      reporters: ['default', 'hanging-process']
    }
  });
};