vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Tests are slow since Vite 3.x upgrade

Open Xa3lis opened this issue 3 years ago • 2 comments

Describe the bug

Since I upgraded Vite to 3.0.4 version, and Vitest to 0.21.1, the launching of my tests is really long (The setup phase, not the tests themselves)

Before 3.0.4 / 0.21.1 upgrade (With Vite 2.9.9 and Vitest 0.12.9)

image

After 3.0.4 / 0.21.1 upgrade

image

My vite.config.ts

/// <reference types="vitest" />
/// <reference types="vitest/globals" />

import { resolve } from 'path'
import dns from 'dns'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Pages from 'vite-plugin-pages'
import Icons from 'unplugin-icons/vite'
import Layouts from 'vite-plugin-vue-layouts'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import VueI18n from '@intlify/vite-plugin-vue-i18n'
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
import type { RouteRecord } from 'vue-router'
import { Role } from './src/models/roles/role-enum'

dns.setDefaultResultOrder('verbatim')

export default defineConfig({
  resolve: {
    alias: {
      '@/': `${resolve(__dirname, 'src')}/`,
      '&/': `${resolve(__dirname, 'tests')}/`,
    },
  },
  plugins: [
    Vue({
      reactivityTransform: true,
    }),
    // https://github.com/hannoeru/vite-plugin-pages
    Pages({
      extendRoute(route: RouteRecord) {
        if (route.name === 'unauthorized' || route.name === 'forbidden') {
          // These routes are available when unauthenticated.
          return route
        }

        // Augment the route with meta that indicates that the route is only allowed to pricing managers.
        return {
          ...route,
          meta: { ...route.meta, authorizedUserRoles: [Role.FR_PRICING_MANAGER, Role.IT_PRICING_MANAGER, Role.ES_PRICING_MANAGER] },
        }
      },
    }),
    Layouts(),

    // https://github.com/antfu/unplugin-auto-import
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        'vue-i18n',
        '@vueuse/head',
        '@vueuse/core',
        {
          pinia: [
            'storeToRefs',
          ],
        },
      ],
      dts: 'src/auto-imports.d.ts',
    }),

    // https://github.com/antfu/vite-plugin-components
    Components({
      resolvers: [
        // auto import icons
        // https://github.com/antfu/vite-plugin-icons
        IconsResolver({
          componentPrefix: '',
          customCollections: [
            'lm',
          ],
        }),
      ],
      dts: 'src/components.d.ts',
    }),

    // https://github.com/antfu/vite-plugin-icons
    Icons({
      autoInstall: true,
      customCollections: {
        lm: FileSystemIconLoader('./public'),
      },
    }),
    VueI18n({
      runtimeOnly: true,
      compositionOnly: true,
      include: [resolve(__dirname, 'locales/**')],
    }),
  ],

  server: {
    fs: {
      strict: true,
    },
    port: 8001,
    base: 'http://localhost:8001/',
    proxy: {
      '/graphql': {
        target: 'http://localhost:8070',
        ws: true,
        changeOrigin: true,
      },
      '^/auth/.*': {
        target: 'http://localhost:8070',
        changeOrigin: true,
      },
    },
  },

  optimizeDeps: {
    include: [
      'vue',
      'vue-router',
      '@vueuse/core',
      '@vueuse/head',
    ],
  },
  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: [resolve(__dirname, 'tests/setup.ts')],
    deps: {
      fallbackCJS: true,
      interopDefault: true,
    },
    coverage: {
      include: ['src/**/*.{ts,vue}'],
      exclude: ['src/models/**/*.ts', '**/*.d.ts', 'src/main.ts', 'src/App.vue', 'src/pages/**/*.vue', 'src/layouts/*.vue', 'src/components/common/feedback/notificatio{n,ns}.vue'],
      reporter: ['html', 'lcov'],
      all: true,
      lines: 90,
      statements: 90,
    },
  },
})

Reproduction

/

System Info

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 224.17 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
  Browsers:
    Brave Browser: 103.1.41.100
    Safari: 15.3
  npmPackages:
    @vitejs/plugin-vue: 3.0.1 => 3.0.1 
    vite: 3.0.5 => 3.0.5 
    vitest: 0.21.1 => 0.21.1

Used Package Manager

pnpm

Validations

Xa3lis avatar Aug 11 '22 11:08 Xa3lis

Hello @Xa3lis. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

github-actions[bot] avatar Aug 11 '22 13:08 github-actions[bot]

Cannot reproduce on stackblitz, might be linked to the M1 chip of my Mac

Xa3lis avatar Aug 12 '22 08:08 Xa3lis

Cannot reproduce on stackblitz, might be linked to the M1 chip of my Mac

You can give github repo as reproduction. I also have Mac M1.

sheremet-va avatar Aug 12 '22 09:08 sheremet-va

For literally no reason, after i switched back to the latest vite/vitest versions and after closing my terminal it worked as good as before... I'm closing the issue

Xa3lis avatar Aug 12 '22 09:08 Xa3lis