@uniflowed/vrt 0.14.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/index.js +59 -0
- package/package.json +23 -0
package/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type { TestPage, ScreenshotResult } from "@uniflowed/test/browser";
|
|
3
|
+
export type VisualSnapshot = {|
|
|
4
|
+
readonly storyId: string,
|
|
5
|
+
readonly viewport: string,
|
|
6
|
+
readonly baseline: string,
|
|
7
|
+
|};
|
|
8
|
+
export type VrtEngine = "chromium-cdp";
|
|
9
|
+
export type DiffAlgorithm = "pixelmatch";
|
|
10
|
+
export type BaselinePolicy = "explicit-update-only";
|
|
11
|
+
export type VisualRegressionPlan = {|
|
|
12
|
+
readonly engine: VrtEngine,
|
|
13
|
+
readonly baselines: string,
|
|
14
|
+
readonly threshold: number,
|
|
15
|
+
readonly diff: DiffAlgorithm,
|
|
16
|
+
readonly baselinePolicy: BaselinePolicy,
|
|
17
|
+
readonly snapshots: $ReadOnlyArray<VisualSnapshot>,
|
|
18
|
+
|};
|
|
19
|
+
export function plan(snapshots?: $ReadOnlyArray<VisualSnapshot>): VisualRegressionPlan {
|
|
20
|
+
return {
|
|
21
|
+
engine: "chromium-cdp",
|
|
22
|
+
baselines: "__uf_vrt__",
|
|
23
|
+
threshold: 0,
|
|
24
|
+
diff: "pixelmatch",
|
|
25
|
+
baselinePolicy: "explicit-update-only",
|
|
26
|
+
snapshots: snapshots ?? [],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function snapshot(storyId: string, viewport: string): VisualSnapshot {
|
|
30
|
+
for (const name of [storyId, viewport]) {
|
|
31
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,49}$/.test(name) || name.includes(".."))
|
|
32
|
+
throw new TypeError("VRT story and viewport names must be short file-safe identifiers");
|
|
33
|
+
}
|
|
34
|
+
return { storyId, viewport, baseline: `${storyId.length}-${storyId}-${viewport}` };
|
|
35
|
+
}
|
|
36
|
+
/** The application resolves each story and viewport to a ready, isolated page. */
|
|
37
|
+
export async function diff(
|
|
38
|
+
value: VisualRegressionPlan,
|
|
39
|
+
render: (snapshot: VisualSnapshot) => Promise<TestPage>,
|
|
40
|
+
): Promise<$ReadOnlyArray<ScreenshotResult>> {
|
|
41
|
+
const results = [];
|
|
42
|
+
for (const entry of value.snapshots) {
|
|
43
|
+
const page = await render(entry);
|
|
44
|
+
try {
|
|
45
|
+
results.push(
|
|
46
|
+
await page.screenshot(entry.baseline, {
|
|
47
|
+
threshold: value.threshold,
|
|
48
|
+
baselines: value.baselines,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
} finally {
|
|
52
|
+
await page.close();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return results;
|
|
56
|
+
}
|
|
57
|
+
export function baseline(path: string): VisualRegressionPlan {
|
|
58
|
+
return { ...plan(), baselines: path };
|
|
59
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uniflowed/vrt",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "Chromium test pages and visual comparisons for Flow applications.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/ubugeeei-prod/uf.git",
|
|
11
|
+
"directory": "npm/vrt"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./index.js"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"!*.test.js"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@uniflowed/test": "0.14.0"
|
|
22
|
+
}
|
|
23
|
+
}
|