2
0

vitest.workspace.mts 2.1 KB

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