@theholocron/vitest-config 7.8.1 → 7.9.1

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@ A [Vitest configuration](https://vitest.dev/config/) with presets for Node.js li
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install --save-dev @theholocron/vitest-config
8
+ pnpm add -D @theholocron/vitest-config
9
9
  ```
10
10
 
11
11
  ## Usage
@@ -23,6 +23,7 @@ declare function reactApp(options?: {}): {
23
23
  };
24
24
  environment: string;
25
25
  globals: boolean;
26
+ setupFiles: string[];
26
27
  include: string[];
27
28
  exclude: string[];
28
29
  reporters: string[];
@@ -10,6 +10,7 @@ declare function react(options?: {}): {
10
10
  test: {
11
11
  environment: string;
12
12
  globals: boolean;
13
+ setupFiles: string[];
13
14
  include: string[];
14
15
  exclude: string[];
15
16
  reporters: string[];
@@ -10,6 +10,7 @@ function react(options = {}) {
10
10
  return { test: {
11
11
  environment: "jsdom",
12
12
  globals: true,
13
+ setupFiles: ["@theholocron/vitest-config/setup/jest-dom"],
13
14
  include: ["**/*.{test,spec}.{js,jsx,ts,tsx}"],
14
15
  exclude: [
15
16
  "**/node_modules/**",
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom";
@@ -0,0 +1,2 @@
1
+ import "@testing-library/jest-dom";
2
+ export {};
@@ -0,0 +1,22 @@
1
+ //#region setup/msw.d.ts
2
+ interface Worker {
3
+ start(options?: {
4
+ onUnhandledRequest?: string;
5
+ }): Promise<void>;
6
+ resetHandlers(): void;
7
+ stop(): void;
8
+ }
9
+ interface Server {
10
+ listen(options?: {
11
+ onUnhandledRequest?: string;
12
+ }): void;
13
+ resetHandlers(): void;
14
+ close(): void;
15
+ }
16
+ interface Annotations {
17
+ beforeAll?(): Promise<void> | void;
18
+ }
19
+ declare function setupMSWBrowser(worker: Worker, annotations?: Annotations): void;
20
+ declare function setupMSWNode(server: Server, annotations?: Annotations): void;
21
+ //#endregion
22
+ export { setupMSWBrowser, setupMSWNode };
@@ -0,0 +1,28 @@
1
+ import { afterAll, afterEach, beforeAll } from "vitest";
2
+ //#region setup/msw.ts
3
+ function setupMSWBrowser(worker, annotations) {
4
+ beforeAll(async () => {
5
+ await annotations?.beforeAll?.();
6
+ await worker.start({ onUnhandledRequest: "warn" });
7
+ });
8
+ afterEach(() => {
9
+ worker.resetHandlers();
10
+ });
11
+ afterAll(() => {
12
+ worker.stop();
13
+ });
14
+ }
15
+ function setupMSWNode(server, annotations) {
16
+ beforeAll(async () => {
17
+ await annotations?.beforeAll?.();
18
+ server.listen({ onUnhandledRequest: "warn" });
19
+ });
20
+ afterEach(() => {
21
+ server.resetHandlers();
22
+ });
23
+ afterAll(() => {
24
+ server.close();
25
+ });
26
+ }
27
+ //#endregion
28
+ export { setupMSWBrowser, setupMSWNode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/vitest-config",
3
- "version": "7.8.1",
3
+ "version": "7.9.1",
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.8.1"
27
+ "@theholocron/tsconfig": "7.9.1"
28
28
  },
29
29
  "exports": {
30
30
  ".": {
@@ -57,6 +57,16 @@
57
57
  "import": "./dist/bundles/react-app.js",
58
58
  "default": "./dist/bundles/react-app.js"
59
59
  },
60
+ "./setup/jest-dom": {
61
+ "types": "./dist/setup/jest-dom.d.ts",
62
+ "import": "./dist/setup/jest-dom.js",
63
+ "default": "./dist/setup/jest-dom.js"
64
+ },
65
+ "./setup/msw": {
66
+ "types": "./dist/setup/msw.d.ts",
67
+ "import": "./dist/setup/msw.js",
68
+ "default": "./dist/setup/msw.js"
69
+ },
60
70
  "./package.json": "./package.json"
61
71
  },
62
72
  "files": [
@@ -64,6 +74,7 @@
64
74
  ],
65
75
  "peerDependencies": {
66
76
  "vitest": "^4",
77
+ "@testing-library/jest-dom": "^6",
67
78
  "@testing-library/react": "^16",
68
79
  "@testing-library/user-event": "^14",
69
80
  "@vitest/browser": "^4",
@@ -73,6 +84,9 @@
73
84
  "playwright": "^1"
74
85
  },
75
86
  "peerDependenciesMeta": {
87
+ "@testing-library/jest-dom": {
88
+ "optional": true
89
+ },
76
90
  "@testing-library/react": {
77
91
  "optional": true
78
92
  },
@@ -106,6 +120,7 @@
106
120
  "scripts": {
107
121
  "build": "tsdown",
108
122
  "typecheck": "tsc --noEmit",
109
- "test": "vitest run"
123
+ "test": "vitest run",
124
+ "test:coverage": "vitest run --coverage"
110
125
  }
111
126
  }