@uiverify/vitest 0.1.0 → 1.0.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/README.md CHANGED
@@ -44,7 +44,7 @@ import { render } from "vitest-browser-react"; // or your framework's browser re
44
44
  import { takeSnapshot, disableAutoSnapshot } from "@uiverify/vitest";
45
45
 
46
46
  test("menu", async () => {
47
- render(<Menu />);
47
+ await render(<Menu />); // render() is async - await it so the DOM is committed before capture
48
48
  await takeSnapshot("closed"); // optional named checkpoint
49
49
  // the final state is archived automatically at the end of the test
50
50
  });
@@ -2,9 +2,13 @@ import {
2
2
  autoSnapshot,
3
3
  beginTest
4
4
  } from "./chunk-ZCABESWT.js";
5
+ import {
6
+ UI_VERIFY_GLOBAL
7
+ } from "./chunk-X2KT34IP.js";
5
8
 
6
9
  // src/browser-setup.ts
7
10
  import { afterEach, beforeEach, inject } from "vitest";
11
+ Reflect.set(globalThis, UI_VERIFY_GLOBAL, true);
8
12
  function globalAutoDisabled() {
9
13
  try {
10
14
  return Boolean(inject("__uiverify")?.disableAutoSnapshot);
@@ -0,0 +1,40 @@
1
+ // ../archive-core/src/out-dir.ts
2
+ import path from "path";
3
+ function resolveOutDir() {
4
+ return process.env.UIVERIFY_ARCHIVE_DIR ?? path.resolve(process.cwd(), "uiverify-archive");
5
+ }
6
+
7
+ // ../archive-core/src/ui-verify.ts
8
+ var UI_VERIFY_GLOBAL = "__UI_VERIFY__";
9
+ var UI_VERIFY_MARKER_SCRIPT = `globalThis.${UI_VERIFY_GLOBAL} = true;`;
10
+
11
+ // ../archive-core/src/write.ts
12
+ import fs from "fs";
13
+ import path2 from "path";
14
+
15
+ // ../archive-core/src/snapshot-file.ts
16
+ import { createHash } from "crypto";
17
+ function snapshotFileName(id) {
18
+ const slug = id.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
19
+ const hash = createHash("sha1").update(id).digest("hex").slice(0, 10);
20
+ return `${slug || "snapshot"}-${hash}.json`;
21
+ }
22
+
23
+ // ../archive-core/src/write.ts
24
+ function writeSnapshot(outDir, snapshot) {
25
+ const dir = path2.join(outDir, "snapshots");
26
+ fs.mkdirSync(dir, { recursive: true });
27
+ const file = path2.join(dir, snapshotFileName(snapshot.id));
28
+ fs.writeFileSync(file, JSON.stringify(snapshot));
29
+ return file;
30
+ }
31
+
32
+ // ../archive-core/src/finalize.ts
33
+ import fs2 from "fs";
34
+ import path3 from "path";
35
+
36
+ export {
37
+ resolveOutDir,
38
+ UI_VERIFY_GLOBAL,
39
+ writeSnapshot
40
+ };
package/dist/plugin.js CHANGED
@@ -1,37 +1,19 @@
1
- // ../archive-core/src/snapshot-file.ts
2
- import { createHash } from "crypto";
3
- function snapshotFileName(id) {
4
- const slug = id.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
5
- const hash = createHash("sha1").update(id).digest("hex").slice(0, 10);
6
- return `${slug || "snapshot"}-${hash}.json`;
7
- }
8
-
9
- // ../archive-core/src/out-dir.ts
10
- import path from "path";
11
- function resolveOutDir() {
12
- return process.env.UIVERIFY_ARCHIVE_DIR ?? path.resolve(process.cwd(), "uiverify-archive");
13
- }
14
-
15
- // ../archive-core/src/write.ts
16
- import fs from "fs";
17
- import path2 from "path";
18
- function writeSnapshot(outDir, snapshot) {
19
- const dir = path2.join(outDir, "snapshots");
20
- fs.mkdirSync(dir, { recursive: true });
21
- const file = path2.join(dir, snapshotFileName(snapshot.id));
22
- fs.writeFileSync(file, JSON.stringify(snapshot));
23
- return file;
24
- }
25
-
26
- // ../archive-core/src/finalize.ts
27
- import fs2 from "fs";
28
- import path3 from "path";
1
+ import {
2
+ resolveOutDir,
3
+ writeSnapshot
4
+ } from "./chunk-X2KT34IP.js";
29
5
 
30
6
  // src/plugin.ts
31
7
  var SETUP_MODULE = "@uiverify/vitest/browser-setup";
32
8
  function uiverifyPlugin(options = {}) {
33
9
  const outDir = options.outDir ?? resolveOutDir();
34
10
  const config = {
11
+ // The capture state (`currentTask`) lives in module scope in `runtime.ts`, shared between the setup
12
+ // file's hooks and the user's `takeSnapshot` import. Dep pre-bundling would give those two entry
13
+ // points separate copies of that module, so `takeSnapshot()` would not see the running test and throw
14
+ // "called outside a test". Excluding the package from optimize keeps everyone on one instance, so a
15
+ // plain `plugins: [uiverifyPlugin()]` works without the user hand-adding this to their config.
16
+ optimizeDeps: { exclude: ["@uiverify/vitest"] },
35
17
  test: {
36
18
  setupFiles: [SETUP_MODULE],
37
19
  provide: { __uiverify: { disableAutoSnapshot: options.disableAutoSnapshot ?? false } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiverify/vitest",
3
- "version": "0.1.0",
3
+ "version": "1.0.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",