@cevek/screentest 0.2.2 → 0.2.3
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/runner.d.ts +23 -4
- package/dist/runner.js +5 -3
- package/package.json +1 -1
package/dist/runner.d.ts
CHANGED
|
@@ -1,21 +1,40 @@
|
|
|
1
|
-
import type { BrowserContext, BrowserContextOptions, Page } from 'playwright';
|
|
1
|
+
import type { BrowserContext, BrowserContextOptions, Page, PageScreenshotOptions } from 'playwright';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Extra Playwright screenshot options the caller can pass through to
|
|
5
|
+
* `compareSnapshot` (e.g. `clip`, `mask`, `omitBackground`, `fullPage: false`).
|
|
6
|
+
* `type` and `path` are reserved — the runner always shoots PNG and writes
|
|
7
|
+
* into `node_modules/.cache/screentest/actual/...`.
|
|
8
|
+
*/
|
|
9
|
+
export type CompareSnapshotOptions = Omit<PageScreenshotOptions, 'type' | 'path'>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Capture a PNG, save under
|
|
5
13
|
* `<project>/node_modules/.cache/screentest/actual/<...path>.png`, and
|
|
6
14
|
* compare its SHA256 against the hash in `<project>/snapshot.json`.
|
|
7
15
|
*
|
|
8
16
|
* The snapshot path is built automatically from the surrounding
|
|
9
17
|
* `describe(...)` + `it(...)` chain, plus `name` as the leaf. Prefix `name`
|
|
10
18
|
* with `/` to opt out of auto-grouping and use an absolute path.
|
|
19
|
+
*
|
|
20
|
+
* Pass `opts` to forward extra Playwright screenshot options (clip, mask,
|
|
21
|
+
* etc.). Defaults: `fullPage: true`, `animations: 'disabled'`,
|
|
22
|
+
* `caret: 'hide'`.
|
|
11
23
|
*/
|
|
12
|
-
export function compareSnapshot(
|
|
24
|
+
export function compareSnapshot(
|
|
25
|
+
page: Page,
|
|
26
|
+
name: string,
|
|
27
|
+
opts?: CompareSnapshotOptions,
|
|
28
|
+
): Promise<void>;
|
|
13
29
|
|
|
14
30
|
/**
|
|
15
31
|
* Freeze `Date` inside `ctx`. `when` may be an ISO string, unix-ms number,
|
|
16
32
|
* or `Date`. Must be called BEFORE the first navigation in the context.
|
|
17
33
|
*/
|
|
18
|
-
export function freezeDate(
|
|
34
|
+
export function freezeDate(
|
|
35
|
+
ctx: BrowserContext,
|
|
36
|
+
when: string | number | Date,
|
|
37
|
+
): Promise<void>;
|
|
19
38
|
|
|
20
39
|
/**
|
|
21
40
|
* Wait for `document.fonts.ready` and every `<img>` to reach `complete`.
|
package/dist/runner.js
CHANGED
|
@@ -96,7 +96,7 @@ function currentTestChain() {
|
|
|
96
96
|
if (!full) return [];
|
|
97
97
|
return full.split(" > ");
|
|
98
98
|
}
|
|
99
|
-
async function compareSnapshot(page, name) {
|
|
99
|
+
async function compareSnapshot(page, name, opts = {}) {
|
|
100
100
|
const explicit = name.split("/").filter(Boolean);
|
|
101
101
|
const path = name.startsWith("/") ? explicit : [...currentTestChain(), ...explicit];
|
|
102
102
|
if (path.length === 0) throw new Error("compareSnapshot: empty name");
|
|
@@ -107,9 +107,11 @@ async function compareSnapshot(page, name) {
|
|
|
107
107
|
await waitForVisualStable(page);
|
|
108
108
|
const actualBuf = await page.screenshot({
|
|
109
109
|
fullPage: true,
|
|
110
|
-
type: "png",
|
|
111
110
|
animations: "disabled",
|
|
112
|
-
caret: "hide"
|
|
111
|
+
caret: "hide",
|
|
112
|
+
...opts,
|
|
113
|
+
type: "png"
|
|
114
|
+
// always — we hash PNG bytes
|
|
113
115
|
});
|
|
114
116
|
await writeFile(absFile, actualBuf);
|
|
115
117
|
const actualHash = createHash("sha256").update(actualBuf).digest("hex");
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.2.
|
|
6
|
+
"version": "0.2.3",
|
|
7
7
|
"description": "Local desktop tool for visual screenshot-test review — CLI, runner helpers, and review UI shipped as a single package.",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|