vitest.workspace.mts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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: ['test/**', '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. setupFiles: ['./test/setup/mongoms.ts'],
  32. // Disable file parallelism to avoid mongodb-memory-server lock conflicts
  33. fileParallelism: false,
  34. deps: {
  35. // Transform inline modules (allows ESM in require context)
  36. interopDefault: true,
  37. },
  38. server: {
  39. deps: {
  40. // Inline workspace packages that use CJS format
  41. inline: [
  42. '@growi/remark-attachment-refs',
  43. '@growi/remark-drawio',
  44. '@growi/remark-lsx',
  45. /src\/server\/events/,
  46. ],
  47. },
  48. },
  49. },
  50. }),
  51. // component test
  52. mergeConfig(configShared, {
  53. plugins: [react()],
  54. test: {
  55. name: 'app-components',
  56. environment: 'happy-dom',
  57. include: ['**/*.spec.{tsx,jsx}'],
  58. setupFiles: ['./test/setup/jest-dom.ts'],
  59. },
  60. }),
  61. ]);