@jmlweb/vitest-config 1.0.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.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # @jmlweb/vitest-config
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@jmlweb/vitest-config)](https://www.npmjs.com/package/@jmlweb/vitest-config)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18.0.0-339933.svg)](https://nodejs.org/)
6
+ [![Vitest](https://img.shields.io/badge/Vitest-1.0%2B-6E9F18.svg)](https://vitest.dev/)
7
+
8
+ > Base Vitest configuration for jmlweb projects. TypeScript support, coverage settings, and sensible defaults out of the box.
9
+
10
+ ## ✨ Features
11
+
12
+ - 🔧 **TypeScript Support**: Configured for TypeScript projects with type checking enabled
13
+ - 📊 **Coverage Configuration**: Pre-configured with v8 provider and 80% coverage thresholds
14
+ - 🎯 **Sensible Defaults**: Node.js environment, globals enabled, standard reporters
15
+ - 🚀 **Easy Extension**: Flat config format for easy customization
16
+ - 📦 **Zero Config**: Works out of the box with minimal setup
17
+
18
+ ## 📦 Installation
19
+
20
+ ```bash
21
+ npm install --save-dev @jmlweb/vitest-config vitest
22
+ ```
23
+
24
+ ## 🚀 Quick Start
25
+
26
+ Create a `vitest.config.ts` file in your project root:
27
+
28
+ ```typescript
29
+ import { defineConfig } from 'vitest/config';
30
+ import baseConfig from '@jmlweb/vitest-config';
31
+
32
+ export default defineConfig({
33
+ ...baseConfig,
34
+ // Add your project-specific overrides here
35
+ });
36
+ ```
37
+
38
+ ## 💡 Examples
39
+
40
+ ### Basic Setup
41
+
42
+ ```typescript
43
+ // vitest.config.ts
44
+ import { defineConfig } from 'vitest/config';
45
+ import baseConfig from '@jmlweb/vitest-config';
46
+
47
+ export default defineConfig({
48
+ ...baseConfig,
49
+ });
50
+ ```
51
+
52
+ ### With Project-Specific Overrides
53
+
54
+ ```typescript
55
+ // vitest.config.ts
56
+ import { defineConfig } from 'vitest/config';
57
+ import baseConfig from '@jmlweb/vitest-config';
58
+
59
+ export default defineConfig({
60
+ ...baseConfig,
61
+ test: {
62
+ ...baseConfig.test,
63
+ // Override environment for browser testing
64
+ environment: 'jsdom',
65
+ // Custom test timeout
66
+ testTimeout: 10000,
67
+ // Custom coverage thresholds
68
+ coverage: {
69
+ ...baseConfig.test?.coverage,
70
+ thresholds: {
71
+ lines: 90,
72
+ functions: 90,
73
+ branches: 85,
74
+ statements: 90,
75
+ },
76
+ },
77
+ },
78
+ });
79
+ ```
80
+
81
+ ### React/JSX Project Example
82
+
83
+ ```typescript
84
+ // vitest.config.ts
85
+ import { defineConfig } from 'vitest/config';
86
+ import baseConfig from '@jmlweb/vitest-config';
87
+
88
+ export default defineConfig({
89
+ ...baseConfig,
90
+ test: {
91
+ ...baseConfig.test,
92
+ environment: 'jsdom', // Use jsdom for React component testing
93
+ setupFiles: ['./src/test/setup.ts'], // Optional setup file
94
+ },
95
+ });
96
+ ```
97
+
98
+ ### Lower Coverage Thresholds
99
+
100
+ ```typescript
101
+ // vitest.config.ts
102
+ import { defineConfig } from 'vitest/config';
103
+ import baseConfig from '@jmlweb/vitest-config';
104
+
105
+ export default defineConfig({
106
+ ...baseConfig,
107
+ test: {
108
+ ...baseConfig.test,
109
+ coverage: {
110
+ ...baseConfig.test?.coverage,
111
+ thresholds: {
112
+ lines: 60,
113
+ functions: 60,
114
+ branches: 60,
115
+ statements: 60,
116
+ },
117
+ },
118
+ },
119
+ });
120
+ ```
121
+
122
+ ## 📋 Configuration Details
123
+
124
+ ### Default Settings
125
+
126
+ | Setting | Value | Description |
127
+ | -------------------------------- | ------ | ---------------------------------------------------- |
128
+ | `globals` | `true` | Enables global test functions (describe, it, expect) |
129
+ | `environment` | `node` | Node.js environment by default |
130
+ | `coverage.provider` | `v8` | Coverage provider |
131
+ | `coverage.thresholds.lines` | `80` | Minimum line coverage |
132
+ | `coverage.thresholds.functions` | `80` | Minimum function coverage |
133
+ | `coverage.thresholds.branches` | `80` | Minimum branch coverage |
134
+ | `coverage.thresholds.statements` | `80` | Minimum statement coverage |
135
+ | `typecheck.enabled` | `true` | Enable TypeScript type checking |
136
+
137
+ ### Coverage Exclusions
138
+
139
+ The following patterns are excluded from coverage by default:
140
+
141
+ - `**/*.d.ts` - TypeScript declaration files
142
+ - `**/*.config.{ts,js}` - Configuration files
143
+ - `**/dist/**` - Build output
144
+ - `**/build/**` - Build directories
145
+ - `**/node_modules/**` - Dependencies
146
+ - `**/coverage/**` - Coverage reports
147
+ - `**/*.test.{ts,tsx,js,jsx}` - Test files
148
+ - `**/*.spec.{ts,tsx,js,jsx}` - Spec files
149
+
150
+ ### Test File Patterns
151
+
152
+ Tests are automatically discovered from:
153
+
154
+ - `**/*.test.{ts,tsx,js,jsx}`
155
+ - `**/*.spec.{ts,tsx,js,jsx}`
156
+
157
+ ### Reporters
158
+
159
+ Default reporters include:
160
+
161
+ - `verbose` - Detailed test output
162
+ - `json` - JSON format for CI/CD
163
+ - `html` - HTML coverage report
164
+
165
+ ## 🎯 When to Use
166
+
167
+ Use this configuration when you want:
168
+
169
+ - ✅ Consistent testing setup across projects
170
+ - ✅ TypeScript support out of the box
171
+ - ✅ Coverage thresholds enforced
172
+ - ✅ Sensible defaults for Node.js projects
173
+ - ✅ Easy customization and extension
174
+
175
+ ## 🔧 Extending the Configuration
176
+
177
+ You can extend or override the configuration for your specific needs:
178
+
179
+ ```typescript
180
+ import { defineConfig } from 'vitest/config';
181
+ import baseConfig from '@jmlweb/vitest-config';
182
+
183
+ export default defineConfig({
184
+ ...baseConfig,
185
+ test: {
186
+ ...baseConfig.test,
187
+ // Add custom setup files
188
+ setupFiles: ['./src/test/setup.ts'],
189
+ // Custom test patterns
190
+ include: ['**/*.test.ts', '**/__tests__/**/*.ts'],
191
+ // Custom environment
192
+ environment: 'jsdom',
193
+ },
194
+ });
195
+ ```
196
+
197
+ ## 📝 Usage with Scripts
198
+
199
+ Add test scripts to your `package.json`:
200
+
201
+ ```json
202
+ {
203
+ "scripts": {
204
+ "test": "vitest",
205
+ "test:run": "vitest run",
206
+ "test:coverage": "vitest run --coverage",
207
+ "test:ui": "vitest --ui"
208
+ }
209
+ }
210
+ ```
211
+
212
+ ## 📋 Requirements
213
+
214
+ - **Node.js** >= 18.0.0
215
+ - **Vitest** >= 1.0.0
216
+ - **TypeScript** project (recommended, but not required)
217
+
218
+ ## 📦 Peer Dependencies
219
+
220
+ This package requires the following peer dependency:
221
+
222
+ - `vitest` (^1.0.0)
223
+
224
+ ## 🔗 Related Packages
225
+
226
+ - [`@jmlweb/eslint-config-base`](../eslint-config-base) - ESLint config for TypeScript projects
227
+ - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
228
+ - [`@jmlweb/tsconfig-base`](../tsconfig-base) - TypeScript configuration
229
+
230
+ ## 📄 License
231
+
232
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => index_default
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var config = {
27
+ test: {
28
+ // Enable globals for cleaner test syntax (e.g., describe, it, expect without imports)
29
+ globals: true,
30
+ // Use Node.js environment by default
31
+ environment: "node",
32
+ // Coverage configuration
33
+ coverage: {
34
+ // Use v8 provider for coverage (default, but explicit for clarity)
35
+ provider: "v8",
36
+ // Coverage thresholds - enforce 80% coverage
37
+ thresholds: {
38
+ lines: 80,
39
+ functions: 80,
40
+ branches: 80,
41
+ statements: 80
42
+ },
43
+ // Files to include in coverage
44
+ include: ["src/**/*.{ts,tsx,js,jsx}"],
45
+ // Files to exclude from coverage
46
+ exclude: [
47
+ "**/*.d.ts",
48
+ "**/*.config.{ts,js}",
49
+ "**/dist/**",
50
+ "**/build/**",
51
+ "**/node_modules/**",
52
+ "**/coverage/**",
53
+ "**/*.test.{ts,tsx,js,jsx}",
54
+ "**/*.spec.{ts,tsx,js,jsx}"
55
+ ],
56
+ // Coverage reporters
57
+ reporter: ["text", "json", "html"]
58
+ },
59
+ // Test file patterns
60
+ include: ["**/*.{test,spec}.{ts,tsx,js,jsx}"],
61
+ // Files to exclude from test runs
62
+ exclude: [
63
+ "**/node_modules/**",
64
+ "**/dist/**",
65
+ "**/build/**",
66
+ "**/.{idea,git,cache,output,temp}/**",
67
+ "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*"
68
+ ],
69
+ // Reporter configuration
70
+ reporters: ["verbose", "json", "html"],
71
+ // TypeScript configuration
72
+ typecheck: {
73
+ enabled: true
74
+ }
75
+ }
76
+ };
77
+ var index_default = config;
@@ -0,0 +1,28 @@
1
+ import { UserConfig } from 'vitest/config';
2
+
3
+ /**
4
+ * Base Vitest configuration with TypeScript support, coverage settings, and sensible defaults.
5
+ * This configuration provides a solid foundation for testing TypeScript projects.
6
+ *
7
+ * Features:
8
+ * - TypeScript support out of the box
9
+ * - Coverage configuration with v8 provider
10
+ * - Standard coverage thresholds (80% for lines, functions, branches, statements)
11
+ * - Node.js environment by default
12
+ * - Globals enabled for cleaner test syntax
13
+ * - Standard reporter configuration
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { defineConfig } from 'vitest/config';
18
+ * import baseConfig from '@jmlweb/vitest-config';
19
+ *
20
+ * export default defineConfig({
21
+ * ...baseConfig,
22
+ * // Add your project-specific overrides here
23
+ * });
24
+ * ```
25
+ */
26
+ declare const config: UserConfig;
27
+
28
+ export { config as default };
@@ -0,0 +1,28 @@
1
+ import { UserConfig } from 'vitest/config';
2
+
3
+ /**
4
+ * Base Vitest configuration with TypeScript support, coverage settings, and sensible defaults.
5
+ * This configuration provides a solid foundation for testing TypeScript projects.
6
+ *
7
+ * Features:
8
+ * - TypeScript support out of the box
9
+ * - Coverage configuration with v8 provider
10
+ * - Standard coverage thresholds (80% for lines, functions, branches, statements)
11
+ * - Node.js environment by default
12
+ * - Globals enabled for cleaner test syntax
13
+ * - Standard reporter configuration
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { defineConfig } from 'vitest/config';
18
+ * import baseConfig from '@jmlweb/vitest-config';
19
+ *
20
+ * export default defineConfig({
21
+ * ...baseConfig,
22
+ * // Add your project-specific overrides here
23
+ * });
24
+ * ```
25
+ */
26
+ declare const config: UserConfig;
27
+
28
+ export { config as default };
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ // src/index.ts
2
+ var config = {
3
+ test: {
4
+ // Enable globals for cleaner test syntax (e.g., describe, it, expect without imports)
5
+ globals: true,
6
+ // Use Node.js environment by default
7
+ environment: "node",
8
+ // Coverage configuration
9
+ coverage: {
10
+ // Use v8 provider for coverage (default, but explicit for clarity)
11
+ provider: "v8",
12
+ // Coverage thresholds - enforce 80% coverage
13
+ thresholds: {
14
+ lines: 80,
15
+ functions: 80,
16
+ branches: 80,
17
+ statements: 80
18
+ },
19
+ // Files to include in coverage
20
+ include: ["src/**/*.{ts,tsx,js,jsx}"],
21
+ // Files to exclude from coverage
22
+ exclude: [
23
+ "**/*.d.ts",
24
+ "**/*.config.{ts,js}",
25
+ "**/dist/**",
26
+ "**/build/**",
27
+ "**/node_modules/**",
28
+ "**/coverage/**",
29
+ "**/*.test.{ts,tsx,js,jsx}",
30
+ "**/*.spec.{ts,tsx,js,jsx}"
31
+ ],
32
+ // Coverage reporters
33
+ reporter: ["text", "json", "html"]
34
+ },
35
+ // Test file patterns
36
+ include: ["**/*.{test,spec}.{ts,tsx,js,jsx}"],
37
+ // Files to exclude from test runs
38
+ exclude: [
39
+ "**/node_modules/**",
40
+ "**/dist/**",
41
+ "**/build/**",
42
+ "**/.{idea,git,cache,output,temp}/**",
43
+ "**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*"
44
+ ],
45
+ // Reporter configuration
46
+ reporters: ["verbose", "json", "html"],
47
+ // TypeScript configuration
48
+ typecheck: {
49
+ enabled: true
50
+ }
51
+ }
52
+ };
53
+ var index_default = config;
54
+ export {
55
+ index_default as default
56
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@jmlweb/vitest-config",
3
+ "version": "1.0.0",
4
+ "description": "Base Vitest configuration for jmlweb projects with TypeScript support and coverage settings",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "require": {
12
+ "types": "./dist/index.d.cts",
13
+ "default": "./dist/index.cjs"
14
+ },
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "clean": "rm -rf dist",
28
+ "prepublishOnly": "pnpm build"
29
+ },
30
+ "keywords": [
31
+ "vitest",
32
+ "vitest-config",
33
+ "testing",
34
+ "test-config",
35
+ "coverage"
36
+ ],
37
+ "author": "jmlweb",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/jmlweb/tooling.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/jmlweb/tooling/issues"
45
+ },
46
+ "homepage": "https://github.com/jmlweb/tooling/tree/main/packages/vitest-config#readme",
47
+ "engines": {
48
+ "node": ">=18.0.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "peerDependencies": {
54
+ "vitest": "^1.0.0"
55
+ },
56
+ "devDependencies": {
57
+ "@jmlweb/tsconfig-internal": "workspace:*",
58
+ "tsup": "^8.5.1",
59
+ "typescript": "^5.9.3",
60
+ "vitest": "^2.1.8"
61
+ }
62
+ }