@helderberto/vitest-config 0.1.0 → 0.1.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Helder Burato Berto
3
+ Copyright (c) 2026 Helder Berto
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,5 +1,69 @@
1
1
  # @helderberto/vitest-config
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@helderberto/vitest-config)](https://www.npmjs.com/package/@helderberto/vitest-config)
4
+
3
5
  Vitest presets for the `node-app`, `react-app`, `react-library` and `ts-library` profiles.
4
6
 
5
- Setup, profile by profile: [docs/usage.md](https://github.com/helderberto/coding-standards/blob/main/docs/usage.md).
7
+ Every preset turns globals on, resets mocks, env and globals between tests, and measures coverage with v8.
8
+
9
+ `node-app` and `ts-library` run in Node. `react-app` and `react-library` run in jsdom, with:
10
+
11
+ - jest-dom matchers
12
+ - Testing Library cleanup after each test
13
+ - `ResizeObserver`, `scrollIntoView` and `<dialog>` filled in where jsdom lacks them
14
+
15
+ ## Install
16
+
17
+ ```sh
18
+ npm install -D @helderberto/vitest-config vitest @vitest/coverage-v8
19
+ ```
20
+
21
+ React presets also need:
22
+
23
+ ```sh
24
+ npm install -D jsdom @testing-library/react @testing-library/dom @testing-library/jest-dom
25
+ ```
26
+
27
+ ## Use
28
+
29
+ ### `node-app`
30
+
31
+ ```ts
32
+ // vitest.config.ts
33
+ import { nodeApp } from '@helderberto/vitest-config/node-app';
34
+ import { defineConfig, mergeConfig } from 'vitest/config';
35
+
36
+ export default mergeConfig(nodeApp, defineConfig({}));
37
+ ```
38
+
39
+ ### `react-app`
40
+
41
+ ```ts
42
+ // vitest.config.ts
43
+ import { reactApp } from '@helderberto/vitest-config/react-app';
44
+ import { defineConfig, mergeConfig } from 'vitest/config';
45
+
46
+ export default mergeConfig(reactApp, defineConfig({}));
47
+ ```
48
+
49
+ ### `react-library`
50
+
51
+ ```ts
52
+ // vitest.config.ts
53
+ import { reactLibrary } from '@helderberto/vitest-config/react-library';
54
+ import { defineConfig, mergeConfig } from 'vitest/config';
55
+
56
+ export default mergeConfig(reactLibrary, defineConfig({}));
57
+ ```
58
+
59
+ ### `ts-library`
60
+
61
+ ```ts
62
+ // vitest.config.ts
63
+ import { tsLibrary } from '@helderberto/vitest-config/ts-library';
64
+ import { defineConfig, mergeConfig } from 'vitest/config';
65
+
66
+ export default mergeConfig(tsLibrary, defineConfig({}));
67
+ ```
68
+
69
+ Project settings, such as coverage thresholds, go in the second `defineConfig`.
@@ -8,12 +8,18 @@ class NoopResizeObserver {
8
8
  unobserve() { }
9
9
  disconnect() { }
10
10
  }
11
- globalThis.ResizeObserver ??= NoopResizeObserver;
12
- Element.prototype.scrollIntoView ??= () => { };
13
- HTMLDialogElement.prototype.showModal ??= function showModal() {
14
- this.open = true;
15
- };
16
- HTMLDialogElement.prototype.close ??= function close() {
17
- this.open = false;
18
- this.dispatchEvent(new Event('close'));
19
- };
11
+ function fillBrowserApis() {
12
+ globalThis.ResizeObserver ??= NoopResizeObserver;
13
+ Element.prototype.scrollIntoView ??= () => { };
14
+ HTMLDialogElement.prototype.showModal ??= function showModal() {
15
+ this.open = true;
16
+ };
17
+ HTMLDialogElement.prototype.close ??= function close() {
18
+ this.open = false;
19
+ this.dispatchEvent(new Event('close'));
20
+ };
21
+ }
22
+ // A test file can opt into `@vitest-environment node`, where there's no DOM to fill in.
23
+ if (typeof Element !== 'undefined') {
24
+ fillBrowserApis();
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helderberto/vitest-config",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {