@cevek/screentest 0.3.6 → 0.4.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,8 +14,7 @@ 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"),
19
- softReportFile: join(cacheDir, "soft-report.json")
17
+ docFile: join(cacheDir, "doc.json")
20
18
  };
21
19
  }
22
20
  function resolveSnapshotFile(projectRoot) {
@@ -30,10 +28,10 @@ function resolveSnapshotFile(projectRoot) {
30
28
  return insideTests;
31
29
  }
32
30
 
33
- // src/runner/soft-mode.ts
34
- function isSoftMode() {
35
- const raw = process.env.SCREENTEST_SOFT?.trim().toLowerCase();
36
- return raw !== void 0 && raw !== "" && raw !== "0" && raw !== "false";
31
+ // src/hash.ts
32
+ import { createHash } from "crypto";
33
+ function sha256Hex(buf) {
34
+ return createHash("sha256").update(buf).digest("hex");
37
35
  }
38
36
 
39
37
  // src/runner/stabilize.ts
@@ -180,28 +178,20 @@ async function compareSnapshot(target, name, opts = {}) {
180
178
  type: "png"
181
179
  });
182
180
  await writeFile(absFile, actualBuf);
183
- const actualHash = createHash("sha256").update(actualBuf).digest("hex");
181
+ const actualHash = sha256Hex(actualBuf);
184
182
  const expectedHash = findExpected(await loadSnapshot(paths.snapshotFile), path);
185
183
  if (expectedHash === void 0) {
186
184
  await insertNullEntry(paths.snapshotFile, path);
187
185
  }
188
- const soft = isSoftMode();
189
186
  if (expectedHash === void 0 || expectedHash === null) {
190
- const message = `Snapshot "${name}" is NEW (hash ${actualHash.slice(0, 12)}\u2026). Run \`screentest review\` to accept it.`;
191
- if (soft) {
192
- console.warn(`[screentest] SOFT: ${message}`);
193
- return;
194
- }
195
- expect.soft(null, message).toBeTruthy();
187
+ expect.soft(
188
+ null,
189
+ `Snapshot "${name}" is NEW (hash ${actualHash.slice(0, 12)}\u2026). Run \`screentest review\` to accept it.`
190
+ ).toBeTruthy();
196
191
  return;
197
192
  }
198
193
  if (actualHash !== expectedHash) {
199
- const message = `Snapshot "${name}" changed. Run \`screentest review\` to inspect.`;
200
- if (soft) {
201
- console.warn(`[screentest] SOFT: ${message}`);
202
- return;
203
- }
204
- expect.soft(actualHash, message).toBe(expectedHash);
194
+ expect.soft(actualHash, `Snapshot "${name}" changed. Run \`screentest review\` to inspect.`).toBe(expectedHash);
205
195
  }
206
196
  }
207
197