@crvy/rprtr 0.0.5 → 0.0.8

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/CHANGELOG.md CHANGED
@@ -5,6 +5,71 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.8] - 2026-06-05
9
+
10
+ ### Fixed
11
+
12
+ - Broadcast test-begin events to UI and allow running→terminal status transitions
13
+ ## [0.0.7] - 2026-06-05
14
+
15
+ ### Ci
16
+
17
+ - Upgrade actions and node version for npm trusted publishing
18
+ ## [0.0.6] - 2026-06-05
19
+
20
+ ### Added
21
+
22
+ - Add named screenshot baseline resolver
23
+ - Resolve unnamed and duplicate screenshot baselines
24
+ - Resolve passed screenshot baselines through Playwright rules
25
+ - Persist approval resolver metadata in report state
26
+ - Emit approval resolver metadata from reporter
27
+ - Reuse resolver for approval routing
28
+ - Report mixed approval routing outcomes
29
+
30
+ ### Changed
31
+
32
+ - Separate resolver attachment and artifact names
33
+ - Tighten screenshot declaration typing
34
+
35
+ ### Documentation
36
+
37
+ - Add passed screenshot baseline resolution design
38
+ - Add passed screenshot baseline resolution plan
39
+ - Document passed screenshot baseline resolution options
40
+ - Narrow approval path claims
41
+ - Add template-aware approval routing design
42
+ - Add template-aware approval routing plan
43
+ - Align approval routing docs with resolver behavior
44
+ - Clarify approval routing configuration scope
45
+
46
+ ### Fixed
47
+
48
+ - Sanitize named screenshot resolver inputs
49
+ - Preserve visual names in named baseline targets
50
+ - Disambiguate named screenshot baseline resolution
51
+ - Restore reporter declaration compatibility
52
+ - Use safe artifact names for copied baselines
53
+ - Encode copied baseline artifact paths safely
54
+ - Neutralize traversal segments in baseline artifact paths
55
+ - Encode saved attachment artifact paths safely
56
+ - Use stable traversal-safe artifact path encoding
57
+ - Preserve approval metadata through schemas
58
+ - Preserve visual name fallback for older payloads
59
+ - Use configured testDir for approval resolution
60
+ - Use configured configDir for approval resolution
61
+ - Require POST for approve-all routing
62
+ - Require POST for approve routing
63
+ - Report no-actual bulk approval outcomes
64
+ - Honor approval api results in client state
65
+
66
+ ### Testing
67
+
68
+ - Cover exact approval routing cases
69
+
70
+ ### Ci
71
+
72
+ - Switch npm publish to OIDC trusted publishing
8
73
  ## [0.0.5] - 2026-05-14
9
74
 
10
75
  ### Added
package/README.md CHANGED
@@ -50,12 +50,15 @@ npx crvy-rprtr ./artifacts
50
50
 
51
51
  ## Reporter Options
52
52
 
53
- | Option | Type | Default | Description |
54
- | ------------------- | -------- | ------------------------------ | -------------------------------------------------- |
55
- | `serverUrl` | `string` | `"ws://localhost:3000"` | WebSocket URL of the Crvy Rprtr server |
56
- | `screenshotDir` | `string` | `"./screenshots"` | Directory for saving screenshot artifacts |
57
- | `offlineReportPath` | `string` | `"./crvy-rprtr-{worker}.json"` | Path for offline report when server is unavailable |
58
- | `reportHtmlPath` | `string` | `"./crvy-rprtr.html"` | Path for the browser-openable static report HTML |
53
+ | Option | Type | Default | Description |
54
+ | ---------------------------------------- | -------- | ------------------------------ | ------------------------------------------------------------------------------------------------------ |
55
+ | `serverUrl` | `string` | `"ws://localhost:3000"` | WebSocket URL of the Crvy Rprtr server |
56
+ | `screenshotDir` | `string` | `"./screenshots"` | Directory for saving screenshot artifacts |
57
+ | `offlineReportPath` | `string` | `"./crvy-rprtr-{worker}.json"` | Path for offline report when server is unavailable |
58
+ | `reportHtmlPath` | `string` | `"./crvy-rprtr.html"` | Path for the browser-openable static report HTML |
59
+ | `playwrightSnapshotDir` | `string` | `undefined` | Override the Playwright snapshot directory used for passed-baseline display lookup |
60
+ | `playwrightSnapshotPathTemplate` | `string` | `undefined` | Mirror Playwright `snapshotPathTemplate` for passed-baseline display resolution |
61
+ | `playwrightToHaveScreenshotPathTemplate` | `string` | `undefined` | Mirror Playwright `expect.toHaveScreenshot.pathTemplate` for passed-baseline display; takes precedence |
59
62
 
