cypress-annotate 1.0.0 → 1.2.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.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +55 -0
- package/DOCS/internals.md +2 -2
- package/dist/annotate-image.d.ts +14 -2
- package/dist/annotate-image.d.ts.map +1 -1
- package/dist/annotate-image.js +39 -10
- package/dist/cypress/commands.d.ts.map +1 -1
- package/dist/cypress/commands.js +7 -0
- package/dist/cypress/failure-hook.d.ts +5 -0
- package/dist/cypress/failure-hook.d.ts.map +1 -1
- package/dist/cypress/failure-hook.js +62 -31
- package/dist/cypress/task.d.ts +13 -1
- package/dist/cypress/task.d.ts.map +1 -1
- package/dist/cypress/task.js +13 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/skills/cypress-annotate/SKILL.md +15 -0
package/AGENTS.md
CHANGED
|
@@ -49,8 +49,8 @@ say so explicitly, and they mean it.
|
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
51
|
npm run typecheck
|
|
52
|
-
npm run test:cypress #
|
|
53
|
-
npm run test:cypress-failures #
|
|
52
|
+
npm run test:cypress # 14 cases, real Cypress
|
|
53
|
+
npm run test:cypress-failures # 8 cases end to end, real Cypress
|
|
54
54
|
npm run test:failure-selector # 12 cases, no browser
|
|
55
55
|
npm run test:svg-escaping # 9 cases
|
|
56
56
|
```
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,61 @@
|
|
|
3
3
|
Notable changes to `cypress-annotate`. Each release's section here becomes the
|
|
4
4
|
body of its GitHub release.
|
|
5
5
|
|
|
6
|
+
## 1.2.0
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- The failure hook could fail its own `afterEach`, and Cypress then skips every
|
|
11
|
+
remaining test in the spec. A failing `cy.task` did it, whether annotating
|
|
12
|
+
threw or the report could not be written, and so did a `cy.get` that waited
|
|
13
|
+
out the whole command timeout when the page re-rendered between measuring and
|
|
14
|
+
scrolling. Each step now fails softly: the plain screenshot is kept, the
|
|
15
|
+
reason goes into the Cypress log and the record's `warnings`, and the next
|
|
16
|
+
test runs. A `fail` handler scoped to the hook catches anything else.
|
|
17
|
+
- The hook scrolls a below-the-fold element synchronously, on the element it
|
|
18
|
+
just measured, instead of querying for it again. It also honours
|
|
19
|
+
`scrollOffset` from `env.annotate` now, which it used to ignore.
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- A task named `annotateScreenshotSoft`, registered by `registerAnnotateTasks`
|
|
24
|
+
alongside the existing one. It returns `{ result }` or `{ error }` and never
|
|
25
|
+
throws. `appendFailureRecord` now returns the same shape. `cy.annotate()`
|
|
26
|
+
still uses `annotateScreenshot`, which throws, because an explicit call should
|
|
27
|
+
fail loudly.
|
|
28
|
+
|
|
29
|
+
## 1.1.0
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Boxes landed up and to the left of the target when the viewport was bigger
|
|
34
|
+
than the headless browser window. A 1920x1080 viewport in a 1280x720 window
|
|
35
|
+
produces a screenshot of the viewport's top-left corner at full scale, and the
|
|
36
|
+
narrow image was taken for a resized one, so on a 2x screen every coordinate
|
|
37
|
+
came out at two thirds of its true value. `cy.annotate()` and the failure hook
|
|
38
|
+
now pass Cypress's own `pixelRatio` and `scaled` to the task, and the image
|
|
39
|
+
width is only used to infer a scale when Cypress says it resized the image.
|
|
40
|
+
- A target outside the captured area is skipped with a warning instead of being
|
|
41
|
+
drawn somewhere it isn't. A screenshot that covers less than the viewport also
|
|
42
|
+
gets a warning that says so.
|
|
43
|
+
- Headless Chrome keeps 87px of its window for UI it never draws, so a default
|
|
44
|
+
1280x720 window captures 1280x633. The new warning caught this in the repo's
|
|
45
|
+
own Chrome run, where one target in a multi-target case had been drawn off the
|
|
46
|
+
bottom of the image. The test config now sizes the window to fit, and the
|
|
47
|
+
skill's traps section explains how to do the same.
|
|
48
|
+
|
|
49
|
+
### Security
|
|
50
|
+
|
|
51
|
+
- `sharp` now needs 0.35.5 or later. Earlier versions bundle a librsvg affected
|
|
52
|
+
by CVE-2026-96889 ([GHSA-wq5f-xc86-pv6w](https://github.com/advisories/GHSA-wq5f-xc86-pv6w)),
|
|
53
|
+
and librsvg is what renders the overlay.
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
- `annotateImage()` takes `captureReport: { pixelRatio, scaled }`, and
|
|
58
|
+
`resolveScale()` takes it as an optional fifth argument, for callers outside
|
|
59
|
+
Cypress whose capture tool reports the same thing.
|
|
60
|
+
|
|
6
61
|
## 1.0.0
|
|
7
62
|
|
|
8
63
|
The package shipped two products under one name. `cy.annotate()` and the failure
|
package/DOCS/internals.md
CHANGED
|
@@ -77,8 +77,8 @@ Playwright pipeline they were written for.
|
|
|
77
77
|
|
|
78
78
|
```bash
|
|
79
79
|
npm install
|
|
80
|
-
npm run test:cypress # cy.annotate and theming,
|
|
81
|
-
npm run test:cypress-failures # failed-test capture end to end,
|
|
80
|
+
npm run test:cypress # cy.annotate and theming, 14 cases, real Cypress 15
|
|
81
|
+
npm run test:cypress-failures # failed-test capture end to end, 8 cases, real Cypress 15
|
|
82
82
|
npm run test:failure-selector # failed-test selector recovery, 12 cases, no browser
|
|
83
83
|
npm run test:svg-escaping # SVG injection regression suite, 9 cases
|
|
84
84
|
npm run typecheck
|
package/dist/annotate-image.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnnotationStyle, CssRect, PageMetrics, PixelRect, ShapeKind } from './types.js';
|
|
1
|
+
import type { AnnotationStyle, CaptureReport, CssRect, PageMetrics, PixelRect, ShapeKind } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Annotating an image that somebody else captured.
|
|
4
4
|
*
|
|
@@ -33,6 +33,12 @@ export interface AnnotateImageOptions {
|
|
|
33
33
|
/** Context to keep around the target when cropping, CSS px. Default 40. */
|
|
34
34
|
cropPadding?: number;
|
|
35
35
|
style?: AnnotationStyle;
|
|
36
|
+
/**
|
|
37
|
+
* What the capturing tool reported about the image. Without it, the scale is
|
|
38
|
+
* inferred from the image width, which cannot tell a resized image from one
|
|
39
|
+
* the browser window cut short.
|
|
40
|
+
*/
|
|
41
|
+
captureReport?: CaptureReport;
|
|
36
42
|
}
|
|
37
43
|
export interface AnnotateImageResult {
|
|
38
44
|
image: Buffer;
|
|
@@ -42,6 +48,7 @@ export interface AnnotateImageResult {
|
|
|
42
48
|
height: number;
|
|
43
49
|
/** Image pixels per CSS pixel actually used. */
|
|
44
50
|
scale: number;
|
|
51
|
+
/** One per target that landed in the image. A target outside it is skipped, with a warning. */
|
|
45
52
|
drawnRects: PixelRect[];
|
|
46
53
|
warnings: string[];
|
|
47
54
|
}
|
|
@@ -59,7 +66,12 @@ export declare function resolveStyle(...layers: (AnnotationStyle | undefined)[])
|
|
|
59
66
|
* screenshots to keep them cheap to send, and a capture that has been resized
|
|
60
67
|
* behind your back is exactly what makes a box drift. So the image is measured
|
|
61
68
|
* and the reported ratio is treated as a hint.
|
|
69
|
+
*
|
|
70
|
+
* A narrow image has a second explanation, though. A headless browser window
|
|
71
|
+
* smaller than the viewport captures only its top-left corner, at full scale,
|
|
72
|
+
* and width alone cannot tell that apart from a resize. So when the capturing
|
|
73
|
+
* tool says the image was not resized, its pixel ratio wins.
|
|
62
74
|
*/
|
|
63
|
-
export declare function resolveScale(imageWidth: number, cssWidth: number, devicePixelRatio: number, warnings: string[]): number;
|
|
75
|
+
export declare function resolveScale(imageWidth: number, cssWidth: number, devicePixelRatio: number, warnings: string[], report?: CaptureReport): number;
|
|
64
76
|
export declare function annotateImage(screenshot: Buffer, targets: MeasuredTarget[], options: AnnotateImageOptions): Promise<AnnotateImageResult>;
|
|
65
77
|
//# sourceMappingURL=annotate-image.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotate-image.d.ts","sourceRoot":"","sources":["../src/annotate-image.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,eAAe,EACf,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AAEH,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,YAAY,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gFAAgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,WAAW,CAAC;IACrB,uEAAuE;IACvE,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IAClC,+CAA+C;IAC/C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,2EAA2E;IAC3E,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"annotate-image.d.ts","sourceRoot":"","sources":["../src/annotate-image.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AAEH,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,YAAY,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gFAAgF;IAChF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,gEAAgE;IACh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and a capture that has been resized
|
|
62
62
|
* behind your back is exactly what makes a box drift. So the image is measured
|
|
63
63
|
* and the reported ratio is treated as a hint.
|
|
64
|
+
*
|
|
65
|
+
* A narrow image has a second explanation, though. A headless browser window
|
|
66
|
+
* smaller than the viewport captures only its top-left corner, at full scale,
|
|
67
|
+
* and width alone cannot tell that apart from a resize. So when the capturing
|
|
68
|
+
* tool says the image was not resized, its pixel ratio wins.
|
|
64
69
|
*/
|
|
65
|
-
export function resolveScale(imageWidth, cssWidth, devicePixelRatio, warnings) {
|
|
70
|
+
export function resolveScale(imageWidth, cssWidth, devicePixelRatio, warnings, report) {
|
|
71
|
+
if (report && !report.scaled && report.pixelRatio > 0)
|
|
72
|
+
return report.pixelRatio;
|
|
66
73
|
if (cssWidth <= 0) {
|
|
67
74
|
warnings.push('Page metrics reported a zero-width viewport; falling back to devicePixelRatio.');
|
|
68
75
|
return devicePixelRatio;
|
|
@@ -100,7 +107,17 @@ export async function annotateImage(screenshot, targets, options) {
|
|
|
100
107
|
if (imageWidth === 0 || imageHeight === 0)
|
|
101
108
|
throw new Error('Could not read the screenshot dimensions.');
|
|
102
109
|
const cssWidth = fullPage ? metrics.documentWidth : metrics.viewportWidth;
|
|
103
|
-
const
|
|
110
|
+
const cssHeight = fullPage ? metrics.documentHeight : metrics.viewportHeight;
|
|
111
|
+
const scale = resolveScale(imageWidth, cssWidth, metrics.devicePixelRatio, warnings, options.captureReport);
|
|
112
|
+
// The CSS area the image actually holds, from its own top-left corner.
|
|
113
|
+
const coveredWidth = imageWidth / scale;
|
|
114
|
+
const coveredHeight = imageHeight / scale;
|
|
115
|
+
if (coveredWidth < cssWidth - 1 || coveredHeight < cssHeight - 1) {
|
|
116
|
+
warnings.push(`Screenshot covers only ${Math.round(coveredWidth)}x${Math.round(coveredHeight)} CSS px of the ` +
|
|
117
|
+
`${Math.round(cssWidth)}x${Math.round(cssHeight)} ${fullPage ? 'page' : 'viewport'}, which usually ` +
|
|
118
|
+
`means the browser window is smaller than the viewport. Size the window to match in before:browser:launch.`);
|
|
119
|
+
}
|
|
120
|
+
const placed = [];
|
|
104
121
|
for (const target of targets) {
|
|
105
122
|
const name = target.describe ?? 'target';
|
|
106
123
|
if (target.viewportRect.width === 0 || target.viewportRect.height === 0) {
|
|
@@ -110,18 +127,26 @@ export async function annotateImage(screenshot, targets, options) {
|
|
|
110
127
|
warnings.push(`${name} is position:fixed, so it has no stable document position in a full-page capture; ` +
|
|
111
128
|
`annotated where it was painted.`);
|
|
112
129
|
}
|
|
113
|
-
}
|
|
114
|
-
const sourceRects = targets.map((target) => {
|
|
115
|
-
const style = resolveStyle(options.style, target.style);
|
|
116
130
|
const base = fullPage ? documentRectOf(target, metrics) : target.viewportRect;
|
|
117
|
-
|
|
118
|
-
|
|
131
|
+
const right = base.x + base.width;
|
|
132
|
+
const bottom = base.y + base.height;
|
|
133
|
+
if (base.x >= coveredWidth || base.y >= coveredHeight || right <= 0 || bottom <= 0) {
|
|
134
|
+
warnings.push(`${name} is outside the captured area, so no box was drawn for it.`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (base.x < 0 || base.y < 0 || right > coveredWidth || bottom > coveredHeight) {
|
|
138
|
+
warnings.push(`${name} runs past the edge of the captured area; its box is clipped.`);
|
|
139
|
+
}
|
|
140
|
+
const style = resolveStyle(options.style, target.style);
|
|
141
|
+
placed.push({ target, rect: scaleRect(inflate(base, style.padding), scale) });
|
|
142
|
+
}
|
|
143
|
+
const sourceRects = placed.map((p) => p.rect);
|
|
119
144
|
let finalImage = screenshot;
|
|
120
145
|
let finalWidth = imageWidth;
|
|
121
146
|
let finalHeight = imageHeight;
|
|
122
147
|
let originX = 0;
|
|
123
148
|
let originY = 0;
|
|
124
|
-
if (options.crop) {
|
|
149
|
+
if (options.crop && sourceRects.length > 0) {
|
|
125
150
|
const pad = (options.cropPadding ?? 40) * scale;
|
|
126
151
|
const union = sourceRects.reduce((acc, r) => {
|
|
127
152
|
const x = Math.min(acc.x, r.x);
|
|
@@ -152,7 +177,7 @@ export async function annotateImage(screenshot, targets, options) {
|
|
|
152
177
|
}
|
|
153
178
|
const drawnRects = sourceRects.map((r) => ({ ...r, x: r.x - originX, y: r.y - originY }));
|
|
154
179
|
const specs = drawnRects.map((rect, i) => {
|
|
155
|
-
const target =
|
|
180
|
+
const target = placed[i]?.target;
|
|
156
181
|
const style = resolveStyle(options.style, target?.style);
|
|
157
182
|
return {
|
|
158
183
|
rect,
|
|
@@ -161,7 +186,11 @@ export async function annotateImage(screenshot, targets, options) {
|
|
|
161
186
|
style: toDeviceStyle(style, scale),
|
|
162
187
|
};
|
|
163
188
|
});
|
|
164
|
-
|
|
189
|
+
// Nothing landed in the image, so leave it untouched. Dimming everything
|
|
190
|
+
// outside zero boxes would only darken the whole screenshot.
|
|
191
|
+
const image = specs.length > 0
|
|
192
|
+
? await compositeOverlay(finalImage, buildOverlaySvg(finalWidth, finalHeight, specs))
|
|
193
|
+
: finalImage;
|
|
165
194
|
return {
|
|
166
195
|
image,
|
|
167
196
|
rawImage: finalImage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cypress/commands.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cypress/commands.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAiB,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7E;;;;;;;;GAQG;AAEH;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gFAAgF;IAChF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,2EAA2E;IAC3E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAgGnC,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,SAAS;YACjB;;;;;;;;;;;eAWG;YACH,QAAQ,CACN,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,EACjD,OAAO,CAAC,EAAE,sBAAsB,GAC/B,SAAS,CAAC,kBAAkB,CAAC,CAAC;SAClC;KACF;CACF"}
|
package/dist/cypress/commands.js
CHANGED
|
@@ -44,6 +44,7 @@ Cypress.Commands.add('annotate', (target, options = {}) => {
|
|
|
44
44
|
})
|
|
45
45
|
.then((measurement) => {
|
|
46
46
|
let screenshotPath;
|
|
47
|
+
let captureReport;
|
|
47
48
|
return cy
|
|
48
49
|
.screenshot(name, {
|
|
49
50
|
capture,
|
|
@@ -51,6 +52,11 @@ Cypress.Commands.add('annotate', (target, options = {}) => {
|
|
|
51
52
|
log: false,
|
|
52
53
|
onAfterScreenshot(_el, props) {
|
|
53
54
|
screenshotPath = props.path;
|
|
55
|
+
// Cypress sets `scaled` at runtime but leaves it out of its types.
|
|
56
|
+
// Without it, send nothing and let the scale be inferred as before.
|
|
57
|
+
const scaled = props.scaled;
|
|
58
|
+
if (typeof scaled === 'boolean')
|
|
59
|
+
captureReport = { pixelRatio: props.pixelRatio, scaled };
|
|
54
60
|
},
|
|
55
61
|
})
|
|
56
62
|
.then(() => {
|
|
@@ -60,6 +66,7 @@ Cypress.Commands.add('annotate', (target, options = {}) => {
|
|
|
60
66
|
return cy.task('annotateScreenshot', {
|
|
61
67
|
screenshotPath,
|
|
62
68
|
measurement,
|
|
69
|
+
captureReport,
|
|
63
70
|
labels,
|
|
64
71
|
capture,
|
|
65
72
|
crop: options.crop ?? defaults.crop,
|
|
@@ -25,6 +25,11 @@ export interface FailureCaptureOptions {
|
|
|
25
25
|
* Requires `screenshotOnRunFailure: false` in cypress.config.ts - otherwise
|
|
26
26
|
* Cypress's own automatic failure screenshot and this hook's screenshot race,
|
|
27
27
|
* and it becomes ambiguous which one the DOM measurement actually matches.
|
|
28
|
+
*
|
|
29
|
+
* The hook must never fail the run. A failing afterEach makes Cypress skip
|
|
30
|
+
* every remaining test in the spec, which is far worse than a missing box. So
|
|
31
|
+
* every step that can fail does so softly and leaves a warning, and a `fail`
|
|
32
|
+
* handler catches anything that still gets through.
|
|
28
33
|
*/
|
|
29
34
|
export declare function registerFailureCapture(options?: FailureCaptureOptions): void;
|
|
30
35
|
//# sourceMappingURL=failure-hook.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"failure-hook.d.ts","sourceRoot":"","sources":["../../src/cypress/failure-hook.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"failure-hook.d.ts","sourceRoot":"","sources":["../../src/cypress/failure-hook.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,aAAa,CAAC;AAG/E,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,qBAA0B,GAAG,IAAI,CAwKhF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="cypress" />
|
|
2
2
|
import { describeFailure, recoverFailure } from './failure-selector.js';
|
|
3
3
|
import { collectInventory, measureTargets, readMetrics } from './measure-dom.js';
|
|
4
|
-
import { isFullyVisible
|
|
4
|
+
import { isFullyVisible } from './scroll-into-view.js';
|
|
5
5
|
import { readAnnotateConfig, DEFAULT_REPORT_PATH } from './config.js';
|
|
6
6
|
function slugify(text) {
|
|
7
7
|
return text.replace(/[^a-z0-9]+/gi, '-').replace(/^-+|-+$/g, '').toLowerCase().slice(0, 60) || 'failure';
|
|
@@ -27,11 +27,23 @@ function slugify(text) {
|
|
|
27
27
|
* Requires `screenshotOnRunFailure: false` in cypress.config.ts - otherwise
|
|
28
28
|
* Cypress's own automatic failure screenshot and this hook's screenshot race,
|
|
29
29
|
* and it becomes ambiguous which one the DOM measurement actually matches.
|
|
30
|
+
*
|
|
31
|
+
* The hook must never fail the run. A failing afterEach makes Cypress skip
|
|
32
|
+
* every remaining test in the spec, which is far worse than a missing box. So
|
|
33
|
+
* every step that can fail does so softly and leaves a warning, and a `fail`
|
|
34
|
+
* handler catches anything that still gets through.
|
|
30
35
|
*/
|
|
31
36
|
export function registerFailureCapture(options = {}) {
|
|
32
37
|
afterEach(function () {
|
|
33
38
|
if (this.currentTest?.state !== 'failed')
|
|
34
39
|
return;
|
|
40
|
+
// cy.on binds to the current runnable, so this covers the hook and is gone
|
|
41
|
+
// by the next test. Returning false abandons the hook's remaining commands,
|
|
42
|
+
// which is why it is only the backstop.
|
|
43
|
+
cy.on('fail', (error) => {
|
|
44
|
+
Cypress.log({ name: 'annotate', message: `! Failure capture gave up: ${error.message}` });
|
|
45
|
+
return false;
|
|
46
|
+
});
|
|
35
47
|
// Read inside the hook rather than at registration: the support file is
|
|
36
48
|
// evaluated before Cypress has finished setting up env for the spec.
|
|
37
49
|
const defaults = readAnnotateConfig();
|
|
@@ -59,38 +71,37 @@ export function registerFailureCapture(options = {}) {
|
|
|
59
71
|
* viewport, so unlike cy.annotate() it may sit well below the fold - the
|
|
60
72
|
* whole reason this exists is to point at a mismatch, so screenshotting a
|
|
61
73
|
* viewport that never contains the mismatch would be a silent no-op box.
|
|
74
|
+
*
|
|
75
|
+
* The scroll is done synchronously on the element just measured. A cy.get
|
|
76
|
+
* here would re-query, and if the page re-rendered in between it would
|
|
77
|
+
* wait out the whole command timeout and then fail the hook.
|
|
62
78
|
*/
|
|
63
79
|
function prepare(win) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
80
|
+
const selector = recovered.selector && !recovered.elementNotFound ? recovered.selector : null;
|
|
81
|
+
let target = selector ? measureTargets(win, [selector]).targets[0] : undefined;
|
|
82
|
+
if (selector && target?.found && target.rect && !isFullyVisible(target.rect, win)) {
|
|
83
|
+
const el = win.document.querySelector(selector);
|
|
84
|
+
if (el) {
|
|
85
|
+
const offset = defaults.scrollOffset ?? 120;
|
|
86
|
+
el.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'instant' });
|
|
87
|
+
win.scrollBy({ top: -offset, behavior: 'instant' });
|
|
88
|
+
// The rect from before the scroll is meaningless now.
|
|
89
|
+
target = measureTargets(win, [selector]).targets[0];
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
target: target ?? null,
|
|
84
|
-
resolved,
|
|
85
|
-
inventory: resolved ? null : collectInventory(w),
|
|
86
|
-
metrics: readMetrics(w),
|
|
87
|
-
};
|
|
88
|
-
});
|
|
92
|
+
const resolved = Boolean(target?.found && target.rect);
|
|
93
|
+
return {
|
|
94
|
+
target: target ?? null,
|
|
95
|
+
resolved,
|
|
96
|
+
inventory: resolved ? null : collectInventory(win),
|
|
97
|
+
metrics: readMetrics(win),
|
|
98
|
+
};
|
|
89
99
|
}
|
|
90
100
|
cy.window({ log: false })
|
|
91
|
-
.then((win) => prepare(win))
|
|
101
|
+
.then((win) => cy.wrap(prepare(win), { log: false }))
|
|
92
102
|
.then(({ target, resolved, inventory, metrics }) => {
|
|
93
103
|
let screenshotPath;
|
|
104
|
+
let captureReport;
|
|
94
105
|
return cy
|
|
95
106
|
.screenshot(name, {
|
|
96
107
|
capture: 'viewport',
|
|
@@ -98,6 +109,11 @@ export function registerFailureCapture(options = {}) {
|
|
|
98
109
|
log: false,
|
|
99
110
|
onAfterScreenshot(_el, props) {
|
|
100
111
|
screenshotPath = props.path;
|
|
112
|
+
// Cypress sets `scaled` at runtime but leaves it out of its types.
|
|
113
|
+
// Without it, send nothing and let the scale be inferred as before.
|
|
114
|
+
const scaled = props.scaled;
|
|
115
|
+
if (typeof scaled === 'boolean')
|
|
116
|
+
captureReport = { pixelRatio: props.pixelRatio, scaled };
|
|
101
117
|
},
|
|
102
118
|
})
|
|
103
119
|
.then(() => {
|
|
@@ -107,9 +123,10 @@ export function registerFailureCapture(options = {}) {
|
|
|
107
123
|
if (!resolved) {
|
|
108
124
|
return cy.wrap(null, { log: false });
|
|
109
125
|
}
|
|
110
|
-
return cy.task('
|
|
126
|
+
return cy.task('annotateScreenshotSoft', {
|
|
111
127
|
screenshotPath,
|
|
112
128
|
measurement: { metrics, targets: [target] },
|
|
129
|
+
captureReport,
|
|
113
130
|
labels: [label],
|
|
114
131
|
capture: 'viewport',
|
|
115
132
|
style: { ...defaults.style, ...options.style },
|
|
@@ -117,9 +134,17 @@ export function registerFailureCapture(options = {}) {
|
|
|
117
134
|
manifestPath: defaults.manifestPath,
|
|
118
135
|
spec: Cypress.spec.relative,
|
|
119
136
|
test: testTitle,
|
|
120
|
-
});
|
|
137
|
+
}, { log: false });
|
|
121
138
|
})
|
|
122
|
-
.then((
|
|
139
|
+
.then((soft) => {
|
|
140
|
+
const annotateResult = soft && 'result' in soft ? soft.result : null;
|
|
141
|
+
const warnings = [...(annotateResult?.warnings ?? [])];
|
|
142
|
+
if (soft && 'error' in soft) {
|
|
143
|
+
warnings.push(`Annotating the screenshot failed, so it was kept as it was: ${soft.error}`);
|
|
144
|
+
}
|
|
145
|
+
for (const warning of warnings) {
|
|
146
|
+
Cypress.log({ name: 'annotate', message: `! ${warning}` });
|
|
147
|
+
}
|
|
123
148
|
const record = {
|
|
124
149
|
spec: Cypress.spec.relative,
|
|
125
150
|
test: testTitle,
|
|
@@ -145,10 +170,16 @@ export function registerFailureCapture(options = {}) {
|
|
|
145
170
|
rect: item.rect,
|
|
146
171
|
}))
|
|
147
172
|
: null,
|
|
148
|
-
warnings
|
|
173
|
+
warnings,
|
|
149
174
|
timestamp: new Date().toISOString(),
|
|
150
175
|
};
|
|
151
|
-
return cy
|
|
176
|
+
return cy
|
|
177
|
+
.task('appendFailureRecord', { reportPath, record }, { log: false })
|
|
178
|
+
.then((written) => {
|
|
179
|
+
if ('error' in written) {
|
|
180
|
+
Cypress.log({ name: 'annotate', message: `! Could not write ${reportPath}: ${written.error}` });
|
|
181
|
+
}
|
|
182
|
+
});
|
|
152
183
|
});
|
|
153
184
|
});
|
|
154
185
|
});
|
package/dist/cypress/task.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnnotationStyle, PixelRect, ShapeKind } from '../types.js';
|
|
1
|
+
import type { AnnotationStyle, CaptureReport, PixelRect, ShapeKind } from '../types.js';
|
|
2
2
|
import type { DomMeasurement } from './measure-dom.js';
|
|
3
3
|
/**
|
|
4
4
|
* The Node half of the Cypress plugin.
|
|
@@ -10,6 +10,8 @@ import type { DomMeasurement } from './measure-dom.js';
|
|
|
10
10
|
export interface AnnotateTaskArgs {
|
|
11
11
|
screenshotPath: string;
|
|
12
12
|
measurement: DomMeasurement;
|
|
13
|
+
/** `pixelRatio` and `scaled` from Cypress's `onAfterScreenshot` props. */
|
|
14
|
+
captureReport?: CaptureReport;
|
|
13
15
|
labels?: (string | undefined)[];
|
|
14
16
|
capture?: 'viewport' | 'fullPage';
|
|
15
17
|
crop?: boolean;
|
|
@@ -52,6 +54,16 @@ export interface AnnotateTaskResult {
|
|
|
52
54
|
drawnRects: PixelRect[];
|
|
53
55
|
warnings: string[];
|
|
54
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* What the failure hook's tasks return in place of throwing. A task that throws
|
|
59
|
+
* fails the cy.task that called it, and inside the hook's afterEach that skips
|
|
60
|
+
* the rest of the spec.
|
|
61
|
+
*/
|
|
62
|
+
export type SoftResult<T> = {
|
|
63
|
+
result: T;
|
|
64
|
+
} | {
|
|
65
|
+
error: string;
|
|
66
|
+
};
|
|
55
67
|
export declare function annotateScreenshot(args: AnnotateTaskArgs): Promise<AnnotateTaskResult>;
|
|
56
68
|
/**
|
|
57
69
|
* Cypress's `on` is a set of overloads, one per event. Naming it precisely
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../src/cypress/task.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../src/cypress/task.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIvD;;;;;;GAMG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,cAAc,CAAC;IAC5B,0EAA0E;IAC1E,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,MAAM,CAAC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A;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAgD9D,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6E5F;AAED;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAI5D,iFAAiF;AACjF,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAa9F"}
|
package/dist/cypress/task.js
CHANGED
|
@@ -3,6 +3,14 @@ import { relative } from 'node:path';
|
|
|
3
3
|
import { annotateImage } from '../annotate-image.js';
|
|
4
4
|
import { appendFailureRecord, appendRecord } from './failure-report.js';
|
|
5
5
|
import { DEFAULT_MANIFEST_PATH } from './config.js';
|
|
6
|
+
async function soft(work) {
|
|
7
|
+
try {
|
|
8
|
+
return { result: await work() };
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
6
14
|
/**
|
|
7
15
|
* Manifest paths already written to by this process. Cypress runs the whole of
|
|
8
16
|
* `cypress run` in one Node process, so "first write of the process" is the
|
|
@@ -72,6 +80,7 @@ export async function annotateScreenshot(args) {
|
|
|
72
80
|
crop: args.crop,
|
|
73
81
|
cropPadding: args.cropPadding,
|
|
74
82
|
style: args.style,
|
|
83
|
+
captureReport: args.captureReport,
|
|
75
84
|
});
|
|
76
85
|
const outPath = args.outPath ?? screenshotPath;
|
|
77
86
|
let rawPath = null;
|
|
@@ -119,6 +128,9 @@ export async function annotateScreenshot(args) {
|
|
|
119
128
|
export function registerAnnotateTasks(on, _config) {
|
|
120
129
|
on('task', {
|
|
121
130
|
annotateScreenshot: ((args) => annotateScreenshot(args)),
|
|
122
|
-
|
|
131
|
+
// The failure hook's two tasks never throw. cy.annotate() keeps the one
|
|
132
|
+
// above, which does, because an explicit call should fail loudly.
|
|
133
|
+
annotateScreenshotSoft: ((args) => soft(() => annotateScreenshot(args))),
|
|
134
|
+
appendFailureRecord: ((args) => soft(() => appendFailureRecord(args))),
|
|
123
135
|
});
|
|
124
136
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -25,6 +25,16 @@ export interface PageMetrics {
|
|
|
25
25
|
documentWidth: number;
|
|
26
26
|
documentHeight: number;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* What the tool that took the screenshot says about it. Cypress hands this to
|
|
30
|
+
* `onAfterScreenshot` as `props.pixelRatio` and `props.scaled`.
|
|
31
|
+
*/
|
|
32
|
+
export interface CaptureReport {
|
|
33
|
+
/** Image pixels per CSS pixel at capture time. */
|
|
34
|
+
pixelRatio: number;
|
|
35
|
+
/** Whether the image was resized after capture. */
|
|
36
|
+
scaled: boolean;
|
|
37
|
+
}
|
|
28
38
|
export type ShapeKind = 'box' | 'circle' | 'arrow';
|
|
29
39
|
export interface AnnotationStyle {
|
|
30
40
|
/** CSS colour for the outline and label background. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,WAAW,OAAO;IACtB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,iFAAiF;AACjF,MAAM,WAAW,SAAS;IACxB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,M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|
|
4
4
|
"description": "Draw a box on exactly what failed. Every failed Cypress test gets an annotated screenshot, in CI, with no AI and no browser download.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cypress",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"typecheck": "tsc --noEmit"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"sharp": "^0.35.
|
|
103
|
+
"sharp": "^0.35.5"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"cypress": ">=13"
|
|
@@ -141,6 +141,10 @@ Where no selector can be recovered, such as an existence check or a
|
|
|
141
141
|
of candidate elements, since the browser session is gone by the time anyone reads
|
|
142
142
|
the report.
|
|
143
143
|
|
|
144
|
+
The hook can't fail the run. If annotating or writing the report goes wrong, the
|
|
145
|
+
plain screenshot is kept, the reason goes into the Cypress log and the record's
|
|
146
|
+
`warnings`, and the next test runs as normal.
|
|
147
|
+
|
|
144
148
|
## Traps
|
|
145
149
|
|
|
146
150
|
**Don't use `fullPage: true` casually.** Cypress builds a full-page screenshot by
|
|
@@ -156,6 +160,17 @@ genuinely needed.
|
|
|
156
160
|
scroll, or click. A rectangle is only valid for the scroll position it was
|
|
157
161
|
measured at. Using `cy.annotate()` rather than hand-rolling this is the point.
|
|
158
162
|
|
|
163
|
+
**A viewport bigger than the headless window is captured only up to the
|
|
164
|
+
window's edge.** Headless browsers open at 1280x720, so `viewportWidth: 1920`
|
|
165
|
+
gets a screenshot of the viewport's top-left 1280x720 corner. The box still lands
|
|
166
|
+
in the right place, but anything past that corner has no box and a warning in
|
|
167
|
+
`annotations.json`. Size the window to match in `before:browser:launch`, with
|
|
168
|
+
`--window-size=1920,1080` for Chrome or `launchOptions.preferences.width` and
|
|
169
|
+
`height` for Electron. Headless Chrome also keeps 87px of its window height for
|
|
170
|
+
UI it never draws, so its default 1280x720 window captures only 1280x633, which
|
|
171
|
+
cuts the bottom off even Cypress's default 1000x660 viewport. Make the Chrome
|
|
172
|
+
window 87px taller than the viewport.
|
|
173
|
+
|
|
159
174
|
**Exact-colour assertions fail on macOS Electron.** Its capture applies a
|
|
160
175
|
colour-profile shift, so `#FF00E4` comes back as `rgb(234,51,221)`. Sample the
|
|
161
176
|
colour from the image rather than trusting the stylesheet.
|