2
0

vitest.workspace.mts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/migrate-mongo.ts',
  47. './test/setup/mongo/index.ts',
  48. ],
  49. deps: {
  50. // Transform inline modules (allows ESM in require context)
  51. interopDefault: true,
  52. },
  53. server: {
  54. deps: {
  55. // Inline workspace packages that use CJS format
  56. inline: [
  57. '@growi/remark-attachment-refs',
  58. '@growi/remark-drawio',
  59. '@growi/remark-lsx',
  60. /src\/server\/events/,
  61. ],
  62. },
  63. },
  64. },
  65. }),
  66. // component test
  67. mergeConfig(configShared, {
  68. plugins: [react()],
  69. test: {
  70. name: 'app-components',
  71. environment: 'happy-dom',
  72. include: ['**/*.spec.{tsx,jsx}'],
  73. setupFiles: ['./test/setup/jest-dom.ts'],
  74. },
  75. }),
  76. ]);