@theholocron/vitest-config 6.1.1 → 7.1.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.
@@ -0,0 +1,35 @@
1
+ //#region bundles/library.d.ts
2
+ /**
3
+ * Vitest bundle for published Node.js libraries.
4
+ * Includes coverage with an 80% threshold on all metrics.
5
+ *
6
+ * Accepts per-file threshold overrides via `thresholds` in options:
7
+ *
8
+ * ```js
9
+ * library({ thresholds: { "src/generated.ts": { lines: 0, functions: 0, branches: 0, statements: 0 } } })
10
+ * ```
11
+ *
12
+ * @param {{ thresholds?: import('vitest/config').CoverageV8Options['thresholds'], [key: string]: unknown }} [options]
13
+ * @returns {import('vitest/config').UserProjectConfig}
14
+ */
15
+ declare function library({ thresholds: thresholdOverrides, ...rest }?: {}): {
16
+ test: {
17
+ coverage: {
18
+ provider: string;
19
+ include: string[];
20
+ exclude: string[];
21
+ thresholds: any;
22
+ };
23
+ environment: string;
24
+ include: string[];
25
+ exclude: string[];
26
+ reporters: string[];
27
+ outputFile: {
28
+ junit: string;
29
+ };
30
+ };
31
+ };
32
+ /** Ready-to-use config for packages that need no customisation. */
33
+ declare const _default: import("vite").UserConfig & Promise<import("vite").UserConfig> & (import("vitest/config").ViteUserConfigFnObject & (import("vitest/config").ViteUserConfigFnPromise & import("vitest/config").ViteUserConfigExport));
34
+ //#endregion
35
+ export { _default as default, library };
@@ -0,0 +1,47 @@
1
+ import { node } from "../presets/node.js";
2
+ import { defineConfig } from "vitest/config";
3
+ //#region bundles/library.ts
4
+ /**
5
+ * Vitest bundle for published Node.js libraries.
6
+ * Includes coverage with an 80% threshold on all metrics.
7
+ *
8
+ * Accepts per-file threshold overrides via `thresholds` in options:
9
+ *
10
+ * ```js
11
+ * library({ thresholds: { "src/generated.ts": { lines: 0, functions: 0, branches: 0, statements: 0 } } })
12
+ * ```
13
+ *
14
+ * @param {{ thresholds?: import('vitest/config').CoverageV8Options['thresholds'], [key: string]: unknown }} [options]
15
+ * @returns {import('vitest/config').UserProjectConfig}
16
+ */
17
+ function library({ thresholds: thresholdOverrides, ...rest } = {}) {
18
+ const base = node(rest);
19
+ return {
20
+ ...base,
21
+ test: {
22
+ ...base.test,
23
+ coverage: {
24
+ provider: "v8",
25
+ include: ["src/**/*.ts"],
26
+ exclude: [
27
+ "src/**/__tests__/**",
28
+ "src/**/*.{test,spec}.ts",
29
+ "src/index.ts",
30
+ "**/node_modules/**",
31
+ "**/dist/**"
32
+ ],
33
+ thresholds: {
34
+ lines: 80,
35
+ branches: 80,
36
+ functions: 80,
37
+ statements: 80,
38
+ ...thresholdOverrides
39
+ }
40
+ }
41
+ }
42
+ };
43
+ }
44
+ /** Ready-to-use config for packages that need no customisation. */
45
+ var library_default = defineConfig(library());
46
+ //#endregion
47
+ export { library_default as default, library };
@@ -0,0 +1,33 @@
1
+ //#region bundles/react-app.d.ts
2
+ /**
3
+ * Vitest bundle for React applications.
4
+ * Includes jsdom environment and coverage with an 80% threshold.
5
+ *
6
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
7
+ * @returns {import('vitest/config').UserProjectConfig}
8
+ */
9
+ declare function reactApp(options?: {}): {
10
+ test: {
11
+ coverage: {
12
+ provider: string;
13
+ include: string[];
14
+ exclude: string[];
15
+ thresholds: {
16
+ lines: number;
17
+ branches: number;
18
+ functions: number;
19
+ statements: number;
20
+ };
21
+ };
22
+ environment: string;
23
+ globals: boolean;
24
+ include: string[];
25
+ exclude: string[];
26
+ reporters: string[];
27
+ outputFile: {
28
+ junit: string;
29
+ };
30
+ };
31
+ };
32
+ //#endregion
33
+ export { reactApp };
@@ -0,0 +1,36 @@
1
+ import { react } from "../presets/react.js";
2
+ //#region bundles/react-app.ts
3
+ /**
4
+ * Vitest bundle for React applications.
5
+ * Includes jsdom environment and coverage with an 80% threshold.
6
+ *
7
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
8
+ * @returns {import('vitest/config').UserProjectConfig}
9
+ */
10
+ function reactApp(options = {}) {
11
+ const base = react(options);
12
+ return {
13
+ ...base,
14
+ test: {
15
+ ...base.test,
16
+ coverage: {
17
+ provider: "v8",
18
+ include: ["src/**"],
19
+ exclude: [
20
+ "**/*.{test,spec}.*",
21
+ "**/*.{story,stories}.*",
22
+ "**/node_modules/**",
23
+ "**/dist/**"
24
+ ],
25
+ thresholds: {
26
+ lines: 80,
27
+ branches: 80,
28
+ functions: 80,
29
+ statements: 80
30
+ }
31
+ }
32
+ }
33
+ };
34
+ }
35
+ //#endregion
36
+ export { reactApp };
@@ -0,0 +1,4 @@
1
+ import { node } from "./presets/node.js";
2
+ import { react } from "./presets/react.js";
3
+ import { storybook } from "./presets/storybook.js";
4
+ export { node, react, storybook };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { node } from "./presets/node.js";
2
+ import { react } from "./presets/react.js";
3
+ import { storybook } from "./presets/storybook.js";
4
+ export { node, react, storybook };
@@ -0,0 +1,21 @@
1
+ //#region presets/node.d.ts
2
+ /**
3
+ * Vitest preset for Node.js libraries and CLI tools.
4
+ * No DOM globals; runs tests in the Node environment.
5
+ *
6
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
7
+ * @returns {import('vitest/config').UserProjectConfig}
8
+ */
9
+ declare function node(options?: {}): {
10
+ test: {
11
+ environment: string;
12
+ include: string[];
13
+ exclude: string[];
14
+ reporters: string[];
15
+ outputFile: {
16
+ junit: string;
17
+ };
18
+ };
19
+ };
20
+ //#endregion
21
+ export { node };
@@ -0,0 +1,20 @@
1
+ //#region presets/node.ts
2
+ /**
3
+ * Vitest preset for Node.js libraries and CLI tools.
4
+ * No DOM globals; runs tests in the Node environment.
5
+ *
6
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
7
+ * @returns {import('vitest/config').UserProjectConfig}
8
+ */
9
+ function node(options = {}) {
10
+ return { test: {
11
+ environment: "node",
12
+ include: ["**/*.{test,spec}.{js,ts,mjs}"],
13
+ exclude: ["**/node_modules/**", "**/dist/**"],
14
+ reporters: ["default", "junit"],
15
+ outputFile: { junit: "./test-report.junit.xml" },
16
+ ...options
17
+ } };
18
+ }
19
+ //#endregion
20
+ export { node };
@@ -0,0 +1,22 @@
1
+ //#region presets/react.d.ts
2
+ /**
3
+ * Vitest preset for React component libraries and apps.
4
+ * Uses jsdom for DOM simulation and assumes @testing-library/react.
5
+ *
6
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
7
+ * @returns {import('vitest/config').UserProjectConfig}
8
+ */
9
+ declare function react(options?: {}): {
10
+ test: {
11
+ environment: string;
12
+ globals: boolean;
13
+ include: string[];
14
+ exclude: string[];
15
+ reporters: string[];
16
+ outputFile: {
17
+ junit: string;
18
+ };
19
+ };
20
+ };
21
+ //#endregion
22
+ export { react };
@@ -0,0 +1,25 @@
1
+ //#region presets/react.ts
2
+ /**
3
+ * Vitest preset for React component libraries and apps.
4
+ * Uses jsdom for DOM simulation and assumes @testing-library/react.
5
+ *
6
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
7
+ * @returns {import('vitest/config').UserProjectConfig}
8
+ */
9
+ function react(options = {}) {
10
+ return { test: {
11
+ environment: "jsdom",
12
+ globals: true,
13
+ include: ["**/*.{test,spec}.{js,jsx,ts,tsx}"],
14
+ exclude: [
15
+ "**/node_modules/**",
16
+ "**/dist/**",
17
+ "**/*.{story,stories}.{js,jsx,ts,tsx}"
18
+ ],
19
+ reporters: ["default", "junit"],
20
+ outputFile: { junit: "./test-report.junit.xml" },
21
+ ...options
22
+ } };
23
+ }
24
+ //#endregion
25
+ export { react };
@@ -0,0 +1,25 @@
1
+ //#region presets/storybook.d.ts
2
+ /**
3
+ * Vitest preset for Storybook component testing via @storybook/addon-vitest.
4
+ * Runs stories as browser tests using Playwright.
5
+ *
6
+ * @param {string} [storybookDir='.storybook'] Path to the .storybook directory
7
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
8
+ * @returns {import('vitest/config').UserProjectConfig}
9
+ */
10
+ declare function storybook(storybookDir?: string, options?: {}): Promise<{
11
+ plugins: Promise<import("vite").Plugin<any>[]>[];
12
+ test: {
13
+ name: string;
14
+ browser: {
15
+ enabled: boolean;
16
+ headless: boolean;
17
+ provider: string;
18
+ instances: {
19
+ browser: string;
20
+ }[];
21
+ };
22
+ };
23
+ }>;
24
+ //#endregion
25
+ export { storybook };
@@ -0,0 +1,27 @@
1
+ //#region presets/storybook.ts
2
+ /**
3
+ * Vitest preset for Storybook component testing via @storybook/addon-vitest.
4
+ * Runs stories as browser tests using Playwright.
5
+ *
6
+ * @param {string} [storybookDir='.storybook'] Path to the .storybook directory
7
+ * @param {import('vitest/config').UserProjectConfig['test']} [options]
8
+ * @returns {import('vitest/config').UserProjectConfig}
9
+ */
10
+ async function storybook(storybookDir = ".storybook", options = {}) {
11
+ const { storybookTest } = await import("@storybook/addon-vitest/vitest-plugin");
12
+ return {
13
+ plugins: [storybookTest({ storybookDir })],
14
+ test: {
15
+ name: "storybook",
16
+ browser: {
17
+ enabled: true,
18
+ headless: true,
19
+ provider: "playwright",
20
+ instances: [{ browser: "chromium" }]
21
+ },
22
+ ...options
23
+ }
24
+ };
25
+ }
26
+ //#endregion
27
+ export { storybook };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/vitest-config",
3
- "version": "6.1.1",
3
+ "version": "7.1.0",
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",
@@ -10,38 +10,56 @@
10
10
  },
