@theholocron/vitest-config 7.12.0 → 7.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +72 -16
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -10,59 +10,115 @@ pnpm add -D @theholocron/vitest-config
10
10
 
11
11
  ## Usage
12
12
 
13
- Pick the preset that matches your project type. Presets return a `UserProjectConfig` object for use in `vitest.config.js`.
13
+ Presets are designed for use with Vitest's `projects` array, which runs unit and component tests in separate environments. Coverage is configured at the root `test` level and applies across all projects.
14
+
15
+ ```typescript
16
+ import { coverage, react, storybook } from "@theholocron/vitest-config";
17
+ import { defineConfig } from "vitest/config";
18
+
19
+ export default defineConfig(async () => ({
20
+ test: {
21
+ coverage: {
22
+ ...coverage,
23
+ exclude: [...coverage.exclude, "**/mocks/**"],
24
+ },
25
+ projects: [react({ name: "unit" }), await storybook(".storybook", { setupFiles: ["./vitest.setup.ts"] })],
26
+ },
27
+ }));
28
+ ```
14
29
 
15
30
  ### Node.js library or CLI tool
16
31
 
17
- ```javascript
32
+ ```typescript
33
+ import { node } from "@theholocron/vitest-config";
18
34
  import { defineConfig } from "vitest/config";
19
- import { node } from "@theholocron/vitest-config/node";
20
35
 
21
- export default defineConfig({ test: node().test });
36
+ export default defineConfig(node());
22
37
  ```
23
38
 
24
39
  ### React component library or app
25
40
 
26
- Requires `jsdom` and `@testing-library/react` as peer dependencies.
41
+ Requires `jsdom`, `@testing-library/react`, and `@testing-library/jest-dom` as peer dependencies. The `react` preset automatically adds `@testing-library/jest-dom` to `setupFiles` — no manual import needed.
27
42
 
28
- ```javascript
43
+ ```typescript
44
+ import { react } from "@theholocron/vitest-config";
29
45
  import { defineConfig } from "vitest/config";
30
- import { react } from "@theholocron/vitest-config/react";
31
46
 
32
- export default defineConfig({ test: react().test });
47
+ export default defineConfig(react());
33
48
  ```
34
49
 
35
50
  ### Storybook component tests
36
51
 
37
52
  Requires `@storybook/addon-vitest` and `playwright` as peer dependencies.
38
53
 
39
- ```javascript
54
+ ```typescript
55
+ import { storybook } from "@theholocron/vitest-config";
40
56
  import { defineConfig } from "vitest/config";
41
- import { storybook } from "@theholocron/vitest-config/storybook";
42
57
 
43
58
  export default defineConfig(await storybook(".storybook"));
44
59
  ```
45
60
 
61
+ ## Coverage defaults
62
+
63
+ The `coverage` export provides standard coverage configuration (v8 provider, `text` + `lcov` reporters, vitest's default excludes). Extend it with project-specific excludes:
64
+
65
+ ```typescript
66
+ import { coverage } from "@theholocron/vitest-config";
67
+
68
+ // in vitest.config.ts
69
+ coverage: {
70
+ ...coverage,
71
+ exclude: [...coverage.exclude, "**/handlers.*", "**/*.mock.*"],
72
+ }
73
+ ```
74
+
75
+ ## MSW setup helpers
76
+
77
+ Use `setupMSWBrowser` and `setupMSWNode` from `@theholocron/vitest-config/setup/msw` to wire MSW lifecycle hooks. Pass optional Storybook annotations to ensure `annotations.beforeAll` runs before the worker starts.
78
+
79
+ ### Browser (Storybook / Playwright)
80
+
81
+ ```typescript
82
+ // vitest.setup.ts
83
+ import { setProjectAnnotations } from "@storybook/react";
84
+ import { setupMSWBrowser } from "@theholocron/vitest-config/setup/msw";
85
+ import * as preview from "./.storybook/preview";
86
+ import { worker } from "./src/mocks/browser";
87
+
88
+ const annotations = setProjectAnnotations([preview]);
89
+ setupMSWBrowser(worker, annotations);
90
+ ```
91
+
92
+ ### Node (unit tests)
93
+
94
+ ```typescript
95
+ // vitest.setup.ts
96
+ import { setupMSWNode } from "@theholocron/vitest-config/setup/msw";
97
+ import { server } from "./src/mocks/node";
98
+
99
+ setupMSWNode(server);
100
+ ```
101
+
46
102
  ## Bundles
47
103
 
48
104
  Bundles combine a preset with opinionated coverage settings (80% threshold on all metrics via `@vitest/coverage-v8`).
49
105
 
50
106
  ### Library bundle
51
107
 
52
- ```javascript
53
- import { defineConfig } from "vitest/config";
108
+ ```typescript
54
109
  import { library } from "@theholocron/vitest-config/bundles/library";
110
+ import { defineConfig } from "vitest/config";
55
111
 
56
- export default defineConfig({ test: library().test });
112
+ export default defineConfig(library());
57
113
  ```
58
114
 
59
115
  ### React app bundle
60
116
 
61
- ```javascript
62
- import { defineConfig } from "vitest/config";
117
+ ```typescript
63
118
  import { reactApp } from "@theholocron/vitest-config/bundles/react-app";
119
+ import { defineConfig } from "vitest/config";
64
120
 
65
- export default defineConfig({ test: reactApp().test });
121
+ export default defineConfig(reactApp());
66
122
  ```
67
123
 
68
124
  ## How We Test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/vitest-config",
3
- "version": "7.12.0",
3
+ "version": "7.13.0",
4
4
  "description": "Vitest configuration presets for libraries, React apps, and Storybook within the Galaxy.",
5
5
  "homepage": "https://github.com/theholocron/configs/tree/main/packages/vitest-config#readme",
6
6
  "bugs": "https://github.com/theholocron/configs/issues",
@@ -24,7 +24,7 @@
24
24
  "typescript": "^5.9.3",
25
25
  "vitest": "^4.1.10",
26
26
  "@vitest/coverage-v8": "^4.1.10",
27
- "@theholocron/tsconfig": "7.12.0"
27
+ "@theholocron/tsconfig": "7.13.0"
28
28
  },
29
29
  "exports": {
30
30
  ".": {