60
63
  ## Server CLI Options
61
64
 
@@ -77,12 +80,14 @@ Explicit flags override the paths derived from `artifact-dir`.
77
80
  | `--screenshot-dir` | `-s` | `./screenshots` | Screenshot directory path |
78
81
  | `--report-path` | `-r` | `./report.json` | Report JSON file path or directory containing `report.json` and `crvy-rprtr-*.json` files |
79
82
 
83
+ The CLI currently exposes only these flags. Approval-routing resolver overrides are available through the programmatic server API, not additional CLI flags.
84
+
80
85
  ## How It Works
81
86
 
82
87
  1. **During test runs:** The Playwright reporter sends test results to the server via WebSocket in real-time and records the same run for artifact export.
83
88
  2. **After tests complete:** A static `crvy-rprtr.html` artifact is written for direct browser viewing, and offline report JSON is also written if the server was unavailable.
84
89
  3. **In the browser:** The UI shows all screenshot tests with side-by-side, swap, slide, and blend diff views.
85
- 4. **Approving changes:** Start the UI server and click "Approve" to accept a new screenshot as the baseline. The server copies the actual image to the expected snapshot location.
90
+ 4. **Approving changes:** Start the UI server and click "Approve" or "Approve All" to accept a new screenshot as the baseline. Approval uses the same exact Playwright-aware resolver as passed-baseline display, including default layouts, unnamed screenshots, duplicate names, and custom templates when the running server was started with matching resolver options. Those approval-routing options are read from the server startup path, not from reporter options. If the server starts without explicit resolver overrides, approval falls back to the server defaults instead. If Crvy Rprtr cannot determine exactly one target path, it leaves the image unresolved instead of guessing.
86
91
 
87
92
  ## Offline Mode
88
93
 
@@ -97,8 +102,14 @@ When the server isn't running during tests, the reporter automatically falls bac
97
102
 
98
103
  Crvy Rprtr keeps passed Playwright screenshot assertions visible in two fallback modes when Playwright does not emit a full passing comparison payload:
99
104
 
100
- - `baseline-only`: Crvy Rprtr copied the expected snapshot into the screenshot directory, so the UI can still show the stored baseline.
101
- - `declared-only`: the screenshot assertion was detected, but Playwright did not emit a passed artifact and no snapshot file could be resolved.
105
+ - `baseline-only`: Crvy Rprtr resolved the exact expected snapshot path and copied that baseline into the screenshot directory, so the UI can show the stored baseline.
106
+ - `declared-only`: the screenshot assertion was detected, but Crvy Rprtr could not resolve one exact snapshot file and therefore keeps the honest text-only fallback.
107
+
108
+ Exact resolution mirrors Playwright's screenshot naming and template rules for default layouts, unnamed screenshots, and explicitly configured custom templates. For slash-containing named screenshot titles, Crvy Rprtr may check both Playwright-equivalent variants and only uses a baseline when exactly one candidate wins.
109
+
110
+ Crvy Rprtr does not auto-read Playwright config for snapshot template discovery. If your suite uses a custom snapshot layout, pass the matching `playwrightSnapshotDir`, `playwrightSnapshotPathTemplate`, or `playwrightToHaveScreenshotPathTemplate` reporter options explicitly for passed-baseline display.
111
+
112
+ Approval routing uses the same resolver, but it reads its resolver settings from the server startup path today. The current user-facing place to pass those overrides is `startServer({...})`, via options such as `configDir`, `playwrightTestDir`, `playwrightSnapshotDir`, `playwrightSnapshotPathTemplate`, and `playwrightToHaveScreenshotPathTemplate`. The CLI does not expose flags for those overrides, so `npx crvy-rprtr` uses the server defaults when they are omitted. For slash-containing named screenshot titles, Crvy Rprtr only updates the baseline when one exact Playwright-equivalent target can be determined.
102
113
 
