@chromatic-com/vitest 0.0.2 → 0.0.3-4b34acb-20260428052623
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 +16 -3
- package/dist/plugin.d.ts +6 -0
- package/dist/plugin.js +16 -9
- package/dist/setupFile.js +16 -3
- package/dist/storybook-config/preview.js +15 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/browser/public/takeSnapshot.ts
|
|
5
5
|
import { assert } from "vitest";
|
|
6
6
|
import { commands } from "vitest/browser";
|
|
7
|
-
import { snapshot } from "@chromaui/rrweb-snapshot";
|
|
7
|
+
import { snapshot, createMirror } from "@chromaui/rrweb-snapshot";
|
|
8
8
|
|
|
9
9
|
// src/browser/getCurrentTest.ts
|
|
10
10
|
import * as vitest from "vitest";
|
|
@@ -32,13 +32,26 @@ async function takeSnapshot(name, options) {
|
|
|
32
32
|
Make sure ${test.file.projectName || "root"} project has chromaticPlugin() enabled.`);
|
|
33
33
|
}
|
|
34
34
|
test.meta.__chromatic_isTakeSnapshotCalled = true;
|
|
35
|
+
const mirror = createMirror();
|
|
35
36
|
const domSnapshot = snapshot(document, {
|
|
36
|
-
recordCanvas: true
|
|
37
|
+
recordCanvas: true,
|
|
38
|
+
mirror
|
|
37
39
|
});
|
|
38
40
|
assert(domSnapshot, "Failed to capture DOM snapshot");
|
|
41
|
+
const pseudoClassIds = {};
|
|
42
|
+
for (const className of [
|
|
43
|
+
":hover",
|
|
44
|
+
":focus",
|
|
45
|
+
":focus-visible",
|
|
46
|
+
":active"
|
|
47
|
+
]) {
|
|
48
|
+
const elements = document.querySelectorAll(className);
|
|
49
|
+
const ids = Array.from(elements, (el) => mirror.getId(el)).filter((id) => id !== -1);
|
|
50
|
+
pseudoClassIds[className] = ids;
|
|
51
|
+
}
|
|
39
52
|
const save = /* @__PURE__ */ __name(async () => {
|
|
40
53
|
await replaceBlobUrls(domSnapshot);
|
|
41
|
-
await commands.__chromatic_uploadDOMSnapshot(test.id, domSnapshot, name);
|
|
54
|
+
await commands.__chromatic_uploadDOMSnapshot(test.id, domSnapshot, pseudoClassIds, name);
|
|
42
55
|
}, "save");
|
|
43
56
|
if (options?.ignoreUnawaited) {
|
|
44
57
|
return await save();
|
package/dist/plugin.d.ts
CHANGED
package/dist/plugin.js
CHANGED
|
@@ -3693,18 +3693,23 @@ var _DOMSnapshot = class _DOMSnapshot2 {
|
|
|
3693
3693
|
static {
|
|
3694
3694
|
__name(this, "_DOMSnapshot");
|
|
3695
3695
|
}
|
|
3696
|
-
constructor(snapshot) {
|
|
3696
|
+
constructor({ snapshot, pseudoClassIds }) {
|
|
3697
3697
|
__publicField(this, "snapshot");
|
|
3698
|
+
__publicField(this, "pseudoClassIds");
|
|
3698
3699
|
if (Buffer.isBuffer(snapshot)) {
|
|
3699
3700
|
const bufferAsString = snapshot.toString("utf-8");
|
|
3700
3701
|
this.snapshot = JSON.parse(bufferAsString);
|
|
3701
3702
|
} else {
|
|
3702
3703
|
this.snapshot = JSON.parse(snapshot);
|
|
3703
3704
|
}
|
|
3705
|
+
this.pseudoClassIds = pseudoClassIds;
|
|
3704
3706
|
}
|
|
3705
3707
|
async mapAssetPaths(sourceMap) {
|
|
3706
|
-
const
|
|
3707
|
-
|
|
3708
|
+
const savedSnapshot = {
|
|
3709
|
+
snapshot: await this.mapNode(this.snapshot, sourceMap),
|
|
3710
|
+
pseudoClassIds: this.pseudoClassIds
|
|
3711
|
+
};
|
|
3712
|
+
return JSON.stringify(savedSnapshot);
|
|
3708
3713
|
}
|
|
3709
3714
|
async mapNode(node, sourceMap) {
|
|
3710
3715
|
node = this.mapNodeAttributes(node, sourceMap);
|
|
@@ -3955,10 +3960,10 @@ async function writeTestResult(e2eTestInfo, domSnapshots, archive, chromaticStor
|
|
|
3955
3960
|
}
|
|
3956
3961
|
await outputFile(join(archiveDir, fileSystemPath), response.body);
|
|
3957
3962
|
}));
|
|
3958
|
-
await Promise.all(Object.entries(domSnapshots).map(async ([name,
|
|
3963
|
+
await Promise.all(Object.entries(domSnapshots).map(async ([name, domSnapshot]) => {
|
|
3959
3964
|
const snapshot = new DOMSnapshot(domSnapshot);
|
|
3960
3965
|
const mappedSnapshot = await snapshot.mapAssetPaths(sourceMap);
|
|
3961
|
-
const snapshotFile = snapshotFileName(snapshotId(title, name), viewport);
|
|
3966
|
+
const snapshotFile = snapshotFileName(snapshotId(title, name), domSnapshot.viewport);
|
|
3962
3967
|
await outputFile(join(archiveDir, snapshotFile), mappedSnapshot);
|
|
3963
3968
|
}));
|
|
3964
3969
|
const storiesFile = storiesFileName(title);
|
|
@@ -4100,7 +4105,7 @@ function createCommands(options) {
|
|
|
4100
4105
|
* Store a `@rrweb` generated DOM snapshot for the test.
|
|
4101
4106
|
* Can be called multiple times during a single test case.
|
|
4102
4107
|
*/
|
|
4103
|
-
async __chromatic_uploadDOMSnapshot(context, id, snapshot, name) {
|
|
4108
|
+
async __chromatic_uploadDOMSnapshot(context, id, snapshot, pseudoClassIds, name) {
|
|
4104
4109
|
let sessionSnapshots = snapshots.get(id);
|
|
4105
4110
|
if (!sessionSnapshots) {
|
|
4106
4111
|
sessionSnapshots = /* @__PURE__ */ new Map();
|
|
@@ -4114,7 +4119,8 @@ function createCommands(options) {
|
|
|
4114
4119
|
}));
|
|
4115
4120
|
sessionSnapshots.set(name, {
|
|
4116
4121
|
snapshot,
|
|
4117
|
-
viewport
|
|
4122
|
+
viewport,
|
|
4123
|
+
pseudoClassIds
|
|
4118
4124
|
});
|
|
4119
4125
|
},
|
|
4120
4126
|
/**
|
|
@@ -4148,10 +4154,11 @@ function createCommands(options) {
|
|
|
4148
4154
|
const { archive, sessionSnapshots } = await onTestCleanup(id);
|
|
4149
4155
|
assert(sessionSnapshots, `No snapshots found for test ${id}`);
|
|
4150
4156
|
const snapshotBuffers = {};
|
|
4151
|
-
for (const [name, { snapshot, viewport }] of sessionSnapshots) {
|
|
4157
|
+
for (const [name, { snapshot, viewport, pseudoClassIds }] of sessionSnapshots) {
|
|
4152
4158
|
snapshotBuffers[name] = {
|
|
4153
4159
|
snapshot: Buffer.from(JSON.stringify(snapshot)),
|
|
4154
|
-
viewport
|
|
4160
|
+
viewport,
|
|
4161
|
+
pseudoClassIds
|
|
4155
4162
|
};
|
|
4156
4163
|
}
|
|
4157
4164
|
await writeTestResult({
|
package/dist/setupFile.js
CHANGED
|
@@ -8,7 +8,7 @@ import { commands as commands3 } from "vitest/browser";
|
|
|
8
8
|
// src/browser/public/takeSnapshot.ts
|
|
9
9
|
import { assert } from "vitest";
|
|
10
10
|
import { commands } from "vitest/browser";
|
|
11
|
-
import { snapshot } from "@chromaui/rrweb-snapshot";
|
|
11
|
+
import { snapshot, createMirror } from "@chromaui/rrweb-snapshot";
|
|
12
12
|
|
|
13
13
|
// src/browser/getCurrentTest.ts
|
|
14
14
|
import * as vitest from "vitest";
|
|
@@ -36,13 +36,26 @@ async function takeSnapshot(name, options) {
|
|
|
36
36
|
Make sure ${test.file.projectName || "root"} project has chromaticPlugin() enabled.`);
|
|
37
37
|
}
|
|
38
38
|
test.meta.__chromatic_isTakeSnapshotCalled = true;
|
|
39
|
+
const mirror = createMirror();
|
|
39
40
|
const domSnapshot = snapshot(document, {
|
|
40
|
-
recordCanvas: true
|
|
41
|
+
recordCanvas: true,
|
|
42
|
+
mirror
|
|
41
43
|
});
|
|
42
44
|
assert(domSnapshot, "Failed to capture DOM snapshot");
|
|
45
|
+
const pseudoClassIds = {};
|
|
46
|
+
for (const className of [
|
|
47
|
+
":hover",
|
|
48
|
+
":focus",
|
|
49
|
+
":focus-visible",
|
|
50
|
+
":active"
|
|
51
|
+
]) {
|
|
52
|
+
const elements = document.querySelectorAll(className);
|
|
53
|
+
const ids = Array.from(elements, (el) => mirror.getId(el)).filter((id) => id !== -1);
|
|
54
|
+
pseudoClassIds[className] = ids;
|
|
55
|
+
}
|
|
43
56
|
const save = /* @__PURE__ */ __name(async () => {
|
|
44
57
|
await replaceBlobUrls(domSnapshot);
|
|
45
|
-
await commands.__chromatic_uploadDOMSnapshot(test.id, domSnapshot, name);
|
|
58
|
+
await commands.__chromatic_uploadDOMSnapshot(test.id, domSnapshot, pseudoClassIds, name);
|
|
46
59
|
}, "save");
|
|
47
60
|
if (options?.ignoreUnawaited) {
|
|
48
61
|
return await save();
|
|
@@ -13,7 +13,7 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
|
13
13
|
})(NodeType || {});
|
|
14
14
|
|
|
15
15
|
// ../shared/storybook-config/preview.ts
|
|
16
|
-
import { rebuild } from "@chromaui/rrweb-snapshot";
|
|
16
|
+
import { rebuild, createMirror, createCache } from "@chromaui/rrweb-snapshot";
|
|
17
17
|
var pageUrl = new URL(window.location.href);
|
|
18
18
|
pageUrl.pathname = "";
|
|
19
19
|
pageUrl.search = "";
|
|
@@ -56,11 +56,22 @@ async function fetchSnapshot(context) {
|
|
|
56
56
|
}
|
|
57
57
|
__name(fetchSnapshot, "fetchSnapshot");
|
|
58
58
|
var renderToCanvas = /* @__PURE__ */ __name(async (context) => {
|
|
59
|
-
const snapshot = await fetchSnapshot(context);
|
|
59
|
+
const { snapshot, pseudoClassIds } = await fetchSnapshot(context);
|
|
60
60
|
const htmlNode = findHtmlNode(snapshot);
|
|
61
|
-
const
|
|
62
|
-
|
|
61
|
+
const mirror = createMirror();
|
|
62
|
+
const html = rebuild(htmlNode, {
|
|
63
|
+
doc: document,
|
|
64
|
+
mirror,
|
|
65
|
+
cache: createCache()
|
|
63
66
|
});
|
|
67
|
+
for (const [className, ids] of Object.entries(pseudoClassIds)) {
|
|
68
|
+
for (const id of ids) {
|
|
69
|
+
const el = mirror.getNode(id);
|
|
70
|
+
if (el?.classList) {
|
|
71
|
+
el.classList.add(className);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
64
75
|
document.replaceChild(html, document.children[0]);
|
|
65
76
|
document.head.innerHTML += '<script id="storybook-root"><\/script><script id="storybook-docs"><\/script>';
|
|
66
77
|
context.showMain();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromatic-com/vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-4b34acb-20260428052623",
|
|
4
4
|
"description": "Chromatic Visual Regression Testing for Vitest",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test:vitest": "vitest --config test/vitest.config.e2e.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@chromaui/rrweb-snapshot": "2.0.0-alpha.
|
|
41
|
+
"@chromaui/rrweb-snapshot": "2.0.0-alpha.19-noAbsolute",
|
|
42
42
|
"@segment/analytics-node": "2.1.3",
|
|
43
43
|
"storybook": "10.2.13",
|
|
44
44
|
"tinyrainbow": "^3.1.0"
|