@helderberto/vitest-config 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Helder Berto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # @helderberto/vitest-config
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@helderberto/vitest-config)](https://www.npmjs.com/package/@helderberto/vitest-config)
4
+
5
+ Vitest presets for the `node-app`, `react-app`, `react-library` and `ts-library` profiles.
6
+
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`.
package/dist/base.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { ViteUserConfig } from 'vitest/config';
2
+ export declare const base: ViteUserConfig;
package/dist/base.js ADDED
@@ -0,0 +1,10 @@
1
+ export const base = {
2
+ test: {
3
+ globals: true,
4
+ mockReset: true,
5
+ restoreMocks: true,
6
+ unstubEnvs: true,
7
+ unstubGlobals: true,
8
+ coverage: { provider: 'v8' },
9
+ },
10
+ };
@@ -0,0 +1 @@
1
+ export { base as nodeApp } from './base.ts';
@@ -0,0 +1 @@
1
+ export { base as nodeApp } from './base.js';
@@ -0,0 +1 @@
1
+ export { react as reactApp } from './react.ts';
@@ -0,0 +1 @@
1
+ export { react as reactApp } from './react.js';
@@ -0,0 +1 @@
1
+ export { react as reactLibrary } from './react.ts';
@@ -0,0 +1 @@
1
+ export { react as reactLibrary } from './react.js';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/vitest';
@@ -0,0 +1,25 @@
1
+ import '@testing-library/jest-dom/vitest';
2
+ import { cleanup } from '@testing-library/react';
3
+ import { afterEach } from 'vitest';
4
+ // Testing Library registers its own cleanup only when a project keeps Vitest globals on.
5
+ afterEach(cleanup);
6
+ class NoopResizeObserver {
7
+ observe() { }
8
+ unobserve() { }
9
+ disconnect() { }
10
+ }
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
+ }
@@ -0,0 +1,2 @@
1
+ import type { ViteUserConfig } from 'vitest/config';
2
+ export declare const react: ViteUserConfig;
package/dist/react.js ADDED
@@ -0,0 +1,12 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { base } from './base.js';
3
+ // Resolved through the exports map so the path points into dist under npm and pnpm alike.
4
+ const setupFile = fileURLToPath(import.meta.resolve('@helderberto/vitest-config/react-setup'));
5
+ export const react = {
6
+ ...base,
7
+ test: {
8
+ ...base.test,
9
+ environment: 'jsdom',
10
+ setupFiles: [setupFile],
11
+ },
12
+ };
@@ -0,0 +1 @@
1
+ export { base as tsLibrary } from './base.ts';
@@ -0,0 +1 @@
1
+ export { base as tsLibrary } from './base.js';
package/package.json CHANGED
@@ -1,6 +1,81 @@
1
1
  {
2
2
  "name": "@helderberto/vitest-config",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/helderberto/coding-standards.git",
9
+ "directory": "packages/vitest-config"
10
+ },
11
+ "exports": {
12
+ "./node-app": {
13
+ "types": "./dist/node-app.d.ts",
14
+ "default": "./dist/node-app.js"
15
+ },
16
+ "./react-app": {
17
+ "types": "./dist/react-app.d.ts",
18
+ "default": "./dist/react-app.js"
19
+ },
20
+ "./react-library": {
21
+ "types": "./dist/react-library.d.ts",
22
+ "default": "./dist/react-library.js"
23
+ },
24
+ "./ts-library": {
25
+ "types": "./dist/ts-library.d.ts",
26
+ "default": "./dist/ts-library.js"
27
+ },
28
+ "./react-setup": {
29
+ "types": "./dist/react-setup.d.ts",
30
+ "default": "./dist/react-setup.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "peerDependencies": {
37
+ "@testing-library/jest-dom": ">=8.0.0",
38
+ "@testing-library/react": ">=16.0.0",
39
+ "@vitest/coverage-v8": ">=5.0.0",
40
+ "jsdom": ">=26.0.0",
41
+ "vitest": ">=5.0.0"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "@testing-library/jest-dom": {
45
+ "optional": true
46
+ },
47
+ "@testing-library/react": {
48
+ "optional": true
49
+ },
50
+ "@vitest/coverage-v8": {
51
+ "optional": true
52
+ },
53
+ "jsdom": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@helderberto/tsconfig": "0.1.0",
59
+ "@testing-library/dom": "10.4.2",
60
+ "@testing-library/jest-dom": "8.0.0",
61
+ "@testing-library/react": "16.3.3",
62
+ "@types/node": "26.6.11",
63
+ "@types/react": "19.3.3",
64
+ "@types/react-dom": "19.3.0",
65
+ "@vitest/coverage-v8": "5.1.2",
66
+ "jsdom": "31.0.1",
67
+ "react": "19.3.1",
68
+ "react-dom": "19.3.1",
69
+ "vitest": "5.1.2"
70
+ },
71
+ "engines": {
72
+ "node": ">=22"
73
+ },
74
+ "publishConfig": {
75
+ "access": "public"
76
+ },
77
+ "scripts": {
78
+ "build": "tsc -p tsconfig.build.json",
79
+ "typecheck": "tsc"
80
+ }
6
81
  }