@crvy/rprtr 0.0.5 → 0.0.7
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 +60 -0
- package/README.md +34 -9
- package/dist/{chunk-MWLM3HWS.js → chunk-JGS2VWQP.js} +189 -2
- package/dist/{chunk-IH44LYNM.js → chunk-OMDYTNWY.js} +131 -53
- package/dist/cli.js +2 -2
- package/dist/index.css +3 -0
- package/dist/index.js +555 -485
- package/dist/report-state.d.ts +6 -1
- package/dist/report-state.d.ts.map +1 -1
- package/dist/report-utils.d.ts +3 -0
- package/dist/report-utils.d.ts.map +1 -1
- package/dist/reporter-utils.d.ts +11 -2
- package/dist/reporter-utils.d.ts.map +1 -1
- package/dist/reporter.cjs +368 -154
- package/dist/reporter.d.ts +13 -1
- package/dist/reporter.d.ts.map +1 -1
- package/dist/reporter.js +182 -153
- package/dist/schemas.d.ts +115 -15
- package/dist/schemas.d.ts.map +1 -1
- package/dist/server/app.d.ts +5 -0
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/routes.d.ts +7 -0
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server.cjs +329 -64
- package/dist/server.js +2 -2
- package/dist/snapshot-path-resolver.d.ts +30 -0
- package/dist/snapshot-path-resolver.d.ts.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,66 @@ 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.7] - 2026-06-05
|
|
9
|
+
|
|
10
|
+
### Ci
|
|
11
|
+
|
|
12
|
+
- Upgrade actions and node version for npm trusted publishing
|
|
13
|
+
## [0.0.6] - 2026-06-05
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Add named screenshot baseline resolver
|
|
18
|
+
- Resolve unnamed and duplicate screenshot baselines
|
|
19
|
+
- Resolve passed screenshot baselines through Playwright rules
|
|
20
|
+
- Persist approval resolver metadata in report state
|
|
21
|
+
- Emit approval resolver metadata from reporter
|
|
22
|
+
- Reuse resolver for approval routing
|
|
23
|
+
- Report mixed approval routing outcomes
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Separate resolver attachment and artifact names
|
|
28
|
+
- Tighten screenshot declaration typing
|
|
29
|
+
|
|
30
|
+
### Documentation
|
|
31
|
+
|
|
32
|
+
- Add passed screenshot baseline resolution design
|
|
33
|
+
- Add passed screenshot baseline resolution plan
|
|
34
|
+
- Document passed screenshot baseline resolution options
|
|
35
|
+
- Narrow approval path claims
|
|
36
|
+
- Add template-aware approval routing design
|
|
37
|
+
- Add template-aware approval routing plan
|
|
38
|
+
- Align approval routing docs with resolver behavior
|
|
39
|
+
- Clarify approval routing configuration scope
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- Sanitize named screenshot resolver inputs
|
|
44
|
+
- Preserve visual names in named baseline targets
|
|
45
|
+
- Disambiguate named screenshot baseline resolution
|
|
46
|
+
- Restore reporter declaration compatibility
|
|
47
|
+
- Use safe artifact names for copied baselines
|
|
48
|
+
- Encode copied baseline artifact paths safely
|
|
49
|
+
- Neutralize traversal segments in baseline artifact paths
|
|
50
|
+
- Encode saved attachment artifact paths safely
|
|
51
|
+
- Use stable traversal-safe artifact path encoding
|
|
52
|
+
- Preserve approval metadata through schemas
|
|
53
|
+
- Preserve visual name fallback for older payloads
|
|
54
|
+
- Use configured testDir for approval resolution
|
|
55
|
+
- Use configured configDir for approval resolution
|
|
56
|
+
- Require POST for approve-all routing
|
|
57
|
+
- Require POST for approve routing
|
|
58
|
+
- Report no-actual bulk approval outcomes
|
|
59
|
+
- Honor approval api results in client state
|
|
60
|
+
|
|
61
|
+
### Testing
|
|
62
|
+
|
|
63
|
+
- Cover exact approval routing cases
|
|
64
|
+
|
|
65
|
+
### Ci
|
|
66
|
+
|
|
67
|
+
- Switch npm publish to OIDC trusted publishing
|
|
8
68
|
## [0.0.5] - 2026-05-14
|
|
9
69
|
|
|
10
70
|
### Added
|
package/README.md
CHANGED
|
@@ -50,12 +50,15 @@ npx crvy-rprtr ./artifacts
|
|
|
50
50
|
|
|
51
51
|
## Reporter Options
|
|
52
52
|
|
|
53
|
-
| Option
|
|
54
|
-
|
|
|
55
|
-
| `serverUrl`
|
|
56
|
-
| `screenshotDir`
|
|
57
|
-
| `offlineReportPath`
|
|
58
|
-
| `reportHtmlPath`
|
|
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.
|
|
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
|
|
101
|
-
- `declared-only`: the screenshot assertion was detected, but
|
|
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,159 @@
|
|
|
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
|
+
|
|
1
157
|
// src/report-utils.ts
|
|
2
158
|
function normalizeScreenshotsBaseUrl(baseUrl) {
|
|
3
159
|
return baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
@@ -17,6 +173,12 @@ function withImageSource(image) {
|
|
|
17
173
|
source: classifyImage(image)
|
|
18
174
|
};
|
|
19
175
|
}
|
|
176
|
+
function getDeclaredVisualNames(visualNames, visualDeclarations) {
|
|
177
|
+
return visualDeclarations?.map(({ visualName }) => visualName) ?? visualNames;
|
|
178
|
+
}
|
|
179
|
+
function copyVisualDeclarations(visualDeclarations) {
|
|
180
|
+
return visualDeclarations?.map((visualDeclaration) => ({ ...visualDeclaration }));
|
|
181
|
+
}
|
|
20
182
|
function mergeDeclaredImages(images, visualNames) {
|
|
21
183
|
const names = /* @__PURE__ */ new Set([...Object.keys(images), ...visualNames]);
|
|
22
184
|
return Object.fromEntries(
|
|
@@ -136,10 +298,14 @@ function applyTestEndEvent(state, data, options = {}) {
|
|
|
136
298
|
}
|
|
137
299
|
test.status = mapStatus(data.status);
|
|
138
300
|
const resultStatus = data.status === "passed" ? "success" : data.status === "failed" ? "failed" : "pending";
|
|
301
|
+
const visualDeclarations = copyVisualDeclarations(data.visualDeclarations);
|
|
139
302
|
const images = preservePreviousPassingImages(
|
|
140
303
|
test,
|
|
141
304
|
data.status,
|
|
142
|
-
mergeDeclaredImages(
|
|
305
|
+
mergeDeclaredImages(
|
|
306
|
+
attachmentsToImages(data.attachments, options.screenshotsBaseUrl),
|
|
307
|
+
getDeclaredVisualNames(data.visualNames, visualDeclarations)
|
|
308
|
+
)
|
|
143
309
|
);
|
|
144
310
|
const diffCount = countDiffImages(images);
|
|
145
311
|
const hasDiffs = diffCount > 0;
|
|
@@ -151,6 +317,7 @@ function applyTestEndEvent(state, data, options = {}) {
|
|
|
151
317
|
status: resultStatus,
|
|
152
318
|
retries: 0,
|
|
153
319
|
images,
|
|
320
|
+
visualDeclarations,
|
|
154
321
|
error: data.error,
|
|
155
322
|
duration: data.duration
|
|
156
323
|
}
|
|
@@ -188,6 +355,20 @@ var ImagesSchema = z.object({
|
|
|
188
355
|
error: z.string().optional(),
|
|
189
356
|
source: VisualSourceSchema.optional()
|
|
190
357
|
});
|
|
358
|
+
var ScreenshotDeclarationSchema = z.discriminatedUnion("kind", [
|
|
359
|
+
z.object({
|
|
360
|
+
visualName: z.string(),
|
|
361
|
+
kind: z.literal("named"),
|
|
362
|
+
declaredName: z.string(),
|
|
363
|
+
snapshotBaseName: z.string(),
|
|
364
|
+
occurrenceIndex: z.number()
|
|
365
|
+
}),
|
|
366
|
+
z.object({
|
|
367
|
+
visualName: z.string(),
|
|
368
|
+
kind: z.literal("unnamed"),
|
|
369
|
+
occurrenceIndex: z.number()
|
|
370
|
+
})
|
|
371
|
+
]);
|
|
191
372
|
var AttachmentSchema = z.object({
|
|
192
373
|
name: z.string(),
|
|
193
374
|
path: z.string(),
|
|
@@ -199,6 +380,7 @@ var TestResultSchema = z.object({
|
|
|
199
380
|
status: TestResultStatusSchema,
|
|
200
381
|
retries: z.number(),
|
|
201
382
|
images: z.record(z.string(), ImagesSchema).optional(),
|
|
383
|
+
visualDeclarations: z.array(ScreenshotDeclarationSchema).optional(),
|
|
202
384
|
error: z.string().optional(),
|
|
203
385
|
duration: z.number().optional()
|
|
204
386
|
});
|
|
@@ -245,6 +427,10 @@ var TestEndDataSchema = z.object({
|
|
|
245
427
|
status: z.enum(["passed", "failed", "skipped"]),
|
|
246
428
|
attachments: z.array(AttachmentSchema),
|
|
247
429
|
visualNames: z.array(z.string()).default([]),
|
|
430
|
+
visualDeclarations: z.preprocess(
|
|
431
|
+
(value) => value === null ? void 0 : value,
|
|
432
|
+
z.array(ScreenshotDeclarationSchema).optional()
|
|
433
|
+
),
|
|
248
434
|
error: z.string().optional(),
|
|
249
435
|
duration: z.number().optional()
|
|
250
436
|
});
|
|
@@ -309,5 +495,6 @@ export {
|
|
|
309
495
|
OfflineReportSchema,
|
|
310
496
|
ApproveRequestBodySchema,
|
|
311
497
|
ClientBootstrapDataSchema,
|
|
312
|
-
safeParse
|
|
498
|
+
safeParse,
|
|
499
|
+
resolveBaselineTargets
|
|
313
500
|
};
|
|
@@ -9,11 +9,12 @@ import {
|
|
|
9
9
|
applyTestEndEvent,
|
|
10
10
|
createMutableReportState,
|
|
11
11
|
finalizeRunEvent,
|
|
12
|
+
resolveBaselineTargets,
|
|
12
13
|
safeParse
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-JGS2VWQP.js";
|
|
14
15
|
|
|
15
16
|
// src/server/app.ts
|
|
16
|
-
import { dirname as
|
|
17
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
17
18
|
import { fileURLToPath } from "url";
|
|
18
19
|
import pLimit from "p-limit";
|
|
19
20
|
|
|
@@ -316,7 +317,8 @@ async function watchReportArtifacts(options) {
|
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
// src/server/routes.ts
|
|
319
|
-
import {
|
|
320
|
+
import { existsSync } from "fs";
|
|
321
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
320
322
|
var LIVE_UPDATES_WEBSOCKET_PATH = "/";
|
|
321
323
|
function isWebSocketUpgradeRequest(req) {
|
|
322
324
|
return new URL(req.url).pathname === LIVE_UPDATES_WEBSOCKET_PATH && req.headers.get("upgrade")?.toLowerCase() === "websocket";
|
|
@@ -339,6 +341,37 @@ async function handleSrcFiles(req) {
|
|
|
339
341
|
function handleApiReport(ctx) {
|
|
340
342
|
return Response.json(ctx.reportData);
|
|
341
343
|
}
|
|
344
|
+
var APPROVAL_TARGET_ERROR = "Could not resolve approval target";
|
|
345
|
+
function actualPathFromUrl(ctx, actualUrl) {
|
|
346
|
+
return actualUrl.startsWith("/screenshots/") ? join3(ctx.reportData.screenshotDir, actualUrl.slice("/screenshots/".length)) : actualUrl;
|
|
347
|
+
}
|
|
348
|
+
function reporterTitlePath(test) {
|
|
349
|
+
const testFile = test.location?.file;
|
|
350
|
+
return ["", test.browser, testFile ?? "", ...test.titlePath, test.title];
|
|
351
|
+
}
|
|
352
|
+
function resolveApprovalTarget(ctx, test, retry, imageName) {
|
|
353
|
+
const testFile = test.location?.file;
|
|
354
|
+
const declaration = test.results?.[retry]?.visualDeclarations?.find((candidate) => candidate.visualName === imageName);
|
|
355
|
+
if (ctx.approvalRouting === void 0 || testFile === void 0 || declaration === void 0) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
const targets = resolveBaselineTargets({
|
|
359
|
+
testFile,
|
|
360
|
+
reporterTitlePath: reporterTitlePath(test),
|
|
361
|
+
declarations: [declaration],
|
|
362
|
+
config: {
|
|
363
|
+
configDir: ctx.approvalRouting.configDir,
|
|
364
|
+
testDir: ctx.approvalRouting.playwrightTestDir ?? dirname2(testFile),
|
|
365
|
+
snapshotDir: ctx.approvalRouting.playwrightSnapshotDir ?? dirname2(testFile),
|
|
366
|
+
projectName: test.browser,
|
|
367
|
+
snapshotSuffix: process.platform,
|
|
368
|
+
snapshotPathTemplate: ctx.approvalRouting.playwrightSnapshotPathTemplate,
|
|
369
|
+
toHaveScreenshotPathTemplate: ctx.approvalRouting.playwrightToHaveScreenshotPathTemplate
|
|
370
|
+
},
|
|
371
|
+
snapshotPathExists: existsSync
|
|
372
|
+
});
|
|
373
|
+
return targets.length === 1 ? targets[0]?.snapshotPath ?? null : null;
|
|
374
|
+
}
|
|
342
375
|
async function handleApiApprove(ctx, req) {
|
|
343
376
|
try {
|
|
344
377
|
const rawBody = await req.json();
|
|
@@ -349,61 +382,96 @@ async function handleApiApprove(ctx, req) {
|
|
|
349
382
|
}
|
|
350
383
|
const { id, retry, image } = parsed;
|
|
351
384
|
const test = ctx.reportData.tests[id];
|
|
352
|
-
if (test
|
|
353
|
-
|
|
354
|
-
|
|
385
|
+
if (test === void 0) {
|
|
386
|
+
return Response.json({ success: false, error: "Test not found" }, { status: 404 });
|
|
387
|
+
}
|
|
388
|
+
const actualUrl = test.results?.[retry]?.images?.[image]?.actual;
|
|
389
|
+
if (actualUrl === void 0) {
|
|
390
|
+
return Response.json({ success: false, error: "Actual image not found" }, { status: 409 });
|
|
391
|
+
}
|
|
392
|
+
const snapshotPath = resolveApprovalTarget(ctx, test, retry, image);
|
|
393
|
+
if (snapshotPath === null) {
|
|
394
|
+
return Response.json({ success: false, error: APPROVAL_TARGET_ERROR }, { status: 409 });
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
await copyFilePortable(actualPathFromUrl(ctx, actualUrl), snapshotPath);
|
|
398
|
+
test.approved = { ...test.approved ?? {}, [image]: retry };
|
|
355
399
|
await ctx.saveReport();
|
|
356
|
-
|
|
357
|
-
if (actualUrl !== null && actualUrl !== void 0 && test.location?.file !== null && test.location?.file !== void 0) {
|
|
358
|
-
const actualPath = actualUrl.replace("/screenshots/", `${ctx.reportData.screenshotDir}/`);
|
|
359
|
-
const snapshotPath = `${test.location.file}-snapshots/${image}-${test.browser}-${process.platform}.png`;
|
|
360
|
-
try {
|
|
361
|
-
await copyFilePortable(actualPath, snapshotPath);
|
|
362
|
-
console.log(` \u2714 Updated baseline: ${snapshotPath}`);
|
|
363
|
-
} catch (err) {
|
|
364
|
-
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
365
|
-
console.error(` \u2717 Failed to update baseline: ${errorMsg}`);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
400
|
+
console.log(` \u2714 Updated baseline: ${snapshotPath}`);
|
|
368
401
|
console.log(` \u2714 Approved [${test.browser}] ${test.title} \u2014 ${image}`);
|
|
402
|
+
return Response.json({ success: true });
|
|
403
|
+
} catch (err) {
|
|
404
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
405
|
+
console.error(` \u2717 Failed to update baseline: ${errorMsg}`);
|
|
406
|
+
return Response.json({ success: false, error: "Failed to update baseline" }, { status: 500 });
|
|
369
407
|
}
|
|
370
|
-
return Response.json({ success: true });
|
|
371
408
|
} catch {
|
|
372
409
|
return Response.json({ success: false, error: "Invalid request" }, { status: 400 });
|
|
373
410
|
}
|
|
374
411
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
const approved = {};
|
|
412
|
+
function createBulkApprovalUpdates(ctx) {
|
|
413
|
+
return Object.values(ctx.reportData.tests).flatMap((test) => {
|
|
414
|
+
if (!test.results || test.results.length === 0) {
|
|
415
|
+
return [];
|
|
416
|
+
}
|
|
381
417
|
const lastRetry = test.results.length - 1;
|
|
382
418
|
const lastResult = test.results[lastRetry];
|
|
383
|
-
if (!lastResult?.images)
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
419
|
+
if (!lastResult?.images) {
|
|
420
|
+
return [];
|
|
421
|
+
}
|
|
422
|
+
return Object.keys(lastResult.images).flatMap((imageName) => {
|
|
387
423
|
const actualUrl = lastResult.images?.[imageName]?.actual;
|
|
388
|
-
if (actualUrl
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}).catch((err) => {
|
|
395
|
-
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
396
|
-
console.error(` \u2717 Failed to update baseline: ${errorMsg}`);
|
|
397
|
-
})
|
|
398
|
-
);
|
|
424
|
+
if (actualUrl === void 0) {
|
|
425
|
+
return [Promise.resolve({ kind: "unresolved" })];
|
|
426
|
+
}
|
|
427
|
+
const snapshotPath = resolveApprovalTarget(ctx, test, lastRetry, imageName);
|
|
428
|
+
if (snapshotPath === null) {
|
|
429
|
+
return [Promise.resolve({ kind: "unresolved" })];
|
|
399
430
|
}
|
|
431
|
+
return [
|
|
432
|
+
copyFilePortable(actualPathFromUrl(ctx, actualUrl), snapshotPath).then(
|
|
433
|
+
() => ({
|
|
434
|
+
kind: "approved",
|
|
435
|
+
imageName,
|
|
436
|
+
retry: lastRetry,
|
|
437
|
+
snapshotPath,
|
|
438
|
+
test
|
|
439
|
+
})
|
|
440
|
+
).catch((err) => {
|
|
441
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
442
|
+
console.error(` \u2717 Failed to update baseline: ${errorMsg}`);
|
|
443
|
+
return { kind: "failed" };
|
|
444
|
+
})
|
|
445
|
+
];
|
|
400
446
|
});
|
|
401
|
-
test.approved = approved;
|
|
402
447
|
});
|
|
448
|
+
}
|
|
449
|
+
function summarizeBulkApprovalOutcomes(outcomes) {
|
|
450
|
+
return outcomes.reduce(
|
|
451
|
+
(summary, outcome) => {
|
|
452
|
+
switch (outcome.kind) {
|
|
453
|
+
case "approved": {
|
|
454
|
+
outcome.test.approved = { ...outcome.test.approved ?? {}, [outcome.imageName]: outcome.retry };
|
|
455
|
+
console.log(` \u2714 Updated baseline: ${outcome.snapshotPath}`);
|
|
456
|
+
return { ...summary, approved: summary.approved + 1 };
|
|
457
|
+
}
|
|
458
|
+
case "unresolved":
|
|
459
|
+
return { ...summary, unresolved: summary.unresolved + 1 };
|
|
460
|
+
case "failed":
|
|
461
|
+
return { ...summary, failed: summary.failed + 1 };
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
{ approved: 0, unresolved: 0, failed: 0 }
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
async function handleApiApproveAll(ctx) {
|
|
468
|
+
const outcomes = await Promise.all(createBulkApprovalUpdates(ctx));
|
|
469
|
+
const counts = summarizeBulkApprovalOutcomes(outcomes);
|
|
403
470
|
await ctx.saveReport();
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
471
|
+
console.log(
|
|
472
|
+
` \u2714 Approved all \u2014 approved: ${counts.approved}, unresolved: ${counts.unresolved}, failed: ${counts.failed}`
|
|
473
|
+
);
|
|
474
|
+
return Response.json({ success: counts.failed === 0, ...counts });
|
|
407
475
|
}
|
|
408
476
|
async function handleApiImages(req) {
|
|
409
477
|
const path = new URL(req.url).pathname.slice("/api/images/".length);
|
|
@@ -438,10 +506,10 @@ function handleHttpRequest(ctx, req) {
|
|
|
438
506
|
if (pathname === "/api/report") {
|
|
439
507
|
return Promise.resolve(handleApiReport(ctx));
|
|
440
508
|
}
|
|
441
|
-
if (pathname === "/api/approve") {
|
|
509
|
+
if (pathname === "/api/approve" && req.method === "POST") {
|
|
442
510
|
return handleApiApprove(ctx, req);
|
|
443
511
|
}
|
|
444
|
-
if (pathname === "/api/approve-all") {
|
|
512
|
+
if (pathname === "/api/approve-all" && req.method === "POST") {
|
|
445
513
|
return handleApiApproveAll(ctx);
|
|
446
514
|
}
|
|
447
515
|
if (pathname.startsWith("/api/images/")) {
|
|
@@ -574,7 +642,7 @@ function createWebSocketMessageHandler(getHandlerContext) {
|
|
|
574
642
|
};
|
|
575
643
|
}
|
|
576
644
|
async function resolveStaticDir(staticDir) {
|
|
577
|
-
const currentDir =
|
|
645
|
+
const currentDir = dirname3(fileURLToPath(import.meta.url));
|
|
578
646
|
const candidates = staticDir === void 0 ? [
|
|
579
647
|
currentDir,
|
|
580
648
|
join4(currentDir, "dist"),
|
|
@@ -599,7 +667,21 @@ async function resolveReportPath(reportPath) {
|
|
|
599
667
|
if (await isDirectory(reportPath)) {
|
|
600
668
|
return { reportFile: join4(reportPath, "report.json"), offlineReportDir: reportPath };
|
|
601
669
|
}
|
|
602
|
-
return { reportFile: reportPath, offlineReportDir:
|
|
670
|
+
return { reportFile: reportPath, offlineReportDir: dirname3(reportPath) };
|
|
671
|
+
}
|
|
672
|
+
function createRoutesContext(reportData, staticDir, saveReport, options) {
|
|
673
|
+
return {
|
|
674
|
+
reportData,
|
|
675
|
+
staticDir,
|
|
676
|
+
saveReport,
|
|
677
|
+
approvalRouting: {
|
|
678
|
+
configDir: options.configDir ?? process.cwd(),
|
|
679
|
+
playwrightTestDir: options.playwrightTestDir,
|
|
680
|
+
playwrightSnapshotDir: options.playwrightSnapshotDir,
|
|
681
|
+
playwrightSnapshotPathTemplate: options.playwrightSnapshotPathTemplate,
|
|
682
|
+
playwrightToHaveScreenshotPathTemplate: options.playwrightToHaveScreenshotPathTemplate
|
|
683
|
+
}
|
|
684
|
+
};
|
|
603
685
|
}
|
|
604
686
|
async function createServerApp(options = {}) {
|
|
605
687
|
const port = options.port ?? 3e3;
|
|
@@ -612,11 +694,7 @@ async function createServerApp(options = {}) {
|
|
|
612
694
|
async function saveReport() {
|
|
613
695
|
await writeJsonFile(reportFile, reportData);
|
|
614
696
|
}
|
|
615
|
-
const routesContext =
|
|
616
|
-
reportData,
|
|
617
|
-
staticDir,
|
|
618
|
-
saveReport
|
|
619
|
-
};
|
|
697
|
+
const routesContext = createRoutesContext(reportData, staticDir, saveReport, options);
|
|
620
698
|
const getHandlerContext = () => createHandlerContext(reportData, wsClients, currentRunIds, saveReport);
|
|
621
699
|
const handleRequest = (req) => handleHttpRequest(routesContext, req);
|
|
622
700
|
const handleWebSocketMessage = createWebSocketMessageHandler(getHandlerContext);
|
package/dist/cli.js
CHANGED