vitest.workspace.mts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { svelte, vitePreprocess } from '@sveltejs/vite-plugin-svelte';
  2. import { defineWorkspace } from 'vitest/config';
  3. /**
  4. * Two projects, one command (`npm test` still runs everything).
  5. *
  6. * The split exists because of exactly one suite. `ui-package.test.ts` mounts
  7. * `@colbymchenry/codegraph-ui`'s components against a mock adapter (task
  8. * CG-61), and to do that it needs three things the engine's suites must never
  9. * see:
  10. *
  11. * - the **Svelte plugin**, to compile `.svelte` and `.svelte.ts` modules;
  12. * - **jsdom**, because a component without a document is not a render;
  13. * - `resolve.conditions: ['browser']`, so `svelte` resolves to its client
  14. * build rather than its server one (`mount()` throws on the server).
  15. *
  16. * That last one is why this is a workspace rather than one config with a
  17. * couple of extra fields. `browser` is a package-resolution condition, not a
  18. * test setting: applied globally it would also hand the engine's suites the
  19. * browser builds of `web-tree-sitter` and friends, and the failures that
  20. * causes look nothing like their cause.
  21. *
  22. * The engine project `extends` the shared base, so the env vars and Node guard
  23. * in `vitest.config.mts` still apply to every engine test. The ui project does
  24. * not — see the note on it.
  25. */
  26. export default defineWorkspace([
  27. {
  28. extends: './vitest.config.mts',
  29. test: {
  30. name: 'engine',
  31. include: ['__tests__/**/*.test.ts'],
  32. exclude: ['**/node_modules/**', '**/dist/**', '__tests__/ui-package.test.ts'],
  33. },
  34. },
  35. {
  36. // Deliberately NOT `extends`: a workspace project CONCATENATES the base's
  37. // `include` with its own, so extending here would run all 200-odd engine
  38. // suites a second time inside jsdom (and two of them fail there, for
  39. // reasons that have nothing to do with anything). This project stands
  40. // alone, and it needs none of the base's spawn-related env anyway.
  41. plugins: [
  42. // The same preprocessor `ui/svelte.config.js` builds with, so the test
  43. // compiles what the package ships.
  44. svelte({ preprocess: vitePreprocess() }),
  45. ],
  46. resolve: { conditions: ['browser'] },
  47. test: {
  48. name: 'ui',
  49. globals: true,
  50. include: ['__tests__/ui-package.test.ts'],
  51. environment: 'jsdom',
  52. server: {
  53. deps: {
  54. // `@xyflow/svelte` ships uncompiled `.svelte` files, so it has to go
  55. // through the plugin above rather than be externalised to Node,
  56. // which has no idea what a `.svelte` file is.
  57. inline: [/@xyflow\/svelte/],
  58. },
  59. },
  60. },
  61. },
  62. ]);