import { EventEmitter } from 'node:events'
import { resolve } from 'node:path'
import { defineConfig } from 'vitest/config'

const hmrServer = new EventEmitter()

// Keep unit tests independent from uni-app's compiler and file watchers.
export default defineConfig({
  plugins: [{
    name: 'unit-test-disable-hmr-socket',
    enforce: 'post',
    configResolved(config) {
      config.server.hmr = { server: hmrServer }
    },
  }],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  test: {
    environment: 'jsdom',
    setupFiles: [resolve(__dirname, 'test/setupTests.ts')],
    include: ['test/**/*.test.ts'],
    pool: 'forks',
    poolOptions: {
      forks: {
        singleFork: true,
      },
    },
    server: {
      deps: {
        inline: ['@pmun/utils'],
      },
    },
  },
})
