@uiverify/vitest 1.1.0 → 1.2.1
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/browser-setup.js
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
2
|
autoSnapshot,
|
|
3
|
-
beginTest
|
|
4
|
-
|
|
3
|
+
beginTest,
|
|
4
|
+
preloadFonts
|
|
5
|
+
} from "./chunk-YGUM67UI.js";
|
|
5
6
|
|
|
6
7
|
// src/browser-setup.ts
|
|
7
8
|
import { afterEach, beforeEach, inject } from "vitest";
|
|
9
|
+
|
|
10
|
+
// src/seed.ts
|
|
11
|
+
var INITIAL_SEED = 2685821657736338400;
|
|
12
|
+
var seed = INITIAL_SEED;
|
|
13
|
+
var installed = false;
|
|
14
|
+
function seededRandom() {
|
|
15
|
+
seed ^= seed << 13;
|
|
16
|
+
seed ^= seed >> 7;
|
|
17
|
+
seed ^= seed << 17;
|
|
18
|
+
return (seed >>> 0) % 1e9 / 1e9;
|
|
19
|
+
}
|
|
20
|
+
function installSeededRandom() {
|
|
21
|
+
if (installed) return;
|
|
22
|
+
installed = true;
|
|
23
|
+
Math.random = seededRandom;
|
|
24
|
+
}
|
|
25
|
+
function resetSeed() {
|
|
26
|
+
if (installed) seed = INITIAL_SEED;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/browser-setup.ts
|
|
8
30
|
Reflect.set(globalThis, "__UI_VERIFY__", true);
|
|
31
|
+
performance.setResourceTimingBufferSize?.(1e6);
|
|
32
|
+
installSeededRandom();
|
|
9
33
|
function globalAutoDisabled() {
|
|
10
34
|
try {
|
|
11
35
|
return Boolean(inject("__uiverify")?.disableAutoSnapshot);
|
|
@@ -13,7 +37,9 @@ function globalAutoDisabled() {
|
|
|
13
37
|
return false;
|
|
14
38
|
}
|
|
15
39
|
}
|
|
16
|
-
beforeEach((ctx) => {
|
|
40
|
+
beforeEach(async (ctx) => {
|
|
41
|
+
resetSeed();
|
|
42
|
+
await preloadFonts();
|
|
17
43
|
beginTest(ctx.task);
|
|
18
44
|
});
|
|
19
45
|
afterEach(async (ctx) => {
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
// src/settle.ts
|
|
2
|
+
var SETTLE_TIMEOUT_MS = 3e3;
|
|
3
|
+
var realSetTimeout = typeof setTimeout === "function" ? setTimeout.bind(globalThis) : () => 0;
|
|
4
|
+
function timeout(ms) {
|
|
5
|
+
return new Promise((resolve) => realSetTimeout(() => resolve(), ms));
|
|
6
|
+
}
|
|
7
|
+
function cap(work) {
|
|
8
|
+
return Promise.race([work, timeout(SETTLE_TIMEOUT_MS)]);
|
|
9
|
+
}
|
|
10
|
+
async function preloadFonts() {
|
|
11
|
+
if (typeof document === "undefined" || !document.fonts) return;
|
|
12
|
+
const loadAll = Promise.all(Array.from(document.fonts, (f) => f.load().catch(() => void 0)));
|
|
13
|
+
await cap(loadAll.then(() => document.fonts.ready));
|
|
14
|
+
}
|
|
15
|
+
async function settle() {
|
|
16
|
+
if (typeof document === "undefined") return;
|
|
17
|
+
await preloadFonts();
|
|
18
|
+
const pending = Array.from(document.images).filter((img) => !img.complete);
|
|
19
|
+
if (!pending.length) return;
|
|
20
|
+
await cap(
|
|
21
|
+
Promise.all(
|
|
22
|
+
pending.map(
|
|
23
|
+
(img) => new Promise((resolve) => {
|
|
24
|
+
img.addEventListener("load", () => resolve(), { once: true });
|
|
25
|
+
img.addEventListener("error", () => resolve(), { once: true });
|
|
26
|
+
})
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
1
32
|
// src/capture.ts
|
|
2
33
|
import { commands } from "@vitest/browser/context";
|
|
3
34
|
import { snapshot } from "rrweb-snapshot";
|
|
@@ -26,7 +57,7 @@ function snapshotIds(task, name) {
|
|
|
26
57
|
// package.json
|
|
27
58
|
var package_default = {
|
|
28
59
|
name: "@uiverify/vitest",
|
|
29
|
-
version: "1.1
|
|
60
|
+
version: "1.2.1",
|
|
30
61
|
description: "Vitest browser-mode capture SDK for UI Verify (uiverify.ai): add uiverifyPlugin() to your Vitest config and each browser-mode test archives its final DOM (serialized DOM + resource bytes) to be replayed + visually diffed by UI Verify. Produces an archive the uiverify CLI uploads; talks to nothing at runtime.",
|
|
31
62
|
keywords: [
|
|
32
63
|
"visual-testing",
|
|
@@ -144,6 +175,7 @@ async function collectResources() {
|
|
|
144
175
|
}
|
|
145
176
|
async function capture(task, name) {
|
|
146
177
|
const { id, title } = snapshotIds(task, name);
|
|
178
|
+
await settle();
|
|
147
179
|
const serialize = (recordCanvas) => snapshot(document, { inlineStylesheet: true, recordCanvas, slimDOM: { script: true } });
|
|
148
180
|
let dom;
|
|
149
181
|
try {
|
|
@@ -201,6 +233,7 @@ async function autoSnapshot(passed) {
|
|
|
201
233
|
}
|
|
202
234
|
|
|
203
235
|
export {
|
|
236
|
+
preloadFonts,
|
|
204
237
|
beginTest,
|
|
205
238
|
takeSnapshot,
|
|
206
239
|
disableAutoSnapshot,
|
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,9 @@ declare function takeSnapshot(name?: string): Promise<string>;
|
|
|
6
6
|
/** Turn off the automatic end-of-test snapshot for the current test only. */
|
|
7
7
|
declare function disableAutoSnapshot(): void;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/** Load every registered `@font-face` and wait for the font set to be ready. Exported so a test can call
|
|
10
|
+
* it BEFORE `render()` for a component that measures text width on mount - a mid-load font bakes a wrong
|
|
11
|
+
* metric (a 1px-shifted layout) that settling AFTER render can no longer undo. */
|
|
12
|
+
declare function preloadFonts(): Promise<void>;
|
|
13
|
+
|
|
14
|
+
export { disableAutoSnapshot, preloadFonts, takeSnapshot };
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uiverify/vitest",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Vitest browser-mode capture SDK for UI Verify (uiverify.ai): add uiverifyPlugin() to your Vitest config and each browser-mode test archives its final DOM (serialized DOM + resource bytes) to be replayed + visually diffed by UI Verify. Produces an archive the uiverify CLI uploads; talks to nothing at runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visual-testing",
|