@jmlweb/vitest-config 1.0.3 → 1.0.5
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/CHANGELOG.md +12 -0
- package/README.md +164 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @jmlweb/vitest-config
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6b73301: Add changelog section with link to CHANGELOG.md in package READMEs
|
|
8
|
+
|
|
9
|
+
## 1.0.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- beae5ae: Add trailing newlines to source files for consistency.
|
|
14
|
+
|
|
3
15
|
## 1.0.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
npm install --save-dev @jmlweb/vitest-config vitest
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
> 💡 **Upgrading from a previous version?** See the [Migration Guide](#-migration-guide) for breaking changes and upgrade instructions.
|
|
26
|
+
|
|
25
27
|
## 🚀 Quick Start
|
|
26
28
|
|
|
27
29
|
Create a `vitest.config.ts` file in your project root:
|
|
@@ -261,10 +263,172 @@ See real-world usage examples:
|
|
|
261
263
|
|
|
262
264
|
## 🔗 Related Packages
|
|
263
265
|
|
|
266
|
+
### Internal Packages
|
|
267
|
+
|
|
268
|
+
- [`@jmlweb/jest-config`](../jest-config) - Jest configuration (alternative test runner)
|
|
264
269
|
- [`@jmlweb/eslint-config-base`](../eslint-config-base) - ESLint config for TypeScript projects
|
|
265
270
|
- [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
|
|
266
271
|
- [`@jmlweb/tsconfig-base`](../tsconfig-base) - TypeScript configuration
|
|
267
272
|
|
|
273
|
+
### External Tools
|
|
274
|
+
|
|
275
|
+
- [Vitest](https://vitest.dev/) - Blazing-fast unit test framework powered by Vite
|
|
276
|
+
- [@testing-library/jest-dom](https://testing-library.com/docs/ecosystem-jest-dom/) - Custom matchers for the DOM (works with Vitest)
|
|
277
|
+
- [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) - React testing utilities (for React projects)
|
|
278
|
+
- [@vitest/ui](https://vitest.dev/guide/ui.html) - Visual UI for Vitest test results
|
|
279
|
+
|
|
280
|
+
## ⚠️ Common Issues
|
|
281
|
+
|
|
282
|
+
> **Note:** This section documents known issues and their solutions. If you encounter a problem not listed here, please [open an issue](https://github.com/jmlweb/tooling/issues/new).
|
|
283
|
+
|
|
284
|
+
### Module Resolution Issues
|
|
285
|
+
|
|
286
|
+
**Symptoms:**
|
|
287
|
+
|
|
288
|
+
- Error: "Cannot find module" when running tests
|
|
289
|
+
- Import paths work in the app but fail in tests
|
|
290
|
+
|
|
291
|
+
**Cause:**
|
|
292
|
+
|
|
293
|
+
- Vitest uses Vite's module resolution which may differ from TypeScript
|
|
294
|
+
- Path aliases or special imports not configured for tests
|
|
295
|
+
|
|
296
|
+
**Solution:**
|
|
297
|
+
|
|
298
|
+
If you're using path aliases in `tsconfig.json`, configure them in your Vitest config:
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
// vitest.config.ts
|
|
302
|
+
import { defineConfig } from 'vitest/config';
|
|
303
|
+
import vitestConfig from '@jmlweb/vitest-config';
|
|
304
|
+
|
|
305
|
+
export default defineConfig({
|
|
306
|
+
...vitestConfig,
|
|
307
|
+
resolve: {
|
|
308
|
+
alias: {
|
|
309
|
+
'@': '/src',
|
|
310
|
+
'@components': '/src/components',
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### jsdom or happy-dom Not Found
|
|
317
|
+
|
|
318
|
+
**Symptoms:**
|
|
319
|
+
|
|
320
|
+
- Error: "Environment 'jsdom' not found" or "Environment 'happy-dom' not found"
|
|
321
|
+
- Tests fail to run with DOM-related errors
|
|
322
|
+
|
|
323
|
+
**Cause:**
|
|
324
|
+
|
|
325
|
+
- The test environment package is not installed
|
|
326
|
+
- This config specifies the environment but doesn't install it (peer dependency)
|
|
327
|
+
|
|
328
|
+
**Solution:**
|
|
329
|
+
|
|
330
|
+
Install the DOM environment package:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# For jsdom (more compatible, slower)
|
|
334
|
+
npm install --save-dev jsdom
|
|
335
|
+
|
|
336
|
+
# Or for happy-dom (faster, less compatible)
|
|
337
|
+
npm install --save-dev happy-dom
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Then specify in your config if different from default:
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
// vitest.config.ts
|
|
344
|
+
import { defineConfig } from 'vitest/config';
|
|
345
|
+
import vitestConfig from '@jmlweb/vitest-config';
|
|
346
|
+
|
|
347
|
+
export default defineConfig({
|
|
348
|
+
...vitestConfig,
|
|
349
|
+
test: {
|
|
350
|
+
...vitestConfig.test,
|
|
351
|
+
environment: 'jsdom', // or 'happy-dom'
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### Coverage Not Working
|
|
357
|
+
|
|
358
|
+
**Symptoms:**
|
|
359
|
+
|
|
360
|
+
- No coverage reports generated
|
|
361
|
+
- Coverage command runs but shows no output
|
|
362
|
+
|
|
363
|
+
**Cause:**
|
|
364
|
+
|
|
365
|
+
- Coverage provider not installed
|
|
366
|
+
- Coverage not enabled in configuration
|
|
367
|
+
|
|
368
|
+
**Solution:**
|
|
369
|
+
|
|
370
|
+
Install the coverage provider:
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
npm install --save-dev @vitest/coverage-v8
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Run tests with coverage flag:
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
vitest --coverage
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Test Files Not Found
|
|
383
|
+
|
|
384
|
+
**Symptoms:**
|
|
385
|
+
|
|
386
|
+
- "No test files found" even though test files exist
|
|
387
|
+
- Vitest doesn't pick up `*.test.ts` or `*.spec.ts` files
|
|
388
|
+
|
|
389
|
+
**Cause:**
|
|
390
|
+
|
|
391
|
+
- Test file pattern mismatch
|
|
392
|
+
- Files in excluded directories
|
|
393
|
+
|
|
394
|
+
**Solution:**
|
|
395
|
+
|
|
396
|
+
This config includes common patterns. If your tests aren't found, check:
|
|
397
|
+
|
|
398
|
+
1. File naming: Use `.test.ts`, `.spec.ts`, `.test.tsx`, or `.spec.tsx`
|
|
399
|
+
2. Location: Ensure tests aren't in `node_modules` or `dist`
|
|
400
|
+
3. Explicitly include test patterns:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
// vitest.config.ts
|
|
404
|
+
import { defineConfig } from 'vitest/config';
|
|
405
|
+
import vitestConfig from '@jmlweb/vitest-config';
|
|
406
|
+
|
|
407
|
+
export default defineConfig({
|
|
408
|
+
...vitestConfig,
|
|
409
|
+
test: {
|
|
410
|
+
...vitestConfig.test,
|
|
411
|
+
include: ['**/*.{test,spec}.{ts,tsx}'],
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## 🔄 Migration Guide
|
|
417
|
+
|
|
418
|
+
### Upgrading to a New Version
|
|
419
|
+
|
|
420
|
+
> **Note:** If no breaking changes were introduced in a version, it's safe to upgrade without additional steps.
|
|
421
|
+
|
|
422
|
+
**No breaking changes have been introduced yet.** This package follows semantic versioning. When breaking changes are introduced, detailed migration instructions will be provided here.
|
|
423
|
+
|
|
424
|
+
For version history, see the [Changelog](./CHANGELOG.md).
|
|
425
|
+
|
|
426
|
+
**Need Help?** If you encounter issues during migration, please [open an issue](https://github.com/jmlweb/tooling/issues/new).
|
|
427
|
+
|
|
428
|
+
## 📜 Changelog
|
|
429
|
+
|
|
430
|
+
See [CHANGELOG.md](./CHANGELOG.md) for version history and release notes.
|
|
431
|
+
|
|
268
432
|
## 📄 License
|
|
269
433
|
|
|
270
434
|
MIT
|
package/package.json
CHANGED