vitest.workspace.mts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import react from '@vitejs/plugin-react';
  2. import tsconfigPaths from 'vite-tsconfig-paths';
  3. import { defineConfig, defineWorkspace, mergeConfig } from 'vitest/config';
  4. const configShared = defineConfig({
  5. plugins: [tsconfigPaths()],
  6. test: {
  7. clearMocks: true,
  8. globals: true,
  9. exclude: ['playwright/**'],
  10. },
  11. });
  12. export default defineWorkspace([
  13. // unit test
  14. mergeConfig(configShared, {
  15. test: {
  16. name: 'app-unit',
  17. environment: 'node',
  18. include: ['**/*.spec.{ts,js}'],
  19. },
  20. }),
  21. // integration test
  22. mergeConfig(configShared, {
  23. resolve: {
  24. // Prefer require (CJS) for server-side packages
  25. conditions: ['require', 'node', 'default'],
  26. },
  27. test: {
  28. name: 'app-integration',
  29. environment: 'node',
  30. include: ['**/*.integ.ts'],
  31. // Pre-download the MongoDB binary before workers start to avoid lock-file race conditions
  32. globalSetup: ['./test/setup/mongo/global-setup.ts'],
  33. setupFiles: [
  34. './test/setup/migrate-mongo.ts',
  35. './test/setup/mongo/index.ts',
  36. ],
  37. deps: {
  38. // Transform inline modules (allows ESM in require context)
  39. interopDefault: true,
  40. },
  41. server: {
  42. deps: {
  43. // Inline workspace packages that use CJS format
  44. inline: [
  45. '@growi/remark-attachment-refs',
  46. '@growi/remark-drawio',
  47. '@growi/remark-lsx',
  48. /src\/server\/events/,
  49. ],
  50. },
  51. },
  52. },
  53. }),
  54. // component test
  55. mergeConfig(configShared, {
  56. plugins: [react()],
  57. test: {
  58. name: 'app-components',
  59. environment: 'happy-dom',
  60. include: ['**/*.spec.{tsx,jsx}'],
  61. setupFiles: ['./test/setup/jest-dom.ts'],
  62. },
  63. }),
  64. ]);