@cevek/screentest 0.3.7 → 0.5.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/dist/runner.js CHANGED
@@ -1,5 +1,4 @@
1
1
  // src/runner/snapshot.ts
2
- import { createHash } from "crypto";
3
2
  import { mkdir, readFile, writeFile } from "fs/promises";
4
3
  import { dirname, join as join2 } from "path";
5
4
  import { expect } from "vitest";
@@ -15,7 +14,8 @@ function resolveRunnerPaths(cwd = process.cwd()) {
15
14
  snapshotFile: resolveSnapshotFile(projectRoot),
16
15
  cacheDir,
17
16
  actualDir: join(cacheDir, "actual"),
18
- docFile: join(cacheDir, "doc.json")
17
+ docFile: join(cacheDir, "doc.json"),
18
+ runFile: join(cacheDir, "run.json")
19
19
  };
20
20
  }
21
21
  function resolveSnapshotFile(projectRoot) {
@@ -29,6 +29,12 @@ function resolveSnapshotFile(projectRoot) {
29
29
  return insideTests;
30
30
  }
31
31
 
32
+ // src/hash.ts
33
+ import { createHash } from "crypto";
34
+ function sha256Hex(buf) {
35
+ return createHash("sha256").update(buf).digest("hex");
36
+ }
37
+
32
38
  // src/runner/stabilize.ts
33
39
  async function freezeDate(ctx, when) {
34
40
  const fixedMs = when instanceof Date ? when.getTime() : typeof when === "number" ? when : Date.parse(when);
@@ -173,7 +179,7 @@ async function compareSnapshot(target, name, opts = {}) {
173
179
  type: "png"
174
180
  });
175
181
  await writeFile(absFile, actualBuf);
176
- const actualHash = createHash("sha256").update(actualBuf).digest("hex");
182
+ const actualHash = sha256Hex(actualBuf);
177
183
  const expectedHash = findExpected(await loadSnapshot(paths.snapshotFile), path);
178
184
  if (expectedHash === void 0) {
179
185
  await insertNullEntry(paths.snapshotFile, path);
@@ -193,15 +199,19 @@ async function compareSnapshot(target, name, opts = {}) {
193
199
  // src/runner/browser.ts
194
200
  import { inject } from "vitest";
195
201
  import { firefox } from "playwright";
202
+
203
+ // src/runner/context-defaults.ts
204
+ var CONTEXT_DEFAULTS = {
205
+ viewport: { width: 1280, height: 800 },
206
+ deviceScaleFactor: 1,
207
+ reducedMotion: "reduce"
208
+ };
209
+
210
+ // src/runner/browser.ts
196
211
  async function newPage(opts = {}) {
197
212
  const wsEndpoint = inject("wsEndpoint");
198
213
  const browser = await firefox.connect(wsEndpoint);
199
- const ctx = await browser.newContext({
200
- viewport: { width: 1280, height: 800 },
201
- deviceScaleFactor: 1,
202
- reducedMotion: "reduce",
203
- ...opts
204
- });
214
+ const ctx = await browser.newContext({ ...CONTEXT_DEFAULTS, ...opts });
205
215
  const page = await ctx.newPage();
206
216
  return {
207
217
  ctx,