103
114
  When the server is running, Crvy Rprtr also refreshes the UI after report JSON or screenshot artifacts change on disk.
104
115
 
@@ -122,6 +133,20 @@ await startServer({
122
133
  })
123
134
  ```
124
135
 
136
+ If you need approval routing to follow a custom Playwright snapshot layout, pass the resolver options when starting the server programmatically:
137
+
138
+ ```ts
139
+ await startServer({
140
+ port: 3000,
141
+ screenshotDir: './screenshots',
142
+ reportPath: './artifacts',
143
+ configDir: process.cwd(),
144
+ playwrightTestDir: './tests',
145
+ playwrightSnapshotDir: './tests/__screenshots__',
146
+ playwrightToHaveScreenshotPathTemplate: '{snapshotDir}/{testFilePath}/{arg}{ext}',
147
+ })
148
+ ```
149
+
125
150
  The programmatic server API works in both Node 22+ and Bun.
126
151
 
127
152
  ## Development
@@ -1,3 +1,301 @@
1
+ // src/snapshot-path-resolver.ts
2
+ import { createHash } from "crypto";
3
+ import { basename, dirname, extname, join, parse, relative, resolve } from "path";
4
+ var DEFAULT_SCREENSHOT_TEMPLATE = "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{-snapshotSuffix}{ext}";
5
+ var WINDOWS_FILESYSTEM_FRIENDLY_LENGTH = 60;
6
+ function isUnsafeFilePathCharacter(character) {
7
+ const codePoint = character.codePointAt(0);
8
+ return codePoint !== void 0 && (codePoint <= 44 || codePoint >= 46 && codePoint <= 47 || codePoint >= 58 && codePoint <= 64 || codePoint >= 91 && codePoint <= 96 || codePoint >= 123 && codePoint <= 127);
9
+ }
10
+ function sanitizeForFilePath(value) {
11
+ return Array.from(value).reduce(
12
+ (state, character) => {
13
+ const unsafeCharacter = isUnsafeFilePathCharacter(character);
14
+ return unsafeCharacter ? state.previousCharacterWasUnsafe ? state : {
15
+ value: `${state.value}-`,
16
+ previousCharacterWasUnsafe: true
17
+ } : {
18
+ value: `${state.value}${character}`,
19
+ previousCharacterWasUnsafe: false
20
+ };
21
+ },
22
+ {
23
+ value: "",
24
+ previousCharacterWasUnsafe: false
25
+ }
26
+ ).value;
27
+ }
28
+ function trimLongString(value, length = WINDOWS_FILESYSTEM_FRIENDLY_LENGTH) {
29
+ if (value.length <= length) {
30
+ return value;
31
+ }
32
+ const hash = createHash("sha1").update(value).digest("hex");
33
+ const middle = `-${hash.slice(0, 5)}-`;
34
+ const start = Math.floor((length - middle.length) / 2);
35
+ const end = length - middle.length - start;
36
+ return value.slice(0, start) + middle + value.slice(-end);
37
+ }
38
+ function sanitizeFilePathBeforeExtension(filePath, extension = extname(filePath)) {
39
+ const base = filePath.slice(0, filePath.length - extension.length);
40
+ return sanitizeForFilePath(base) + extension;
41
+ }
42
+ function addSuffixToFilePath(filePath, suffix) {
43
+ const extension = extname(filePath);
44
+ return filePath.slice(0, filePath.length - extension.length) + suffix + extension;
45
+ }
46
+ function normalizedSnapshotDir(config) {
47
+ return resolve(config.configDir, config.snapshotDir);
48
+ }
49
+ function templateValue(template, token, value) {
50
+ return template.replace(
51
+ new RegExp(`\\{(.)?${token}\\}`, "g"),
52
+ (_, prefix) => value === "" ? "" : `${prefix ?? ""}${value}`
53
+ );
54
+ }
55
+ function applyTemplate(input, nameArgument, extension) {
56
+ const template = input.config.toHaveScreenshotPathTemplate ?? input.config.snapshotPathTemplate ?? DEFAULT_SCREENSHOT_TEMPLATE;
57
+ const relativeTestFilePath = relative(input.config.testDir, input.testFile);
58
+ const parsed = parse(relativeTestFilePath);
59
+ const tokens = [
60
+ ["testDir", input.config.testDir],
61
+ ["snapshotDir", normalizedSnapshotDir(input.config)],
62
+ ["snapshotSuffix", input.config.snapshotSuffix],
63
+ ["testFileDir", parsed.dir],
64
+ ["platform", process.platform],
65
+ ["projectName", sanitizeForFilePath(input.config.projectName)],
66
+ ["testName", ""],
67
+ ["testFileName", parsed.base],
68
+ ["testFilePath", relativeTestFilePath],
69
+ ["arg", nameArgument],
70
+ ["ext", extension]
71
+ ];
72
+ const snapshotPath = tokens.reduce(
73
+ (currentTemplate, [token, value]) => templateValue(currentTemplate, token, value),
74
+ template
75
+ );
76
+ return resolve(input.config.configDir, snapshotPath);
77
+ }
78
+ function removeExtension(filePath, extension = extname(filePath)) {
79
+ return filePath.slice(0, filePath.length - extension.length);
80
+ }
81
+ function snapshotNameParts(declaredName) {
82
+ const extension = extname(declaredName) || ".png";
83
+ return {
84
+ extension,
85
+ filePath: extname(declaredName) === "" ? `${declaredName}${extension}` : declaredName
86
+ };
87
+ }
88
+ function filePathForOccurrence(filePath, occurrenceIndex) {
89
+ return occurrenceIndex === 1 ? filePath : addSuffixToFilePath(filePath, `-${occurrenceIndex - 1}`);
90
+ }
91
+ function createResolvedBaselineTarget(input, declaration, nameArgument, extension) {
92
+ return {
93
+ visualName: declaration.visualName,
94
+ attachmentBaseName: declaration.visualName,
95
+ artifactBaseName: sanitizeForFilePath(declaration.visualName),
96
+ snapshotPath: applyTemplate(input, nameArgument, extension)
97
+ };
98
+ }
99
+ function resolveStringCallTarget(input, declaration) {
100
+ const { extension, filePath } = snapshotNameParts(declaration.declaredName);
101
+ const occurrenceFilePath = filePathForOccurrence(filePath, declaration.occurrenceIndex);
102
+ const sanitizedNameWithExtension = sanitizeFilePathBeforeExtension(occurrenceFilePath, extension);
103
+ const nameArgument = removeExtension(sanitizedNameWithExtension, extension);
104
+ return createResolvedBaselineTarget(input, declaration, nameArgument, extension);
105
+ }
106
+ function resolveArrayCallTarget(input, declaration) {
107
+ const { extension, filePath } = snapshotNameParts(declaration.declaredName);
108
+ const occurrenceFilePath = filePathForOccurrence(filePath, declaration.occurrenceIndex);
109
+ const nameArgument = join(dirname(occurrenceFilePath), basename(occurrenceFilePath, extension));
110
+ return createResolvedBaselineTarget(input, declaration, nameArgument, extension);
111
+ }
112
+ function resolveNamedTarget(input, declaration) {
113
+ if (!declaration.declaredName.includes("/")) {
114
+ return resolveStringCallTarget(input, declaration);
115
+ }
116
+ const stringCallTarget = resolveStringCallTarget(input, declaration);
117
+ const arrayCallTarget = resolveArrayCallTarget(input, declaration);
118
+ if (stringCallTarget.snapshotPath === arrayCallTarget.snapshotPath) {
119
+ return stringCallTarget;
120
+ }
121
+ if (input.snapshotPathExists === void 0) {
122
+ return void 0;
123
+ }
124
+ const stringCallTargetExists = input.snapshotPathExists(stringCallTarget.snapshotPath);
125
+ const arrayCallTargetExists = input.snapshotPathExists(arrayCallTarget.snapshotPath);
126
+ if (stringCallTargetExists === arrayCallTargetExists) {
127
+ return void 0;
128
+ }
129
+ return stringCallTargetExists ? stringCallTarget : arrayCallTarget;
130
+ }
131
+ function reporterTitlesWithoutProjectAndFile(reporterTitlePath) {
132
+ return reporterTitlePath.slice(3).filter((part) => part !== "");
133
+ }
134
+ function anonymousName(reporterTitlePath, occurrenceIndex) {
135
+ const rawAnonymousName = `${reporterTitlesWithoutProjectAndFile(reporterTitlePath).join(" ")} ${occurrenceIndex}.png`;
136
+ return sanitizeFilePathBeforeExtension(trimLongString(rawAnonymousName), ".png");
137
+ }
138
+ function resolveTarget(input, declaration) {
139
+ switch (declaration.kind) {
140
+ case "named":
141
+ return typeof declaration.declaredName === "string" && declaration.declaredName !== "" ? resolveNamedTarget(input, declaration) : void 0;
142
+ case "unnamed": {
143
+ const anonymousFileName = anonymousName(input.reporterTitlePath, declaration.occurrenceIndex);
144
+ const extension = ".png";
145
+ const nameArgument = join(dirname(anonymousFileName), basename(anonymousFileName, extension));
146
+ return createResolvedBaselineTarget(input, declaration, nameArgument, extension);
147
+ }
148
+ }
149
+ }
150
+ function resolveBaselineTargets(input) {
151
+ return input.declarations.flatMap((declaration) => {
152
+ const resolvedTarget = resolveTarget(input, declaration);
153
+ return resolvedTarget === void 0 ? [] : [resolvedTarget];
154
+ });
155
+ }
156
+
157
+ // src/schemas.ts
158
+ import { z } from "zod";
159
+ var LocationSchema = z.object({
160
+ file: z.string(),
161
+ line: z.number()
162
+ });
163
+ var VisualSourceSchema = z.enum(["comparison", "baseline-only", "declared-only"]);
164
+ var ImagesSchema = z.object({
165
+ actual: z.string().optional(),
166
+ expect: z.string().optional(),
167
+ diff: z.string().optional(),
168
+ error: z.string().optional(),
169
+ source: VisualSourceSchema.optional()
170
+ });
171
+ var ScreenshotDeclarationSchema = z.discriminatedUnion("kind", [
172
+ z.object({
173
+ visualName: z.string(),
174
+ kind: z.literal("named"),
175
+ declaredName: z.string(),
176
+ snapshotBaseName: z.string(),
177
+ occurrenceIndex: z.number()
178
+ }),
179
+ z.object({
180
+ visualName: z.string(),
181
+ kind: z.literal("unnamed"),
182
+ occurrenceIndex: z.number()
183
+ })
184
+ ]);
185
+ var AttachmentSchema = z.object({
186
+ name: z.string(),
187
+ path: z.string(),
188
+ contentType: z.string()
189
+ });
190
+ var TestStatusSchema = z.enum(["unknown", "pending", "running", "failed", "approved", "success", "retrying"]);
191
+ var TestResultStatusSchema = z.enum(["failed", "success", "pending"]);
192
+ var TestResultSchema = z.object({
193
+ status: TestResultStatusSchema,
194
+ retries: z.number(),
195
+ images: z.record(z.string(), ImagesSchema).optional(),
196
+ visualDeclarations: z.array(ScreenshotDeclarationSchema).optional(),
197
+ error: z.string().optional(),
198
+ duration: z.number().optional()
199
+ });
200
+ var TestDataSchema = z.object({
201
+ id: z.string(),
202
+ titlePath: z.array(z.string()),
203
+ browser: z.string(),
204
+ title: z.string(),
205
+ skip: z.union([z.boolean(), z.string()]).optional(),
206
+ retries: z.number().optional(),
207
+ status: TestStatusSchema.optional(),
208
+ results: z.array(TestResultSchema).optional(),
209
+ approved: z.record(z.string(), z.number()).nullable().optional(),
210
+ attachments: z.array(AttachmentSchema).optional(),
211
+ location: LocationSchema.optional()
212
+ });
213
+ var CrvyRprtrTestSchema = TestDataSchema.extend({
214
+ checked: z.boolean()
215
+ });
216
+ var CrvyRprtrSuiteSchema = z.lazy(
217
+ () => z.object({
218
+ path: z.array(z.string()),
219
+ skip: z.boolean(),
220
+ status: TestStatusSchema.optional(),
221
+ opened: z.boolean(),
222
+ checked: z.boolean(),
223
+ indeterminate: z.boolean(),
224
+ children: z.record(z.string(), z.union([CrvyRprtrSuiteSchema, CrvyRprtrTestSchema])).optional()
225
+ })
226
+ );
227
+ var WebSocketMessageSchema = z.object({
228
+ type: z.enum(["test-begin", "test-end", "run-end", "approve", "sync"]),
229
+ data: z.unknown()
230
+ });
231
+ var TestBeginDataSchema = z.object({
232
+ id: z.string(),
233
+ title: z.string(),
234
+ titlePath: z.array(z.string()),
235
+ browser: z.string(),
236
+ location: LocationSchema
237
+ });
238
+ var TestEndDataSchema = z.object({
239
+ id: z.string(),
240
+ status: z.enum(["passed", "failed", "skipped"]),
241
+ attachments: z.array(AttachmentSchema),
242
+ visualNames: z.array(z.string()).default([]),
243
+ visualDeclarations: z.preprocess(
244
+ (value) => value === null ? void 0 : value,
245
+ z.array(ScreenshotDeclarationSchema).optional()
246
+ ),
247
+ error: z.string().optional(),
248
+ duration: z.number().optional()
249
+ });
250
+ var ReportDataSchema = z.object({
251
+ isRunning: z.boolean(),
252
+ tests: z.record(z.string(), TestDataSchema),
253
+ browsers: z.array(z.string()),
254
+ isUpdateMode: z.boolean(),
255
+ screenshotDir: z.string()
256
+ });
257
+ var LoadedReportDataSchema = z.object({
258
+ tests: z.record(z.string(), TestDataSchema).optional(),
259
+ isUpdateMode: z.boolean().optional()
260
+ });
261
+ var OfflineEventSchema = z.object({
262
+ type: z.enum(["test-begin", "test-end", "run-end"]),
263
+ data: z.unknown(),
264
+ timestamp: z.number(),
265
+ workerIndex: z.number()
266
+ });
267
+ var OfflineReportSchema = z.object({
268
+ version: z.number(),
269
+ generatedAt: z.string(),
270
+ workers: z.number(),
271
+ events: z.array(OfflineEventSchema)
272
+ });
273
+ var ApproveRequestBodySchema = z.object({
274
+ id: z.string(),
275
+ retry: z.number(),
276
+ image: z.string()
277
+ });
278
+ var ReportApiResponseSchema = z.object({
279
+ tests: z.record(z.string(), TestDataSchema),
280
+ isUpdateMode: z.boolean().optional()
281
+ });
282
+ var ClientBootstrapDataSchema = z.object({
283
+ report: ReportApiResponseSchema.extend({
284
+ isUpdateMode: z.boolean()
285
+ }),
286
+ liveUpdates: z.boolean(),
287
+ approvalEnabled: z.boolean(),
288
+ approvalMessage: z.string().optional()
289
+ });
290
+ var ImagesViewModeSchema = z.enum(["side-by-side", "swap", "slide", "blend"]);
291
+ function safeParse(schema, data) {
292
+ const result = schema.safeParse(data);
293
+ if (result.success) {
294
+ return result.data;
295
+ }
296
+ return null;
297
+ }
298
+
1
299
  // src/report-utils.ts
2
300
  function normalizeScreenshotsBaseUrl(baseUrl) {
3
301
  return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
@@ -17,6 +315,12 @@ function withImageSource(image) {
17
315
  source: classifyImage(image)
18
316
  };
19
317
  }
318
+ function getDeclaredVisualNames(visualNames, visualDeclarations) {
319
+ return visualDeclarations?.map(({ visualName }) => visualName) ?? visualNames;
320
+ }
321
+ function copyVisualDeclarations(visualDeclarations) {
322
+ return visualDeclarations?.map((visualDeclaration) => ({ ...visualDeclaration }));
323
+ }
20
324
  function mergeDeclaredImages(images, visualNames) {
21
325
  const names = /* @__PURE__ */ new Set([...Object.keys(images), ...visualNames]);
22
326
  return Object.fromEntries(
@@ -136,10 +440,14 @@ function applyTestEndEvent(state, data, options = {}) {
136
440
  }
137
441
  test.status = mapStatus(data.status);
138
442
  const resultStatus = data.status === "passed" ? "success" : data.status === "failed" ? "failed" : "pending";
443
+ const visualDeclarations = copyVisualDeclarations(data.visualDeclarations);
139
444
  const images = preservePreviousPassingImages(
140
445
  test,
141
446
  data.status,
142
- mergeDeclaredImages(attachmentsToImages(data.attachments, options.screenshotsBaseUrl), data.visualNames)
447
+ mergeDeclaredImages(
448
+ attachmentsToImages(data.attachments, options.screenshotsBaseUrl),
449
+ getDeclaredVisualNames(data.visualNames, visualDeclarations)
450
+ )
143
451
  );
144
452
  const diffCount = countDiffImages(images);
145
453
  const hasDiffs = diffCount > 0;
@@ -151,6 +459,7 @@ function applyTestEndEvent(state, data, options = {}) {
151
459
  status: resultStatus,
152
460
  retries: 0,
153
461
  images,
462
+ visualDeclarations,
154
463
  error: data.error,
155
464
  duration: data.duration
156
465
  }
@@ -174,129 +483,6 @@ function finalizeRunEvent(state) {
174
483
  };
175
484
  }
176
485
 
177
- // src/schemas.ts
178
- import { z } from "zod";
179
- var LocationSchema = z.object({
180
- file: z.string(),
181
- line: z.number()
182
- });
183
- var VisualSourceSchema = z.enum(["comparison", "baseline-only", "declared-only"]);
184
- var ImagesSchema = z.object({
185
- actual: z.string().optional(),
186
- expect: z.string().optional(),
187
- diff: z.string().optional(),
188
- error: z.string().optional(),
189
- source: VisualSourceSchema.optional()
190
- });
191
- var AttachmentSchema = z.object({
192
- name: z.string(),
193
- path: z.string(),
194
- contentType: z.string()
195
- });
196
- var TestStatusSchema = z.enum(["unknown", "pending", "running", "failed", "approved", "success", "retrying"]);
197
- var TestResultStatusSchema = z.enum(["failed", "success", "pending"]);
198
- var TestResultSchema = z.object({
199
- status: TestResultStatusSchema,
200
- retries: z.number(),
201
- images: z.record(z.string(), ImagesSchema).optional(),
202
- error: z.string().optional(),
203
- duration: z.number().optional()
204
- });
205
- var TestDataSchema = z.object({
206
- id: z.string(),
207
- titlePath: z.array(z.string()),
208
- browser: z.string(),
209
- title: z.string(),
210
- skip: z.union([z.boolean(), z.string()]).optional(),
211
- retries: z.number().optional(),
212
- status: TestStatusSchema.optional(),
213
- results: z.array(TestResultSchema).optional(),
214
- approved: z.record(z.string(), z.number()).nullable().optional(),
215
- attachments: z.array(AttachmentSchema).optional(),
216
- location: LocationSchema.optional()
217
- });
218
- var CrvyRprtrTestSchema = TestDataSchema.extend({
219
- checked: z.boolean()
220
- });
221
- var CrvyRprtrSuiteSchema = z.lazy(
222
- () => z.object({
223
- path: z.array(z.string()),
224
- skip: z.boolean(),
225
- status: TestStatusSchema.optional(),
226
- opened: z.boolean(),
227
- checked: z.boolean(),
228
- indeterminate: z.boolean(),
229
- children: z.record(z.string(), z.union([CrvyRprtrSuiteSchema, CrvyRprtrTestSchema])).optional()
230
- })
231
- );
232
- var WebSocketMessageSchema = z.object({
233
- type: z.enum(["test-begin", "test-end", "run-end", "approve", "sync"]),
234
- data: z.unknown()
235
- });
236
- var TestBeginDataSchema = z.object({
237
- id: z.string(),
238
- title: z.string(),
239
- titlePath: z.array(z.string()),
240
- browser: z.string(),
241
- location: LocationSchema
242
- });
243
- var TestEndDataSchema = z.object({
244
- id: z.string(),
245
- status: z.enum(["passed", "failed", "skipped"]),
246
- attachments: z.array(AttachmentSchema),
247
- visualNames: z.array(z.string()).default([]),
248
- error: z.string().optional(),
249
- duration: z.number().optional()
250
- });
251
- var ReportDataSchema = z.object({
252
- isRunning: z.boolean(),
253
- tests: z.record(z.string(), TestDataSchema),
254
- browsers: z.array(z.string()),
255
- isUpdateMode: z.boolean(),
256
- screenshotDir: z.string()
257
- });
258
- var LoadedReportDataSchema = z.object({
259
- tests: z.record(z.string(), TestDataSchema).optional(),
260
- isUpdateMode: z.boolean().optional()
261
- });
262
- var OfflineEventSchema = z.object({
263
- type: z.enum(["test-begin", "test-end", "run-end"]),
264
- data: z.unknown(),
265
- timestamp: z.number(),
266
- workerIndex: z.number()
267
- });
268
- var OfflineReportSchema = z.object({
269
- version: z.number(),
270
- generatedAt: z.string(),
271
- workers: z.number(),
272
- events: z.array(OfflineEventSchema)
273
- });
274
- var ApproveRequestBodySchema = z.object({
275
- id: z.string(),
276
- retry: z.number(),
277
- image: z.string()
278
- });
279
- var ReportApiResponseSchema = z.object({
280
- tests: z.record(z.string(), TestDataSchema),
281
- isUpdateMode: z.boolean().optional()
282
- });
283
- var ClientBootstrapDataSchema = z.object({
284
- report: ReportApiResponseSchema.extend({
285
- isUpdateMode: z.boolean()
286
- }),
287
- liveUpdates: z.boolean(),
288
- approvalEnabled: z.boolean(),
289
- approvalMessage: z.string().optional()
290
- });
291
- var ImagesViewModeSchema = z.enum(["side-by-side", "swap", "slide", "blend"]);
292
- function safeParse(schema, data) {
293
- const result = schema.safeParse(data);
294
- if (result.success) {
295
- return result.data;
296
- }
297
- return null;
298
- }
299
-
300
486
  export {
301
487
  createMutableReportState,
302
488
  applyTestBeginEvent,
@@ -309,5 +495,6 @@ export {
309
495
  OfflineReportSchema,
310
496
  ApproveRequestBodySchema,
311
497
  ClientBootstrapDataSchema,
312
- safeParse
498
+ safeParse,
499
+ resolveBaselineTargets
313
500
  };