11
11
  "license": "GPL-3.0",
12
12
  "author": "Newton Koumantzelis",
13
+ "keywords": [
14
+ "vitest",
15
+ "testing",
16
+ "coverage",
17
+ "typescript",
18
+ "config",
19
+ "theholocron"
20
+ ],
13
21
  "type": "module",
22
+ "devDependencies": {
23
+ "tsdown": "^0.22.8",
24
+ "typescript": "^5.9.3",
25
+ "vitest": "^4.0.0",
26
+ "@theholocron/tsconfig": "7.1.0"
27
+ },
14
28
  "exports": {
15
29
  ".": {
16
- "import": "./index.js",
17
- "default": "./index.js"
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js",
32
+ "default": "./dist/index.js"
18
33
  },
19
34
  "./node": {
20
- "import": "./presets/node.js",
21
- "default": "./presets/node.js"
35
+ "types": "./dist/presets/node.d.ts",
36
+ "import": "./dist/presets/node.js",
37
+ "default": "./dist/presets/node.js"
22
38
  },
23
39
  "./react": {
24
- "import": "./presets/react.js",
25
- "default": "./presets/react.js"
40
+ "types": "./dist/presets/react.d.ts",
41
+ "import": "./dist/presets/react.js",
42
+ "default": "./dist/presets/react.js"
26
43
  },
27
44
  "./storybook": {
28
- "import": "./presets/storybook.js",
29
- "default": "./presets/storybook.js"
45
+ "types": "./dist/presets/storybook.d.ts",
46
+ "import": "./dist/presets/storybook.js",
47
+ "default": "./dist/presets/storybook.js"
30
48
  },
31
49
  "./bundles/library": {
32
- "import": "./bundles/library.js",
33
- "default": "./bundles/library.js"
50
+ "types": "./dist/bundles/library.d.ts",
51
+ "import": "./dist/bundles/library.js",
52
+ "default": "./dist/bundles/library.js"
34
53
  },
35
54
  "./bundles/react-app": {
36
- "import": "./bundles/react-app.js",
37
- "default": "./bundles/react-app.js"
55
+ "types": "./dist/bundles/react-app.d.ts",
56
+ "import": "./dist/bundles/react-app.js",
57
+ "default": "./dist/bundles/react-app.js"
38
58
  },
39
59
  "./package.json": "./package.json"
40
60
  },
