@uiverify/vitest 1.0.2 → 1.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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  autoSnapshot,
3
3
  beginTest
4
- } from "./chunk-W4AFNW3N.js";
4
+ } from "./chunk-YDH23IMH.js";
5
5
 
6
6
  // src/browser-setup.ts
7
7
  import { afterEach, beforeEach, inject } from "vitest";
@@ -26,7 +26,7 @@ function snapshotIds(task, name) {
26
26
  // package.json
27
27
  var package_default = {
28
28
  name: "@uiverify/vitest",
29
- version: "1.0.2",
29
+ version: "1.1.0",
30
30
  description: "Vitest browser-mode capture SDK for UI Verify (uiverify.ai): add uiverifyPlugin() to your Vitest config and each browser-mode test archives its final DOM (serialized DOM + resource bytes) to be replayed + visually diffed by UI Verify. Produces an archive the uiverify CLI uploads; talks to nothing at runtime.",
31
31
  keywords: [
32
32
  "visual-testing",
@@ -164,7 +164,11 @@ async function capture(task, name) {
164
164
  colorScheme,
165
165
  dom,
166
166
  resources,
167
- producer: PRODUCER
167
+ producer: PRODUCER,
168
+ // The test file (project-root-relative), so UI Verify can locate this snapshot in the module graph
169
+ // for skip-unchanged. `task.file.name` is already root-relative — the same value snapshot ids derive
170
+ // their first segment from — so it lines up with the graph names the reporter emits.
171
+ ...task.file?.name ? { sourcePath: task.file.name } : {}
168
172
  };
169
173
  await commands.__uiverifyWriteSnapshot(archived);
170
174
  return id;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  disableAutoSnapshot,
3
3
  takeSnapshot
4
- } from "./chunk-W4AFNW3N.js";
4
+ } from "./chunk-YDH23IMH.js";
5
5
  export {
6
6
  disableAutoSnapshot,
7
7
  takeSnapshot
package/dist/plugin.js CHANGED
@@ -31,6 +31,115 @@ function writeSnapshot(outDir, snapshot) {
31
31
  import fs2 from "fs";
32
32
  import path3 from "path";
33
33
 
34
+ // src/graph-reporter.ts
35
+ import fs3 from "fs";
36
+ import path5 from "path";
37
+
38
+ // src/preview-stats.ts
39
+ import path4 from "path";
40
+ function toRepoRel(viteRoot, raw) {
41
+ if (!raw) return null;
42
+ const p = raw.replace(/\?.*$/, "");
43
+ if (p.includes("\0") || p.startsWith("virtual:")) return null;
44
+ if (!path4.isAbsolute(p)) return null;
45
+ if (/(^|[/\\])node_modules[/\\]/.test(p)) return null;
46
+ return path4.relative(viteRoot, p).split(path4.sep).join("/");
47
+ }
48
+ function buildPreviewStats(input) {
49
+ const reasonsByName = /* @__PURE__ */ new Map();
50
+ const ensure = (name) => {
51
+ let set = reasonsByName.get(name);
52
+ if (!set) reasonsByName.set(name, set = /* @__PURE__ */ new Set());
53
+ return set;
54
+ };
55
+ for (const mod of input.modules) {
56
+ const name = toRepoRel(input.viteRoot, mod.file ?? mod.id);
57
+ if (name === null) continue;
58
+ const reasons = ensure(name);
59
+ for (const imp of mod.importers ?? []) {
60
+ const r = toRepoRel(input.viteRoot, imp.file ?? imp.id);
61
+ if (r !== null && r !== name) reasons.add(r);
62
+ }
63
+ }
64
+ const testNames = input.testFiles.map((f) => toRepoRel(input.viteRoot, f)).filter((n) => n !== null);
65
+ for (const sf of input.setupFiles) {
66
+ const name = toRepoRel(input.viteRoot, sf);
67
+ if (name === null) continue;
68
+ const reasons = ensure(name);
69
+ for (const t of testNames) if (t !== name) reasons.add(t);
70
+ }
71
+ return {
72
+ modules: [...reasonsByName].map(([name, reasons]) => ({
73
+ name,
74
+ reasons: [...reasons].map((moduleName) => ({ moduleName }))
75
+ }))
76
+ };
77
+ }
78
+
79
+ // src/graph-reporter.ts
80
+ function collectModules(map, out) {
81
+ if (typeof map?.forEach !== "function") return;
82
+ map.forEach((mod) => out.push(mod));
83
+ }
84
+ function buildStatsFromRun(vitest, testModules) {
85
+ const projects = vitest?.projects ?? [];
86
+ if (projects.length === 0) return null;
87
+ const testFilesByProject = /* @__PURE__ */ new Map();
88
+ for (const tm of testModules ?? []) {
89
+ if (!tm.project || !tm.moduleId) continue;
90
+ const arr = testFilesByProject.get(tm.project) ?? [];
91
+ arr.push(tm.moduleId);
92
+ testFilesByProject.set(tm.project, arr);
93
+ }
94
+ const reasonsByName = /* @__PURE__ */ new Map();
95
+ let any = false;
96
+ for (const project of projects) {
97
+ const vite = project.browser?.vite;
98
+ const viteRoot = vite?.config?.root;
99
+ if (!vite || !viteRoot) continue;
100
+ const modules = [];
101
+ collectModules((vite.environments?.client?.moduleGraph ?? vite.moduleGraph)?.idToModuleMap, modules);
102
+ if (modules.length === 0) continue;
103
+ const testFiles = [.../* @__PURE__ */ new Set([...testFilesByProject.get(project) ?? [], ...project.testFilesList ?? []])];
104
+ const stats = buildPreviewStats({ viteRoot, modules, setupFiles: project.config?.setupFiles ?? [], testFiles });
105
+ for (const m of stats.modules) {
106
+ let set = reasonsByName.get(m.name);
107
+ if (!set) reasonsByName.set(m.name, set = /* @__PURE__ */ new Set());
108
+ for (const r of m.reasons) set.add(r.moduleName);
109
+ }
110
+ any = true;
111
+ }
112
+ if (!any) return null;
113
+ return {
114
+ modules: [...reasonsByName].map(([name, reasons]) => ({
115
+ name,
116
+ reasons: [...reasons].map((moduleName) => ({ moduleName }))
117
+ }))
118
+ };
119
+ }
120
+ function emitModuleGraph(outDir, vitest, testModules) {
121
+ const stats = buildStatsFromRun(vitest, testModules);
122
+ if (!stats) return false;
123
+ fs3.mkdirSync(outDir, { recursive: true });
124
+ fs3.writeFileSync(path5.join(outDir, "preview-stats.json"), JSON.stringify(stats));
125
+ return true;
126
+ }
127
+ function graphReporter(outDir) {
128
+ let vitest;
129
+ return {
130
+ onInit(ctx) {
131
+ vitest = ctx;
132
+ },
133
+ onTestRunEnd(testModules) {
134
+ try {
135
+ emitModuleGraph(outDir, vitest, testModules);
136
+ } catch (err) {
137
+ console.warn("[uiverify] could not emit the module graph for --only-changed:", err);
138
+ }
139
+ }
140
+ };
141
+ }
142
+
34
143
  // src/plugin.ts
35
144
  var SETUP_MODULE = "@uiverify/vitest/browser-setup";
36
145
  function uiverifyPlugin(options = {}) {
@@ -44,6 +153,11 @@ function uiverifyPlugin(options = {}) {
44
153
  optimizeDeps: { exclude: ["@uiverify/vitest"] },
45
154
  test: {
46
155
  setupFiles: [SETUP_MODULE],
156
+ // Emit Vite's module graph as `preview-stats.json` so `uiverify upload --only-changed` can skip
157
+ // unchanged snapshots. `"default"` is kept so the plugin doesn't silence Vitest's own output. If a
158
+ // user's own `reporters` config ends up displacing this, the only effect is that no graph ships and
159
+ // the server safely renders everything — add `graphReporter()` back to keep the skip savings.
160
+ reporters: ["default", graphReporter(outDir)],
47
161
  provide: { __uiverify: { disableAutoSnapshot: options.disableAutoSnapshot ?? false } },
48
162
  browser: {
49
163
  commands: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiverify/vitest",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Vitest browser-mode capture SDK for UI Verify (uiverify.ai): add uiverifyPlugin() to your Vitest config and each browser-mode test archives its final DOM (serialized DOM + resource bytes) to be replayed + visually diffed by UI Verify. Produces an archive the uiverify CLI uploads; talks to nothing at runtime.",
5
5
  "keywords": [
6
6
  "visual-testing",