@circi/cypress 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +82 -2
- package/dist/index.d.mts +332 -0
- package/dist/index.mjs +4382 -0
- package/dist/index.mjs.map +1 -0
- package/dist/names-D1laAiFj.mjs +51 -0
- package/dist/names-D1laAiFj.mjs.map +1 -0
- package/dist/support.d.mts +1 -0
- package/dist/support.mjs +161 -0
- package/dist/support.mjs.map +1 -0
- package/package.json +58 -3
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// ../cli/dist/names.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Where a capture goes, and what CirCI calls it. Pure string work, shared by the browser-side
|
|
4
|
+
* matcher and the tests; it imports nothing, so a browser bundle can load it.
|
|
5
|
+
*/
|
|
6
|
+
/** Vitest's own rule for a screenshot name: words kept, whitespace to dashes, the rest dropped. */
|
|
7
|
+
function sanitize(input) {
|
|
8
|
+
return input.replace(/\s+/g, "-").replace(/[^\w-]+/g, "").replace(/-{2,}/g, "-");
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A screenshot's file name from the `name` given to `toMatchScreenshot`, or from the generated
|
|
12
|
+
* `<describe> > <test> <n>` when none was given. The same rule Vitest applies to its own
|
|
13
|
+
* references, so a name means the same file in both: `/` keeps folders, nothing escapes upward.
|
|
14
|
+
*/
|
|
15
|
+
function captureName(name) {
|
|
16
|
+
const parts = (name.endsWith(".png") ? name.slice(0, -4) : name).split("/").filter((part) => part !== ".." && part !== ".").map(sanitize).filter((part) => part.length > 0);
|
|
17
|
+
if (parts.length === 0) throw new Error(`"${name}" is not a usable screenshot name`);
|
|
18
|
+
return parts.join("/");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The path of a capture relative to the project root: `<dir>/<test file>/<name>.png`, with the test
|
|
22
|
+
* file relative to the root too, so two tests with the same screenshot name never share a file.
|
|
23
|
+
*/
|
|
24
|
+
function capturePath(dir, testFile, name) {
|
|
25
|
+
const file = testFile.split(/[\\/]/).filter((part) => part.length > 0 && part !== "." && part !== "..").join("/");
|
|
26
|
+
return `${dir.replace(/\/+$/, "")}/${file}/${captureName(name)}.png`;
|
|
27
|
+
}
|
|
28
|
+
/** Where captures go unless told otherwise, relative to the project root. */
|
|
29
|
+
const DEFAULT_DIR = ".circi/screenshots";
|
|
30
|
+
/**
|
|
31
|
+
* The folder a tool owns inside the captures' folder: `.circi/screenshots/vitest`,
|
|
32
|
+
* `.circi/screenshots/storybook`, `.circi/screenshots/cypress`. `dir` is the parent, the same for
|
|
33
|
+
* every tool (`options.dir ?? DEFAULT_DIR`); a tool writes, cleans and uploads only its own
|
|
34
|
+
* folder, so two tools in one project never upload or delete each other's captures. Names in CirCI
|
|
35
|
+
* are relative to the tool's folder, so they don't carry the tool's name.
|
|
36
|
+
*/
|
|
37
|
+
function toolDir(dir, tool) {
|
|
38
|
+
return `${dir.replace(/\/+$/, "")}/${tool}`;
|
|
39
|
+
}
|
|
40
|
+
/** CSS that stops everything that moves or blinks, so a screenshot doesn't catch a frame halfway. */
|
|
41
|
+
const STABILIZE_CSS = `
|
|
42
|
+
*, *::before, *::after {
|
|
43
|
+
animation: none !important;
|
|
44
|
+
transition: none !important;
|
|
45
|
+
caret-color: transparent !important;
|
|
46
|
+
scroll-behavior: auto !important;
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
export { toolDir as i, STABILIZE_CSS as n, capturePath as r, DEFAULT_DIR as t };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=names-D1laAiFj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names-D1laAiFj.mjs","names":[],"sources":["../../cli/src/names.ts"],"sourcesContent":["/**\n * Where a capture goes, and what CirCI calls it. Pure string work, shared by the browser-side\n * matcher and the tests; it imports nothing, so a browser bundle can load it.\n */\n\n/** Vitest's own rule for a screenshot name: words kept, whitespace to dashes, the rest dropped. */\nfunction sanitize(input: string): string {\n return input\n .replace(/\\s+/g, '-')\n .replace(/[^\\w-]+/g, '')\n .replace(/-{2,}/g, '-')\n}\n\n/**\n * A screenshot's file name from the `name` given to `toMatchScreenshot`, or from the generated\n * `<describe> > <test> <n>` when none was given. The same rule Vitest applies to its own\n * references, so a name means the same file in both: `/` keeps folders, nothing escapes upward.\n */\nexport function captureName(name: string): string {\n const withoutExtension = name.endsWith('.png') ? name.slice(0, -'.png'.length) : name\n const parts = withoutExtension\n .split('/')\n .filter((part) => part !== '..' && part !== '.')\n .map(sanitize)\n .filter((part) => part.length > 0)\n if (parts.length === 0) throw new Error(`\"${name}\" is not a usable screenshot name`)\n return parts.join('/')\n}\n\n/**\n * The path of a capture relative to the project root: `<dir>/<test file>/<name>.png`, with the test\n * file relative to the root too, so two tests with the same screenshot name never share a file.\n */\nexport function capturePath(dir: string, testFile: string, name: string): string {\n const file = testFile\n .split(/[\\\\/]/)\n .filter((part) => part.length > 0 && part !== '.' && part !== '..')\n .join('/')\n return `${dir.replace(/\\/+$/, '')}/${file}/${captureName(name)}.png`\n}\n\n/** Where captures go unless told otherwise, relative to the project root. */\nexport const DEFAULT_DIR = '.circi/screenshots'\n\n/**\n * The folder a tool owns inside the captures' folder: `.circi/screenshots/vitest`,\n * `.circi/screenshots/storybook`, `.circi/screenshots/cypress`. `dir` is the parent, the same for\n * every tool (`options.dir ?? DEFAULT_DIR`); a tool writes, cleans and uploads only its own\n * folder, so two tools in one project never upload or delete each other's captures. Names in CirCI\n * are relative to the tool's folder, so they don't carry the tool's name.\n */\nexport function toolDir(dir: string, tool: string): string {\n return `${dir.replace(/\\/+$/, '')}/${tool}`\n}\n\n/** CSS that stops everything that moves or blinks, so a screenshot doesn't catch a frame halfway. */\nexport const STABILIZE_CSS = `\n*, *::before, *::after {\n animation: none !important;\n transition: none !important;\n caret-color: transparent !important;\n scroll-behavior: auto !important;\n}\n`\n"],"mappings":";;;;;;AAMA,SAAS,SAAS,OAAuB;CACvC,OAAO,MACJ,QAAQ,QAAQ,GAAG,CAAC,CACpB,QAAQ,YAAY,EAAE,CAAC,CACvB,QAAQ,UAAU,GAAG;AAC1B;;;;;;AAOA,SAAgB,YAAY,MAAsB;CAEhD,MAAM,SADmB,KAAK,SAAS,MAAM,IAAI,KAAK,MAAM,GAAG,EAAc,IAAI,KAAA,CAE9E,MAAM,GAAG,CAAC,CACV,QAAQ,SAAS,SAAS,QAAQ,SAAS,GAAG,CAAC,CAC/C,IAAI,QAAQ,CAAC,CACb,QAAQ,SAAS,KAAK,SAAS,CAAC;CACnC,IAAI,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,IAAI,KAAK,kCAAkC;CACnF,OAAO,MAAM,KAAK,GAAG;AACvB;;;;;AAMA,SAAgB,YAAY,KAAa,UAAkB,MAAsB;CAC/E,MAAM,OAAO,SACV,MAAM,OAAO,CAAC,CACd,QAAQ,SAAS,KAAK,SAAS,KAAK,SAAS,OAAO,SAAS,IAAI,CAAC,CAClE,KAAK,GAAG;CACX,OAAO,GAAG,IAAI,QAAQ,QAAQ,EAAE,EAAE,GAAG,KAAK,GAAG,YAAY,IAAI,EAAE;AACjE;;AAGA,MAAa,cAAc;;;;;;;;AAS3B,SAAgB,QAAQ,KAAa,MAAsB;CACzD,OAAO,GAAG,IAAI,QAAQ,QAAQ,EAAE,EAAE,GAAG;AACvC;;AAGA,MAAa,gBAAgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/support.mjs
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { n as STABILIZE_CSS } from "./names-D1laAiFj.mjs";
|
|
2
|
+
// src/page.ts
|
|
3
|
+
/**
|
|
4
|
+
* Browser-side steps behind `cy.screenshot()`: make the page hold still, and decide what the
|
|
5
|
+
* picture is of so that it holds the thing and nothing around it. Runs inside the page, so it uses
|
|
6
|
+
* the DOM; Node never imports it.
|
|
7
|
+
*/
|
|
8
|
+
const STABILIZE_ID = "circi-stabilize";
|
|
9
|
+
const frame = (win) => new Promise((r) => win.requestAnimationFrame(() => r()));
|
|
10
|
+
/** Add the stabilizing style, then wait for fonts and two painted frames. */
|
|
11
|
+
async function settle(win) {
|
|
12
|
+
const doc = win.document;
|
|
13
|
+
if (!doc.getElementById("circi-stabilize")) {
|
|
14
|
+
const style = doc.createElement("style");
|
|
15
|
+
style.id = STABILIZE_ID;
|
|
16
|
+
style.textContent = STABILIZE_CSS;
|
|
17
|
+
doc.head.append(style);
|
|
18
|
+
}
|
|
19
|
+
await frame(win);
|
|
20
|
+
await doc.fonts.ready;
|
|
21
|
+
await frame(win);
|
|
22
|
+
await frame(win);
|
|
23
|
+
}
|
|
24
|
+
function unsettle(win) {
|
|
25
|
+
win.document.getElementById(STABILIZE_ID)?.remove();
|
|
26
|
+
}
|
|
27
|
+
function describe(el) {
|
|
28
|
+
const id = el.id ? `#${el.id}` : "";
|
|
29
|
+
const cls = el.classList.length > 0 ? `.${[...el.classList].join(".")}` : "";
|
|
30
|
+
return `<${el.tagName.toLowerCase()}${id}${cls}>`;
|
|
31
|
+
}
|
|
32
|
+
/** Not `display: none` or `visibility: hidden` (browsers without `checkVisibility` say yes). */
|
|
33
|
+
function isShown(el) {
|
|
34
|
+
return typeof el.checkVisibility === "function" ? el.checkVisibility() : true;
|
|
35
|
+
}
|
|
36
|
+
/** An element with a box and not hidden: otherwise there is nothing to take a picture of. */
|
|
37
|
+
function assertCapturable(el, what = describe(el)) {
|
|
38
|
+
const box = el.getBoundingClientRect();
|
|
39
|
+
if (box.width <= 0 || box.height <= 0 || !isShown(el)) throw new Error(`cy.screenshot(): nothing to capture, ${what} has no size or isn't visible. Wait for it to render before taking the screenshot.`);
|
|
40
|
+
}
|
|
41
|
+
/** The bottom of everything on the page, in page coordinates: where its content ends. */
|
|
42
|
+
function contentBottom(win) {
|
|
43
|
+
const doc = win.document;
|
|
44
|
+
const body = doc.body;
|
|
45
|
+
let bottom = 0;
|
|
46
|
+
const range = doc.createRange();
|
|
47
|
+
range.selectNodeContents(body);
|
|
48
|
+
const own = range.getBoundingClientRect();
|
|
49
|
+
if (own.width > 0 || own.height > 0) bottom = own.bottom;
|
|
50
|
+
for (const el of body.querySelectorAll("*")) {
|
|
51
|
+
const box = el.getBoundingClientRect();
|
|
52
|
+
if (box.width > 0 && box.height > 0 && isShown(el)) bottom = Math.max(bottom, box.bottom);
|
|
53
|
+
}
|
|
54
|
+
return Math.ceil(bottom + win.scrollY);
|
|
55
|
+
}
|
|
56
|
+
/** The padding below the content that the caller asked for (the `bottom` of Cypress's `padding`). */
|
|
57
|
+
function bottomPadding(padding) {
|
|
58
|
+
if (typeof padding === "number") return padding;
|
|
59
|
+
if (Array.isArray(padding)) {
|
|
60
|
+
const bottom = padding.length === 2 ? padding[0] : padding[2];
|
|
61
|
+
return typeof bottom === "number" ? bottom : 0;
|
|
62
|
+
}
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
/** Decide what a `cy.screenshot()` without a subject photographs. */
|
|
66
|
+
function pageTarget(win, testingType, padding) {
|
|
67
|
+
const doc = win.document;
|
|
68
|
+
if (testingType === "component") {
|
|
69
|
+
const root = doc.querySelector("[data-cy-root]");
|
|
70
|
+
if (!root) throw new Error("cy.screenshot(): nothing to capture, no component is mounted");
|
|
71
|
+
const target = root.children.length === 1 ? root.children[0] ?? root : root;
|
|
72
|
+
assertCapturable(target, root.children.length === 1 ? "the mounted component" : "the mount point");
|
|
73
|
+
return { element: target };
|
|
74
|
+
}
|
|
75
|
+
const content = contentBottom(win);
|
|
76
|
+
if (content <= 0) throw new Error("cy.screenshot(): nothing to capture, the page has no content");
|
|
77
|
+
return { clip: {
|
|
78
|
+
x: 0,
|
|
79
|
+
y: 0,
|
|
80
|
+
width: doc.documentElement.clientWidth,
|
|
81
|
+
height: Math.min(content + bottomPadding(padding), Math.max(doc.documentElement.scrollHeight, content))
|
|
82
|
+
} };
|
|
83
|
+
}
|
|
84
|
+
// src/support.ts
|
|
85
|
+
/**
|
|
86
|
+
* `import '@circi/cypress/support'` in the support file. `cy.screenshot()` keeps its signature and
|
|
87
|
+
* what it yields; before a capture it waits for fonts and stops animations and the caret, and
|
|
88
|
+
* what it photographs is exactly the thing and nothing around it:
|
|
89
|
+
*
|
|
90
|
+
* - on an element (`cy.get(sel).screenshot('x')`): the element's box;
|
|
91
|
+
* - on the page: its content, as tall as the content is (not padded to the viewport), without
|
|
92
|
+
* Cypress's own interface;
|
|
93
|
+
* - in component testing: the mounted component's box.
|
|
94
|
+
*
|
|
95
|
+
* An element with no size, or hidden, is an error rather than a blank image. `padding` adds space
|
|
96
|
+
* on purpose. An explicit `capture` or `clip` is left alone.
|
|
97
|
+
*/
|
|
98
|
+
Cypress.Screenshot.defaults({
|
|
99
|
+
capture: "fullPage",
|
|
100
|
+
disableTimersAndAnimations: true
|
|
101
|
+
});
|
|
102
|
+
function isOptions(value) {
|
|
103
|
+
return typeof value === "object" && value !== null;
|
|
104
|
+
}
|
|
105
|
+
/** The element a command was chained off (`cy.get(...)` yields a jQuery collection), if any. */
|
|
106
|
+
function subjectElement(subject) {
|
|
107
|
+
if (!isOptions(subject) || !("length" in subject)) return void 0;
|
|
108
|
+
const first = Reflect.get(subject, "0");
|
|
109
|
+
return isElement(first) ? first : void 0;
|
|
110
|
+
}
|
|
111
|
+
/** Structural, not `instanceof`: the page under test is another window with its own `Element`. */
|
|
112
|
+
function isElement(value) {
|
|
113
|
+
return typeof value === "object" && value !== null && "getBoundingClientRect" in value && typeof value.getBoundingClientRect === "function";
|
|
114
|
+
}
|
|
115
|
+
function screenshot(original, subject, ...rest) {
|
|
116
|
+
const [first, second] = rest;
|
|
117
|
+
const name = typeof first === "string" ? first : void 0;
|
|
118
|
+
const given = (isOptions(first) ? first : isOptions(second) ? second : void 0) ?? {};
|
|
119
|
+
const chained = subjectElement(subject);
|
|
120
|
+
const own = Reflect.get(given, "timeout");
|
|
121
|
+
const timeout = typeof own === "number" ? own : Cypress.config("responseTimeout");
|
|
122
|
+
return cy.window({ log: false }).then(async (win) => {
|
|
123
|
+
await settle(win);
|
|
124
|
+
if (chained) {
|
|
125
|
+
assertCapturable(chained);
|
|
126
|
+
return {
|
|
127
|
+
win,
|
|
128
|
+
options: {},
|
|
129
|
+
target: void 0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (given.capture !== void 0 || given.clip !== void 0) return {
|
|
133
|
+
win,
|
|
134
|
+
options: {},
|
|
135
|
+
target: void 0
|
|
136
|
+
};
|
|
137
|
+
const plan = pageTarget(win, Cypress.testingType, given.padding);
|
|
138
|
+
return {
|
|
139
|
+
win,
|
|
140
|
+
options: plan.clip ? {
|
|
141
|
+
capture: "fullPage",
|
|
142
|
+
clip: plan.clip
|
|
143
|
+
} : {},
|
|
144
|
+
target: plan.element ? Cypress.$(plan.element) : void 0
|
|
145
|
+
};
|
|
146
|
+
}).then({ timeout }, ({ win, options, target }) => {
|
|
147
|
+
const merged = {
|
|
148
|
+
...given,
|
|
149
|
+
...options,
|
|
150
|
+
onAfterScreenshot(...args) {
|
|
151
|
+
unsettle(win);
|
|
152
|
+
given.onAfterScreenshot?.(...args);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return original(target ?? subject, ...name === void 0 ? [merged] : [name, merged]);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
Cypress.Commands.overwrite("screenshot", screenshot);
|
|
159
|
+
export {};
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=support.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"support.mjs","names":[],"sources":["../src/page.ts","../src/support.ts"],"sourcesContent":["/**\n * Browser-side steps behind `cy.screenshot()`: make the page hold still, and decide what the\n * picture is of so that it holds the thing and nothing around it. Runs inside the page, so it uses\n * the DOM; Node never imports it.\n */\nimport { STABILIZE_CSS } from '@circi/cli/names'\n\nexport const STABILIZE_ID = 'circi-stabilize'\n\nconst frame = (win: Window): Promise<void> =>\n new Promise((r) => win.requestAnimationFrame(() => r()))\n\n/** Add the stabilizing style, then wait for fonts and two painted frames. */\nexport async function settle(win: Window): Promise<void> {\n const doc = win.document\n if (!doc.getElementById(STABILIZE_ID)) {\n const style = doc.createElement('style')\n style.id = STABILIZE_ID\n style.textContent = STABILIZE_CSS\n doc.head.append(style)\n }\n // A frame first: a font is only requested once text that uses it has been laid out, and\n // `fonts.ready` resolves at once while nothing has been requested yet.\n await frame(win)\n await doc.fonts.ready\n await frame(win)\n await frame(win)\n}\n\nexport function unsettle(win: Window): void {\n win.document.getElementById(STABILIZE_ID)?.remove()\n}\n\nfunction describe(el: Element): string {\n const id = el.id ? `#${el.id}` : ''\n const cls = el.classList.length > 0 ? `.${[...el.classList].join('.')}` : ''\n return `<${el.tagName.toLowerCase()}${id}${cls}>`\n}\n\n/** Not `display: none` or `visibility: hidden` (browsers without `checkVisibility` say yes). */\nfunction isShown(el: Element): boolean {\n return typeof el.checkVisibility === 'function' ? el.checkVisibility() : true\n}\n\n/** An element with a box and not hidden: otherwise there is nothing to take a picture of. */\nexport function assertCapturable(el: Element, what = describe(el)): void {\n const box = el.getBoundingClientRect()\n if (box.width <= 0 || box.height <= 0 || !isShown(el)) {\n throw new Error(\n `cy.screenshot(): nothing to capture, ${what} has no size or isn't visible. ` +\n 'Wait for it to render before taking the screenshot.',\n )\n }\n}\n\n/** What to photograph when `cy.screenshot()` is called on the page. */\nexport interface PageTarget {\n /** A page: capture it at this size, from the top. */\n clip?: { x: number; y: number; width: number; height: number }\n /** Component testing: the mounted component itself. */\n element?: Element\n}\n\n/** The bottom of everything on the page, in page coordinates: where its content ends. */\nexport function contentBottom(win: Window): number {\n const doc = win.document\n const body = doc.body\n let bottom = 0\n const range = doc.createRange()\n range.selectNodeContents(body)\n const own = range.getBoundingClientRect()\n if (own.width > 0 || own.height > 0) bottom = own.bottom\n for (const el of body.querySelectorAll('*')) {\n const box = el.getBoundingClientRect()\n if (box.width > 0 && box.height > 0 && isShown(el)) bottom = Math.max(bottom, box.bottom)\n }\n return Math.ceil(bottom + win.scrollY)\n}\n\n/** The padding below the content that the caller asked for (the `bottom` of Cypress's `padding`). */\nexport function bottomPadding(padding: unknown): number {\n if (typeof padding === 'number') return padding\n if (Array.isArray(padding)) {\n const bottom: unknown = padding.length === 2 ? padding[0] : padding[2]\n return typeof bottom === 'number' ? bottom : 0\n }\n return 0\n}\n\n/** Decide what a `cy.screenshot()` without a subject photographs. */\nexport function pageTarget(win: Window, testingType: string, padding: unknown): PageTarget {\n const doc = win.document\n if (testingType === 'component') {\n const root = doc.querySelector('[data-cy-root]')\n if (!root) throw new Error('cy.screenshot(): nothing to capture, no component is mounted')\n // The component's own box: the one element the root renders, or the root if there are several.\n const target = root.children.length === 1 ? (root.children[0] ?? root) : root\n assertCapturable(\n target,\n root.children.length === 1 ? 'the mounted component' : 'the mount point',\n )\n return { element: target }\n }\n const content = contentBottom(win)\n if (content <= 0) throw new Error('cy.screenshot(): nothing to capture, the page has no content')\n return {\n clip: {\n x: 0,\n y: 0,\n width: doc.documentElement.clientWidth,\n // Padding adds space below the content, but never past the end of the document: a capture\n // can't show more page than there is.\n height: Math.min(\n content + bottomPadding(padding),\n Math.max(doc.documentElement.scrollHeight, content),\n ),\n },\n }\n}\n","/// <reference types=\"cypress\" />\n/**\n * `import '@circi/cypress/support'` in the support file. `cy.screenshot()` keeps its signature and\n * what it yields; before a capture it waits for fonts and stops animations and the caret, and\n * what it photographs is exactly the thing and nothing around it:\n *\n * - on an element (`cy.get(sel).screenshot('x')`): the element's box;\n * - on the page: its content, as tall as the content is (not padded to the viewport), without\n * Cypress's own interface;\n * - in component testing: the mounted component's box.\n *\n * An element with no size, or hidden, is an error rather than a blank image. `padding` adds space\n * on purpose. An explicit `capture` or `clip` is left alone.\n */\nimport { assertCapturable, pageTarget, settle, unsettle } from './page.ts'\n\nCypress.Screenshot.defaults({ capture: 'fullPage', disableTimersAndAnimations: true })\n\ntype Options = Partial<Cypress.ScreenshotOptions>\n\nfunction isOptions(value: unknown): value is Options {\n return typeof value === 'object' && value !== null\n}\n\n/** The element a command was chained off (`cy.get(...)` yields a jQuery collection), if any. */\nfunction subjectElement(subject: unknown): Element | undefined {\n if (!isOptions(subject) || !('length' in subject)) return undefined\n const first: unknown = Reflect.get(subject, '0')\n return isElement(first) ? first : undefined\n}\n\n/** Structural, not `instanceof`: the page under test is another window with its own `Element`. */\nfunction isElement(value: unknown): value is Element {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'getBoundingClientRect' in value &&\n typeof value.getBoundingClientRect === 'function'\n )\n}\n\ninterface Plan {\n win: Window\n options: Options\n target: JQuery<Element> | undefined\n}\n\n// A dual command: the argument after the original is the subject (undefined on `cy`).\nfunction screenshot(\n original: (...args: unknown[]) => unknown,\n subject: unknown,\n ...rest: unknown[]\n) {\n const [first, second] = rest\n const name = typeof first === 'string' ? first : undefined\n const given: Options = (isOptions(first) ? first : isOptions(second) ? second : undefined) ?? {}\n const chained = subjectElement(subject)\n // The real `cy.screenshot` runs inside the last `.then()`, so that step gets the screenshot's own\n // limit (its `timeout`, else `responseTimeout`) rather than `.then()`'s 4 s: a full-page capture of\n // a tall page is several captures stitched together, which took longer than 4 s on CI.\n const own: unknown = Reflect.get(given, 'timeout')\n const timeout = typeof own === 'number' ? own : Cypress.config('responseTimeout')\n\n return cy\n .window({ log: false })\n .then(async (win): Promise<Plan> => {\n await settle(win)\n if (chained) {\n assertCapturable(chained)\n return { win, options: {}, target: undefined }\n }\n // An explicit `capture` or `clip` is the test's own choice.\n if (given.capture !== undefined || given.clip !== undefined) {\n return { win, options: {}, target: undefined }\n }\n const plan = pageTarget(win, Cypress.testingType, given.padding)\n return {\n win,\n options: plan.clip ? { capture: 'fullPage', clip: plan.clip } : {},\n target: plan.element ? Cypress.$(plan.element) : undefined,\n }\n })\n .then({ timeout }, ({ win, options, target }) => {\n const merged: Options = {\n ...given,\n ...options,\n onAfterScreenshot(...args) {\n unsettle(win)\n given.onAfterScreenshot?.(...args)\n },\n }\n return original(target ?? subject, ...(name === undefined ? [merged] : [name, merged]))\n })\n}\n\n// The command types describe `cy.screenshot(name?, options?)`; the subject-first form the\n// overwrite is called with isn't in them.\n// oxlint-disable-next-line typescript/no-unsafe-type-assertion\nCypress.Commands.overwrite('screenshot', screenshot as never)\n"],"mappings":";;;;;;;AAOA,MAAa,eAAe;AAE5B,MAAM,SAAS,QACb,IAAI,SAAS,MAAM,IAAI,4BAA4B,EAAE,CAAC,CAAC;;AAGzD,eAAsB,OAAO,KAA4B;CACvD,MAAM,MAAM,IAAI;CAChB,IAAI,CAAC,IAAI,eAAA,iBAA2B,GAAG;EACrC,MAAM,QAAQ,IAAI,cAAc,OAAO;EACvC,MAAM,KAAK;EACX,MAAM,cAAc;EACpB,IAAI,KAAK,OAAO,KAAK;CACvB;CAGA,MAAM,MAAM,GAAG;CACf,MAAM,IAAI,MAAM;CAChB,MAAM,MAAM,GAAG;CACf,MAAM,MAAM,GAAG;AACjB;AAEA,SAAgB,SAAS,KAAmB;CAC1C,IAAI,SAAS,eAAe,YAAY,CAAC,EAAE,OAAO;AACpD;AAEA,SAAS,SAAS,IAAqB;CACrC,MAAM,KAAK,GAAG,KAAK,IAAI,GAAG,OAAO;CACjC,MAAM,MAAM,GAAG,UAAU,SAAS,IAAI,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC,KAAK,GAAG,MAAM;CAC1E,OAAO,IAAI,GAAG,QAAQ,YAAY,IAAI,KAAK,IAAI;AACjD;;AAGA,SAAS,QAAQ,IAAsB;CACrC,OAAO,OAAO,GAAG,oBAAoB,aAAa,GAAG,gBAAgB,IAAI;AAC3E;;AAGA,SAAgB,iBAAiB,IAAa,OAAO,SAAS,EAAE,GAAS;CACvE,MAAM,MAAM,GAAG,sBAAsB;CACrC,IAAI,IAAI,SAAS,KAAK,IAAI,UAAU,KAAK,CAAC,QAAQ,EAAE,GAClD,MAAM,IAAI,MACR,wCAAwC,KAAK,mFAE/C;AAEJ;;AAWA,SAAgB,cAAc,KAAqB;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/D,OAAO;GACL;GACA,SAAS,KAAK,OAAO;IAAE,SAAS;IAAY,MAAM,KAAK;GAAK,IAAI,CAAC;GACjE,QAAQ,KAAK,UAAU,QAAQ,EAAE,KAAK,OAAO,IAAI,KAAA;EACnD;CACF,CAAC,CAAC,CACD,KAAK,EAAE,QAAQ,IAAI,EAAE,KAAK,SAAS,aAAa;EAC/C,MAAM,SAAkB;GACtB,GAAG;GACH,GAAG;GACH,kBAAkB,GAAG,MAAM;IACzB,SAAS,GAAG;IACZ,MAAM,oBAAoB,GAAG,IAAI;GACnC;EACF;EACA,OAAO,SAAS,UAAU,SAAS,GAAI,SAAS,KAAA,IAAY,CAAC,MAAM,IAAI,CAAC,MAAM,MAAM,CAAE;CACxF,CAAC;AACL;AAKA,QAAQ,SAAS,UAAU,cAAc,UAAmB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@circi/cypress",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Cypress integration: cy.circiScreenshot() and a plugin that uploads the screenshots to CirCI",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cypress",
|
|
7
|
+
"cypress-plugin",
|
|
8
|
+
"screenshots",
|
|
9
|
+
"visual-regression",
|
|
10
|
+
"visual-testing"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://circi.dev/ci/cypress/",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/cir-ci/repo/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "GPL-3.0-only",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/cir-ci/repo.git",
|
|
20
|
+
"directory": "packages/cypress"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"imports": {
|
|
28
|
+
"#src/*": "./src/*"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"default": "./dist/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./support": {
|
|
36
|
+
"types": "./dist/support.d.mts",
|
|
37
|
+
"default": "./dist/support.mjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public",
|
|
42
|
+
"provenance": true
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@arethetypeswrong/core": "0.18.5",
|
|
46
|
+
"@circi/cli": "0.2.1",
|
|
47
|
+
"cypress": "16.3.0",
|
|
48
|
+
"publint": "0.3.25",
|
|
49
|
+
"tsdown": "0.23.7",
|
|
50
|
+
"vite": "8.3.8"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"cypress": ">=13"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=22"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsdown"
|
|
60
|
+
}
|
|
6
61
|
}
|