@vitejs/devtools-vitest 0.4.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) 2025-present, VoidZero Inc. and contributors
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.
@@ -0,0 +1,4 @@
1
+ //#region src/dirs.d.ts
2
+ declare const clientPublicDir: string;
3
+ //#endregion
4
+ export { clientPublicDir };
package/dist/dirs.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { fileURLToPath } from "node:url";
2
+ //#region src/dirs.ts
3
+ const clientPublicDir = fileURLToPath(new URL("../public", import.meta.url));
4
+ //#endregion
5
+ export { clientPublicDir };
@@ -0,0 +1,16 @@
1
+ import { PluginWithDevTools } from "@vitejs/devtools-kit";
2
+ //#region src/node/plugin.d.ts
3
+ /**
4
+ * A slim launcher for the Vitest UI, surfaced in the "Vite+" dock group.
5
+ *
6
+ * The dock only appears when the project depends on `vitest`. Clicking it
7
+ * installs `@vitest/ui` on demand (as a devDependency), spawns `vitest --ui`
8
+ * on a free port, streams the startup output as a digest, then swaps the dock
9
+ * entry to an iframe embedding Vitest's own UI once the server is ready.
10
+ *
11
+ * This is the canonical "run commands, start a server, then embed it" launcher
12
+ * built on the kit's `createProcessLauncher`.
13
+ */
14
+ declare function DevToolsVitestUI(): PluginWithDevTools;
15
+ //#endregion
16
+ export { DevToolsVitestUI };
package/dist/index.mjs ADDED
@@ -0,0 +1,123 @@
1
+ import { clientPublicDir } from "./dirs.mjs";
2
+ import process from "node:process";
3
+ import { DEVTOOLS_VITEPLUS_GROUP_ID } from "@vitejs/devtools-kit/constants";
4
+ import { createProcessLauncher } from "@vitejs/devtools-kit/node";
5
+ import { getPort } from "get-port-please";
6
+ import { isPackageExists } from "local-pkg";
7
+ import { addDependency } from "nypm";
8
+ import { createConsoleReporter, defineDiagnostics } from "nostics";
9
+ //#region src/node/diagnostics.ts
10
+ const diagnostics = /* #__PURE__ */ defineDiagnostics({
11
+ docsBase: "https://devtools.vite.dev/errors",
12
+ reporters: [createConsoleReporter()],
13
+ codes: {
14
+ VTDT0001: {
15
+ why: (p) => `Failed to install \`@vitest/ui\`: ${p.error}`,
16
+ fix: "Install it manually with your package manager, e.g. `npm i -D @vitest/ui`, then launch again."
17
+ },
18
+ VTDT0002: {
19
+ why: (p) => `Vitest UI server did not become reachable at ${p.url} within ${p.timeout}ms.`,
20
+ fix: "Check the Vitest UI terminal session for startup errors, then launch again."
21
+ }
22
+ }
23
+ });
24
+ //#endregion
25
+ //#region src/node/plugin.ts
26
+ const VITEST_DEVTOOLS_BASE = "/__devtools-vitest/";
27
+ /** Path Vitest's own UI server serves its app under. */
28
+ const VITEST_UI_PATH = "__vitest__/";
29
+ /** Fixed terminal-session id so re-launches are idempotent. */
30
+ const SESSION_ID = "vitest:ui";
31
+ const DOCK_ID = "vitest";
32
+ const PREFERRED_PORT = 51204;
33
+ const READY_TIMEOUT = 3e4;
34
+ /**
35
+ * A slim launcher for the Vitest UI, surfaced in the "Vite+" dock group.
36
+ *
37
+ * The dock only appears when the project depends on `vitest`. Clicking it
38
+ * installs `@vitest/ui` on demand (as a devDependency), spawns `vitest --ui`
39
+ * on a free port, streams the startup output as a digest, then swaps the dock
40
+ * entry to an iframe embedding Vitest's own UI once the server is ready.
41
+ *
42
+ * This is the canonical "run commands, start a server, then embed it" launcher
43
+ * built on the kit's `createProcessLauncher`.
44
+ */
45
+ function DevToolsVitestUI() {
46
+ return {
47
+ name: "vite:devtools:vitest-ui",
48
+ devtools: { async setup(ctx) {
49
+ const cwd = ctx.cwd ?? process.cwd();
50
+ if (!isPackageExists("vitest", { paths: [cwd] })) return;
51
+ ctx.views.hostStatic(VITEST_DEVTOOLS_BASE, clientPublicDir);
52
+ const icon = `${VITEST_DEVTOOLS_BASE}favicon.svg`;
53
+ const hasUi = isPackageExists("@vitest/ui", { paths: [cwd] });
54
+ let url;
55
+ await createProcessLauncher({
56
+ id: DOCK_ID,
57
+ title: "Vitest",
58
+ groupId: DEVTOOLS_VITEPLUS_GROUP_ID,
59
+ icon,
60
+ label: "Vitest UI",
61
+ description: hasUi ? "Start the Vitest UI and view it inside DevTools." : "Install `@vitest/ui` (as a devDependency) and view it inside DevTools.",
62
+ buttonStart: hasUi ? "Start Vitest UI" : "Install @vitest/ui & start",
63
+ buttonLoading: "Starting Vitest UI…",
64
+ command: {
65
+ id: "vite:devtools:vitest:start-ui",
66
+ title: "Start Vitest UI",
67
+ icon
68
+ },
69
+ session: {
70
+ id: SESSION_ID,
71
+ title: "Vitest UI",
72
+ icon: "ph:terminal-window-duotone"
73
+ },
74
+ prepare: async () => {
75
+ if (!isPackageExists("@vitest/ui", { paths: [cwd] })) try {
76
+ await addDependency("@vitest/ui", {
77
+ cwd,
78
+ dev: true
79
+ });
80
+ } catch (error) {
81
+ throw diagnostics.VTDT0001({ error: error instanceof Error ? error.message : String(error) });
82
+ }
83
+ },
84
+ process: async () => {
85
+ const port = await getPort({
86
+ port: PREFERRED_PORT,
87
+ portRange: [PREFERRED_PORT, 51704]
88
+ });
89
+ url = `http://localhost:${port}/${VITEST_UI_PATH}`;
90
+ return {
91
+ command: "vitest",
92
+ args: [
93
+ "--ui",
94
+ "--no-open",
95
+ "--api.port",
96
+ String(port)
97
+ ],
98
+ cwd
99
+ };
100
+ },
101
+ serve: { onReady: async () => {
102
+ if (!await waitForServer(url, READY_TIMEOUT)) throw diagnostics.VTDT0002({
103
+ url,
104
+ timeout: READY_TIMEOUT
105
+ });
106
+ return url;
107
+ } }
108
+ }).devtools.setup(ctx);
109
+ } }
110
+ };
111
+ }
112
+ async function waitForServer(url, timeout) {
113
+ const start = Date.now();
114
+ while (Date.now() - start < timeout) {
115
+ try {
116
+ if ((await fetch(url)).status < 500) return true;
117
+ } catch {}
118
+ await new Promise((resolve) => setTimeout(resolve, 300));
119
+ }
120
+ return false;
121
+ }
122
+ //#endregion
123
+ export { DevToolsVitestUI };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@vitejs/devtools-vitest",
3
+ "type": "module",
4
+ "version": "0.4.1",
5
+ "description": "DevTools for Vitest",
6
+ "author": "VoidZero Inc.",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/vitejs/devtools#readme",
9
+ "repository": {
10
+ "directory": "packages/vitest",
11
+ "type": "git",
12
+ "url": "git+https://github.com/vitejs/devtools.git"
13
+ },
14
+ "bugs": "https://github.com/vitejs/devtools/issues",
15
+ "keywords": [
16
+ "vitest",
17
+ "devtools"
18
+ ],
19
+ "sideEffects": false,
20
+ "exports": {
21
+ ".": "./dist/index.mjs",
22
+ "./dirs": "./dist/dirs.mjs",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "types": "./dist/index.d.mts",
26
+ "files": [
27
+ "dist",
28
+ "public"
29
+ ],
30
+ "peerDependencies": {
31
+ "vitest": "*"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "vitest": {
35
+ "optional": true
36
+ }
37
+ },
38
+ "dependencies": {
39
+ "get-port-please": "^3.2.0",
40
+ "local-pkg": "^1.2.1",
41
+ "nostics": "^1.1.4",
42
+ "nypm": "^0.6.8",
43
+ "@vitejs/devtools-kit": "0.4.1"
44
+ },
45
+ "devDependencies": {
46
+ "tsdown": "^0.22.7"
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown"
50
+ }
51
+ }
@@ -0,0 +1,50 @@
1
+ <svg width="45" height="43" viewBox="0 0 45 43" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M21.2659 42.2067C20.9342 42.797 20.163 42.965 19.6137 42.5665L0.465308 28.6398C0.172341 28.4265 0 28.0862 0 27.7243V10.939C0 10.0148 1.04907 9.48061 1.79657 10.0235L13.5088 18.541C14.6031 19.3381 16.1476 18.9999 16.8111 17.8215L26.5113 0.577439C26.7117 0.222001 27.0887 0.00012207 27.498 0.00012207H43.0726C43.9385 0.00012207 44.4836 0.932876 44.0592 1.68683L21.2659 42.2046V42.2067Z" fill="#22FF84"/>
3
+ <mask id="mask0_2002_17204" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="45" height="43">
4
+ <path d="M21.2659 42.2066C20.9342 42.7968 20.163 42.9649 19.6137 42.5663L0.465308 28.6397C0.172341 28.4264 0 28.086 0 27.7241V10.9389C0 10.0147 1.04907 9.48049 1.79657 10.0233L13.5088 18.5409C14.6031 19.338 16.1476 18.9998 16.8111 17.8214L26.5113 0.577317C26.7117 0.221879 27.0887 0 27.498 0H43.0726C43.9385 0 44.4836 0.932754 44.0592 1.68671L21.2659 42.2044V42.2066Z" fill="black"/>
5
+ </mask>
6
+ <g mask="url(#mask0_2002_17204)">
7
+ <g filter="url(#filter0_f_2002_17204)">
8
+ <ellipse cx="14.0313" cy="3.39062" rx="14.0313" ry="3.39062" transform="matrix(-0.650066 0.759878 0.759879 0.650065 32.5093 -3.61884)" fill="#00CCC6"/>
9
+ </g>
10
+ <g filter="url(#filter1_f_2002_17204)">
11
+ <ellipse cx="14.0313" cy="6.0868" rx="14.0313" ry="6.0868" transform="matrix(-0.588245 -0.808682 -0.808682 0.588246 16.1094 37.5068)" fill="#00CCC6"/>
12
+ </g>
13
+ <g filter="url(#filter2_f_2002_17204)">
14
+ <ellipse cx="6.44313" cy="12.1953" rx="6.37416" ry="5.55082" transform="rotate(23.1293 6.44313 12.1953)" fill="#77FF00"/>
15
+ </g>
16
+ <g filter="url(#filter3_f_2002_17204)">
17
+ <ellipse cx="40.7746" cy="15.9509" rx="5.61461" ry="24.5343" transform="rotate(23.1293 40.7746 15.9509)" fill="#77FF00"/>
18
+ </g>
19
+ <g filter="url(#filter4_f_2002_17204)">
20
+ <ellipse cx="4.98534" cy="10.0691" rx="4.98534" ry="10.0691" transform="matrix(0.707107 -0.707107 -0.707107 -0.707107 39.4482 10.9414)" fill="#97FFE2"/>
21
+ </g>
22
+ </g>
23
+ <defs>
24
+ <filter id="filter0_f_2002_17204" x="7.29277" y="-10.8334" width="37.3432" height="40.1616" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
25
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
26
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
27
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
28
+ </filter>
29
+ <filter id="filter1_f_2002_17204" x="-15.8693" y="8.64781" width="37.6054" height="42.1854" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
30
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
31
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
32
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
33
+ </filter>
34
+ <filter id="filter2_f_2002_17204" x="-9.0041" y="-2.68275" width="30.8944" height="29.7561" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
35
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
36
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
37
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
38
+ </filter>
39
+ <filter id="filter3_f_2002_17204" x="20.6482" y="-15.9117" width="40.2528" height="63.7251" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
40
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
41
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
42
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
43
+ </filter>
44
+ <filter id="filter4_f_2002_17204" x="18.7156" y="-16.8414" width="34.2758" height="34.2754" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
45
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
46
+ <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
47
+ <feGaussianBlur stdDeviation="4.59556" result="effect1_foregroundBlur_2002_17204"/>
48
+ </filter>
49
+ </defs>
50
+ </svg>