41
61
  "files": [
42
- "index.js",
43
- "presets/",
44
- "bundles/"
62
+ "dist/"
45
63
  ],
46
64
  "peerDependencies": {
47
65
  "vitest": "^4",
@@ -76,9 +94,17 @@
76
94
  "optional": true
77
95
  }
78
96
  },
97
+ "engines": {
98
+ "node": ">=22.0.0"
99
+ },
79
100
  "publishConfig": {
80
101
  "access": "public"
81
102
  },
82
103
  "releases": "https://github.com/theholocron/configs/releases",
83
- "wiki": "https://github.com/theholocron/configs/wiki"
104
+ "wiki": "https://github.com/theholocron/configs/wiki",
105
+ "scripts": {
106
+ "build": "tsdown",
107
+ "typecheck": "tsc --noEmit",
108
+ "test": "vitest run"
109
+ }
84
110
  }
@@ -1,47 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
- import { node } from "../presets/node.js";
3
-
4
- /**
5
- * Vitest bundle for published Node.js libraries.
6
- * Includes coverage with an 80% threshold on all metrics.
7
- *
8
- * Accepts per-file threshold overrides via `thresholds` in options:
9
- *
10
- * ```js
11
- * library({ thresholds: { "src/generated.ts": { lines: 0, functions: 0, branches: 0, statements: 0 } } })
12
- * ```
13
- *
14
- * @param {{ thresholds?: import('vitest/config').CoverageV8Options['thresholds'], [key: string]: unknown }} [options]
15
- * @returns {import('vitest/config').UserProjectConfig}
16
- */
17
- export function library({ thresholds: thresholdOverrides, ...rest } = {}) {
18
- const base = node(rest);
19
-
20
- return {
21
- ...base,
22
- test: {
23
- ...base.test,
24
- coverage: {
25
- provider: "v8",
26
- include: ["src/**/*.ts"],
27
- exclude: [
28
- "src/**/__tests__/**",
29
- "src/**/*.{test,spec}.ts",
30
- "src/index.ts",
31
- "**/node_modules/**",
32
- "**/dist/**",
33
- ],
34
- thresholds: {
35
- lines: 80,
36
- branches: 80,
37
- functions: 80,
38
- statements: 80,
39
- ...thresholdOverrides,
40
- },
41
- },
42
- },
43
- };
44
- }
45
-
46
- /** Ready-to-use config for packages that need no customisation. */
47
- export default defineConfig(library());
@@ -1,35 +0,0 @@
1
- import { react } from "../presets/react.js";
2
-
3
- /**
4
- * Vitest bundle for React applications.
5
- * Includes jsdom environment and coverage with an 80% threshold.
6
- *
7
- * @param {import('vitest/config').UserProjectConfig['test']} [options]
8
- * @returns {import('vitest/config').UserProjectConfig}
9
- */
10
- export function reactApp(options = {}) {
11
- const base = react(options);
12
-
13
- return {
14
- ...base,
15
- test: {
16
- ...base.test,
17
- coverage: {
18
- provider: "v8",
19
- include: ["src/**"],
20
- exclude: [
21
- "**/*.{test,spec}.*",
22
- "**/*.{story,stories}.*",
23
- "**/node_modules/**",
24
- "**/dist/**",
25
- ],
26
- thresholds: {
27
- lines: 80,
28
- branches: 80,
29
- functions: 80,
30
- statements: 80,
31
- },
32
- },
33
- },
34
- };
35
- }
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { node } from "./presets/node.js";
2
- export { react } from "./presets/react.js";
3
- export { storybook } from "./presets/storybook.js";
package/presets/node.js DELETED
@@ -1,21 +0,0 @@
1
- /**
2
- * Vitest preset for Node.js libraries and CLI tools.
3
- * No DOM globals; runs tests in the Node environment.
4
- *
5
- * @param {import('vitest/config').UserProjectConfig['test']} [options]
6
- * @returns {import('vitest/config').UserProjectConfig}
7
- */
8
- export function node(options = {}) {
9
- return {
10
- test: {
11
- environment: "node",
12
- include: ["**/*.{test,spec}.{js,ts,mjs}"],
13
- exclude: ["**/node_modules/**", "**/dist/**"],
14
- reporters: ["default", "junit"],
15
- outputFile: {
16
- junit: "./test-report.junit.xml",
17
- },
18
- ...options,
19
- },
20
- };
21
- }
package/presets/react.js DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Vitest preset for React component libraries and apps.
3
- * Uses jsdom for DOM simulation and assumes @testing-library/react.
4
- *
5
- * @param {import('vitest/config').UserProjectConfig['test']} [options]
6
- * @returns {import('vitest/config').UserProjectConfig}
7
- */
8
- export function react(options = {}) {
9
- return {
10
- test: {
11
- environment: "jsdom",
12
- globals: true,
13
- include: ["**/*.{test,spec}.{js,jsx,ts,tsx}"],
14
- exclude: [
15
- "**/node_modules/**",
16
- "**/dist/**",
17
- "**/*.{story,stories}.{js,jsx,ts,tsx}",
18
- ],
19
- reporters: ["default", "junit"],
20
- outputFile: {
21
- junit: "./test-report.junit.xml",
22
- },
23
- ...options,
24
- },
25
- };
26
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Vitest preset for Storybook component testing via @storybook/addon-vitest.
3
- * Runs stories as browser tests using Playwright.
4
- *
5
- * @param {string} [storybookDir='.storybook'] Path to the .storybook directory
6
- * @param {import('vitest/config').UserProjectConfig['test']} [options]
7
- * @returns {import('vitest/config').UserProjectConfig}
8
- */
9
- export async function storybook(storybookDir = ".storybook", options = {}) {
10
- const { storybookTest } =
11
- await import("@storybook/addon-vitest/vitest-plugin");
12
-
13
- return {
14
- plugins: [storybookTest({ storybookDir })],
15
- test: {
16
- name: "storybook",
17
- browser: {
18
- enabled: true,
19
- headless: true,
20
- provider: "playwright",
21
- instances: [{ browser: "chromium" }],
22
- },
23
- ...options,
24
- },
25
- };
26
- }