@chromatic-com/cypress 0.12.2 → 0.12.3-33fdb89-20260504080255
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/dist/index.js +14 -8
- package/dist/index.mjs +14 -8
- package/dist/storybook-config/preview.mjs +15 -4
- package/dist/support.js +16 -2
- package/dist/support.mjs +17 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3689,18 +3689,23 @@ var import_srcset = __toESM(require_srcset());
|
|
|
3689
3689
|
var CSS_URL_REGEX = /url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi;
|
|
3690
3690
|
var _a3;
|
|
3691
3691
|
var _DOMSnapshot = (_a3 = class {
|
|
3692
|
-
constructor(snapshot) {
|
|
3692
|
+
constructor({ snapshot, pseudoClassIds }) {
|
|
3693
3693
|
__publicField(this, "snapshot");
|
|
3694
|
+
__publicField(this, "pseudoClassIds");
|
|
3694
3695
|
if (Buffer.isBuffer(snapshot)) {
|
|
3695
3696
|
const bufferAsString = snapshot.toString("utf-8");
|
|
3696
3697
|
this.snapshot = JSON.parse(bufferAsString);
|
|
3697
3698
|
} else {
|
|
3698
3699
|
this.snapshot = JSON.parse(snapshot);
|
|
3699
3700
|
}
|
|
3701
|
+
this.pseudoClassIds = pseudoClassIds;
|
|
3700
3702
|
}
|
|
3701
3703
|
async mapAssetPaths(sourceMap) {
|
|
3702
|
-
const
|
|
3703
|
-
|
|
3704
|
+
const savedSnapshot = {
|
|
3705
|
+
snapshot: await this.mapNode(this.snapshot, sourceMap),
|
|
3706
|
+
pseudoClassIds: this.pseudoClassIds
|
|
3707
|
+
};
|
|
3708
|
+
return JSON.stringify(savedSnapshot);
|
|
3704
3709
|
}
|
|
3705
3710
|
async mapNode(node, sourceMap) {
|
|
3706
3711
|
node = this.mapNodeAttributes(node, sourceMap);
|
|
@@ -3934,7 +3939,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
3934
3939
|
// cypress: https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Spec-files
|
|
3935
3940
|
pathPart.replace(/\.(ts|js|mjs|cjs|tsx|jsx|cjsx|coffee)$/, "").replace(/\.(spec|test|cy)$/, "")
|
|
3936
3941
|
));
|
|
3937
|
-
const title = titlePathWithoutFileExtensions.join("/");
|
|
3942
|
+
const title = titlePathWithoutFileExtensions.join("/").replace(/\/([ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\]+)\//gi, "$1/");
|
|
3938
3943
|
const finalOutputDir = path2.join(outputDir, "chromatic-archives");
|
|
3939
3944
|
const archiveDir = path2.join(finalOutputDir, "archive");
|
|
3940
3945
|
await ensureDir(archiveDir);
|
|
@@ -3951,10 +3956,10 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
3951
3956
|
}
|
|
3952
3957
|
await outputFile(path2.join(archiveDir, fileSystemPath), response.body);
|
|
3953
3958
|
}));
|
|
3954
|
-
await Promise.all(Object.entries(domSnapshots).map(async ([name,
|
|
3959
|
+
await Promise.all(Object.entries(domSnapshots).map(async ([name, domSnapshot]) => {
|
|
3955
3960
|
const snapshot = new DOMSnapshot(domSnapshot);
|
|
3956
3961
|
const mappedSnapshot = await snapshot.mapAssetPaths(sourceMap);
|
|
3957
|
-
const snapshotFile = snapshotFileName(snapshotId(title, name), viewport);
|
|
3962
|
+
const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
|
|
3958
3963
|
await outputFile(path2.join(archiveDir, snapshotFile), mappedSnapshot);
|
|
3959
3964
|
}));
|
|
3960
3965
|
const storiesFile = storiesFileName(title);
|
|
@@ -4006,11 +4011,12 @@ __name2(trackComplete, "trackComplete");
|
|
|
4006
4011
|
var writeArchives = /* @__PURE__ */ __name(async ({ testTitlePath, domSnapshots, resourceArchive, chromaticStorybookParams, pageUrl, outputDir }) => {
|
|
4007
4012
|
const allSnapshots = Object.fromEntries(
|
|
4008
4013
|
// manual snapshots can be given a name; otherwise, just use the snapshot's place in line as the name
|
|
4009
|
-
domSnapshots.map(({ name, snapshot, viewport }, index) => [
|
|
4014
|
+
domSnapshots.map(({ name, snapshot, viewport, pseudoClassIds }, index) => [
|
|
4010
4015
|
name ?? `Snapshot #${index + 1}`,
|
|
4011
4016
|
{
|
|
4012
4017
|
snapshot: Buffer.from(JSON.stringify(snapshot)),
|
|
4013
|
-
viewport
|
|
4018
|
+
viewport,
|
|
4019
|
+
pseudoClassIds
|
|
4014
4020
|
}
|
|
4015
4021
|
])
|
|
4016
4022
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -3682,18 +3682,23 @@ var import_srcset = __toESM(require_srcset());
|
|
|
3682
3682
|
var CSS_URL_REGEX = /url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi;
|
|
3683
3683
|
var _a3;
|
|
3684
3684
|
var _DOMSnapshot = (_a3 = class {
|
|
3685
|
-
constructor(snapshot) {
|
|
3685
|
+
constructor({ snapshot, pseudoClassIds }) {
|
|
3686
3686
|
__publicField(this, "snapshot");
|
|
3687
|
+
__publicField(this, "pseudoClassIds");
|
|
3687
3688
|
if (Buffer.isBuffer(snapshot)) {
|
|
3688
3689
|
const bufferAsString = snapshot.toString("utf-8");
|
|
3689
3690
|
this.snapshot = JSON.parse(bufferAsString);
|
|
3690
3691
|
} else {
|
|
3691
3692
|
this.snapshot = JSON.parse(snapshot);
|
|
3692
3693
|
}
|
|
3694
|
+
this.pseudoClassIds = pseudoClassIds;
|
|
3693
3695
|
}
|
|
3694
3696
|
async mapAssetPaths(sourceMap) {
|
|
3695
|
-
const
|
|
3696
|
-
|
|
3697
|
+
const savedSnapshot = {
|
|
3698
|
+
snapshot: await this.mapNode(this.snapshot, sourceMap),
|
|
3699
|
+
pseudoClassIds: this.pseudoClassIds
|
|
3700
|
+
};
|
|
3701
|
+
return JSON.stringify(savedSnapshot);
|
|
3697
3702
|
}
|
|
3698
3703
|
async mapNode(node, sourceMap) {
|
|
3699
3704
|
node = this.mapNodeAttributes(node, sourceMap);
|
|
@@ -3927,7 +3932,7 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
3927
3932
|
// cypress: https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Spec-files
|
|
3928
3933
|
pathPart.replace(/\.(ts|js|mjs|cjs|tsx|jsx|cjsx|coffee)$/, "").replace(/\.(spec|test|cy)$/, "")
|
|
3929
3934
|
));
|
|
3930
|
-
const title = titlePathWithoutFileExtensions.join("/");
|
|
3935
|
+
const title = titlePathWithoutFileExtensions.join("/").replace(/\/([ ’–—―′¿'`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\]+)\//gi, "$1/");
|
|
3931
3936
|
const finalOutputDir = join(outputDir, "chromatic-archives");
|
|
3932
3937
|
const archiveDir = join(finalOutputDir, "archive");
|
|
3933
3938
|
await ensureDir(archiveDir);
|
|
@@ -3944,10 +3949,10 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
3944
3949
|
}
|
|
3945
3950
|
await outputFile(join(archiveDir, fileSystemPath), response.body);
|
|
3946
3951
|
}));
|
|
3947
|
-
await Promise.all(Object.entries(domSnapshots).map(async ([name,
|
|
3952
|
+
await Promise.all(Object.entries(domSnapshots).map(async ([name, domSnapshot]) => {
|
|
3948
3953
|
const snapshot = new DOMSnapshot(domSnapshot);
|
|
3949
3954
|
const mappedSnapshot = await snapshot.mapAssetPaths(sourceMap);
|
|
3950
|
-
const snapshotFile = snapshotFileName(snapshotId(title, name), viewport);
|
|
3955
|
+
const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
|
|
3951
3956
|
await outputFile(join(archiveDir, snapshotFile), mappedSnapshot);
|
|
3952
3957
|
}));
|
|
3953
3958
|
const storiesFile = storiesFileName(title);
|
|
@@ -3999,11 +4004,12 @@ __name2(trackComplete, "trackComplete");
|
|
|
3999
4004
|
var writeArchives = /* @__PURE__ */ __name(async ({ testTitlePath, domSnapshots, resourceArchive, chromaticStorybookParams, pageUrl, outputDir }) => {
|
|
4000
4005
|
const allSnapshots = Object.fromEntries(
|
|
4001
4006
|
// manual snapshots can be given a name; otherwise, just use the snapshot's place in line as the name
|
|
4002
|
-
domSnapshots.map(({ name, snapshot, viewport }, index) => [
|
|
4007
|
+
domSnapshots.map(({ name, snapshot, viewport, pseudoClassIds }, index) => [
|
|
4003
4008
|
name ?? `Snapshot #${index + 1}`,
|
|
4004
4009
|
{
|
|
4005
4010
|
snapshot: Buffer.from(JSON.stringify(snapshot)),
|
|
4006
|
-
viewport
|
|
4011
|
+
viewport,
|
|
4012
|
+
pseudoClassIds
|
|
4007
4013
|
}
|
|
4008
4014
|
])
|
|
4009
4015
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rebuild } from '@chromaui/rrweb-snapshot';
|
|
1
|
+
import { createMirror, rebuild, createCache } from '@chromaui/rrweb-snapshot';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -55,11 +55,22 @@ async function fetchSnapshot(context) {
|
|
|
55
55
|
}
|
|
56
56
|
__name(fetchSnapshot, "fetchSnapshot");
|
|
57
57
|
var renderToCanvas = /* @__PURE__ */ __name(async (context) => {
|
|
58
|
-
const snapshot = await fetchSnapshot(context);
|
|
58
|
+
const { snapshot, pseudoClassIds } = await fetchSnapshot(context);
|
|
59
59
|
const htmlNode = findHtmlNode(snapshot);
|
|
60
|
-
const
|
|
61
|
-
|
|
60
|
+
const mirror = createMirror();
|
|
61
|
+
const html = rebuild(htmlNode, {
|
|
62
|
+
doc: document,
|
|
63
|
+
mirror,
|
|
64
|
+
cache: createCache()
|
|
62
65
|
});
|
|
66
|
+
for (const [className, ids] of Object.entries(pseudoClassIds)) {
|
|
67
|
+
for (const id of ids) {
|
|
68
|
+
const el = mirror.getNode(id);
|
|
69
|
+
if (el?.classList) {
|
|
70
|
+
el.classList.add(className);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
document.replaceChild(html, document.children[0]);
|
|
64
75
|
document.head.innerHTML += '<script id="storybook-root"><\/script><script id="storybook-docs"><\/script>';
|
|
65
76
|
context.showMain();
|
package/dist/support.js
CHANGED
|
@@ -9,9 +9,22 @@ var takeSnapshot = /* @__PURE__ */ __name((doc, viewport, isManualSnapshot) => {
|
|
|
9
9
|
if (!isManualSnapshot && Cypress.env("disableAutoSnapshot")) {
|
|
10
10
|
resolve(null);
|
|
11
11
|
}
|
|
12
|
+
const mirror = rrwebSnapshot.createMirror();
|
|
12
13
|
const domSnapshot = rrwebSnapshot.snapshot(doc, {
|
|
13
|
-
recordCanvas: true
|
|
14
|
+
recordCanvas: true,
|
|
15
|
+
mirror
|
|
14
16
|
});
|
|
17
|
+
const pseudoClassIds = {};
|
|
18
|
+
for (const className of [
|
|
19
|
+
":hover",
|
|
20
|
+
":focus",
|
|
21
|
+
":focus-visible",
|
|
22
|
+
":active"
|
|
23
|
+
]) {
|
|
24
|
+
const elements = doc.querySelectorAll(className);
|
|
25
|
+
const ids = Array.from(elements, (el) => mirror.getId(el)).filter((id) => id !== -1);
|
|
26
|
+
pseudoClassIds[className] = ids;
|
|
27
|
+
}
|
|
15
28
|
const toDataURL = /* @__PURE__ */ __name(async (url) => {
|
|
16
29
|
const response = await fetch(url);
|
|
17
30
|
const blob = await response.blob();
|
|
@@ -39,7 +52,8 @@ var takeSnapshot = /* @__PURE__ */ __name((doc, viewport, isManualSnapshot) => {
|
|
|
39
52
|
replaceBlobUrls(domSnapshot).then(() => {
|
|
40
53
|
resolve({
|
|
41
54
|
snapshot: domSnapshot,
|
|
42
|
-
viewport
|
|
55
|
+
viewport,
|
|
56
|
+
pseudoClassIds
|
|
43
57
|
});
|
|
44
58
|
});
|
|
45
59
|
});
|
package/dist/support.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { snapshot } from '@chromaui/rrweb-snapshot';
|
|
1
|
+
import { createMirror, snapshot } from '@chromaui/rrweb-snapshot';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -7,9 +7,22 @@ var takeSnapshot = /* @__PURE__ */ __name((doc, viewport, isManualSnapshot) => {
|
|
|
7
7
|
if (!isManualSnapshot && Cypress.env("disableAutoSnapshot")) {
|
|
8
8
|
resolve(null);
|
|
9
9
|
}
|
|
10
|
+
const mirror = createMirror();
|
|
10
11
|
const domSnapshot = snapshot(doc, {
|
|
11
|
-
recordCanvas: true
|
|
12
|
+
recordCanvas: true,
|
|
13
|
+
mirror
|
|
12
14
|
});
|
|
15
|
+
const pseudoClassIds = {};
|
|
16
|
+
for (const className of [
|
|
17
|
+
":hover",
|
|
18
|
+
":focus",
|
|
19
|
+
":focus-visible",
|
|
20
|
+
":active"
|
|
21
|
+
]) {
|
|
22
|
+
const elements = doc.querySelectorAll(className);
|
|
23
|
+
const ids = Array.from(elements, (el) => mirror.getId(el)).filter((id) => id !== -1);
|
|
24
|
+
pseudoClassIds[className] = ids;
|
|
25
|
+
}
|
|
13
26
|
const toDataURL = /* @__PURE__ */ __name(async (url) => {
|
|
14
27
|
const response = await fetch(url);
|
|
15
28
|
const blob = await response.blob();
|
|
@@ -37,7 +50,8 @@ var takeSnapshot = /* @__PURE__ */ __name((doc, viewport, isManualSnapshot) => {
|
|
|
37
50
|
replaceBlobUrls(domSnapshot).then(() => {
|
|
38
51
|
resolve({
|
|
39
52
|
snapshot: domSnapshot,
|
|
40
|
-
viewport
|
|
53
|
+
viewport,
|
|
54
|
+
pseudoClassIds
|
|
41
55
|
});
|
|
42
56
|
});
|
|
43
57
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromatic-com/cypress",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3-33fdb89-20260504080255",
|
|
4
4
|
"description": "Chromatic Visual Regression Testing for Cypress",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"test:unit": "yarn workspace @chromaui/chromatic-e2e test:unit --project Cypress"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@chromaui/rrweb-snapshot": "2.0.0-alpha.
|
|
60
|
+
"@chromaui/rrweb-snapshot": "2.0.0-alpha.19-noAbsolute",
|
|
61
61
|
"@segment/analytics-node": "2.1.3",
|
|
62
62
|
"chrome-remote-interface": "^0.33.0",
|
|
63
63
|
"storybook": "10.2.13"
|