@treelocator/runtime 0.5.2 → 0.6.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.
Files changed (163) hide show
  1. package/.eslintignore +1 -0
  2. package/dist/_generated_styles.d.ts +1 -1
  3. package/dist/_generated_styles.js +20 -0
  4. package/dist/_generated_tree_icon.d.ts +1 -1
  5. package/dist/adapters/HtmlElementTreeNode.d.ts +2 -2
  6. package/dist/adapters/HtmlElementTreeNode.js +4 -6
  7. package/dist/adapters/createTreeNode.js +17 -44
  8. package/dist/adapters/detectFramework.d.ts +8 -0
  9. package/dist/adapters/detectFramework.js +25 -0
  10. package/dist/adapters/detectFramework.test.d.ts +1 -0
  11. package/dist/adapters/detectFramework.test.js +60 -0
  12. package/dist/adapters/jsx/jsxAdapter.js +54 -89
  13. package/dist/adapters/jsx/jsxAdapter.test.d.ts +1 -0
  14. package/dist/adapters/jsx/jsxAdapter.test.js +273 -0
  15. package/dist/adapters/nextjs/parseNextjsDataAttributes.js +1 -1
  16. package/dist/adapters/nextjs/parseNextjsDataAttributes.test.d.ts +1 -0
  17. package/dist/adapters/nextjs/parseNextjsDataAttributes.test.js +158 -0
  18. package/dist/adapters/react/findFiberByHtmlElement.d.ts +1 -1
  19. package/dist/adapters/react/findFiberByHtmlElement.js +1 -1
  20. package/dist/adapters/react/getAllParentsElementsAndRootComponent.js +4 -0
  21. package/dist/adapters/resolveAdapter.d.ts +1 -1
  22. package/dist/adapters/resolveAdapter.js +4 -8
  23. package/dist/adapters/svelte/svelteAdapter.test.d.ts +1 -0
  24. package/dist/adapters/svelte/svelteAdapter.test.js +280 -0
  25. package/dist/adapters/vue/vueAdapter.test.d.ts +1 -0
  26. package/dist/adapters/vue/vueAdapter.test.js +222 -0
  27. package/dist/browserApi.d.ts +148 -0
  28. package/dist/browserApi.js +146 -5
  29. package/dist/browserApi.test.d.ts +1 -0
  30. package/dist/browserApi.test.js +287 -0
  31. package/dist/components/RecordingPillButton.d.ts +11 -0
  32. package/dist/components/RecordingPillButton.js +202 -0
  33. package/dist/components/RecordingResults.d.ts +2 -0
  34. package/dist/components/RecordingResults.js +213 -78
  35. package/dist/components/Runtime.js +161 -554
  36. package/dist/components/SettingsPanel.d.ts +5 -0
  37. package/dist/components/SettingsPanel.js +312 -0
  38. package/dist/consoleCapture.d.ts +9 -0
  39. package/dist/consoleCapture.js +95 -0
  40. package/dist/functions/cssRuleInspector.d.ts +83 -0
  41. package/dist/functions/cssRuleInspector.js +608 -0
  42. package/dist/functions/cssRuleInspector.test.d.ts +1 -0
  43. package/dist/functions/cssRuleInspector.test.js +439 -0
  44. package/dist/functions/deduplicateLabels.test.d.ts +1 -0
  45. package/dist/functions/deduplicateLabels.test.js +178 -0
  46. package/dist/functions/enrichAncestrySourceMaps.js +0 -1
  47. package/dist/functions/extractComputedStyles.d.ts +51 -0
  48. package/dist/functions/extractComputedStyles.js +447 -0
  49. package/dist/functions/extractComputedStyles.test.d.ts +1 -0
  50. package/dist/functions/extractComputedStyles.test.js +549 -0
  51. package/dist/functions/formatAncestryChain.d.ts +8 -0
  52. package/dist/functions/formatAncestryChain.js +21 -1
  53. package/dist/functions/formatAncestryChain.test.js +18 -0
  54. package/dist/functions/getUsableName.test.d.ts +1 -0
  55. package/dist/functions/getUsableName.test.js +219 -0
  56. package/dist/functions/isCombinationModifiersPressed.test.d.ts +1 -0
  57. package/dist/functions/isCombinationModifiersPressed.test.js +192 -0
  58. package/dist/functions/mergeRects.test.js +210 -1
  59. package/dist/functions/namedSnapshots.d.ts +52 -0
  60. package/dist/functions/namedSnapshots.js +161 -0
  61. package/dist/functions/namedSnapshots.test.d.ts +1 -0
  62. package/dist/functions/namedSnapshots.test.js +85 -0
  63. package/dist/functions/normalizeFilePath.test.d.ts +1 -0
  64. package/dist/functions/normalizeFilePath.test.js +66 -0
  65. package/dist/functions/parseDataId.test.d.ts +1 -0
  66. package/dist/functions/parseDataId.test.js +101 -0
  67. package/dist/hooks/getStorage.d.ts +3 -0
  68. package/dist/hooks/getStorage.js +17 -0
  69. package/dist/hooks/useEventListeners.d.ts +15 -0
  70. package/dist/hooks/useEventListeners.js +56 -0
  71. package/dist/hooks/useLocatorStorage.d.ts +18 -0
  72. package/dist/hooks/useLocatorStorage.js +41 -0
  73. package/dist/hooks/useLocatorStorage.test.d.ts +1 -0
  74. package/dist/hooks/useLocatorStorage.test.js +124 -0
  75. package/dist/hooks/useRecordingState.d.ts +43 -0
  76. package/dist/hooks/useRecordingState.js +387 -0
  77. package/dist/hooks/useSettings.d.ts +13 -0
  78. package/dist/hooks/useSettings.js +66 -0
  79. package/dist/index.d.ts +5 -2
  80. package/dist/index.js +4 -2
  81. package/dist/initRuntime.d.ts +3 -1
  82. package/dist/initRuntime.js +4 -1
  83. package/dist/mcpBridge.d.ts +61 -0
  84. package/dist/mcpBridge.js +534 -0
  85. package/dist/mcpBridge.test.d.ts +1 -0
  86. package/dist/mcpBridge.test.js +248 -0
  87. package/dist/output.css +20 -0
  88. package/dist/visualDiff/diff.d.ts +9 -0
  89. package/dist/visualDiff/diff.js +209 -0
  90. package/dist/visualDiff/diff.test.d.ts +1 -0
  91. package/dist/visualDiff/diff.test.js +253 -0
  92. package/dist/visualDiff/settle.d.ts +3 -0
  93. package/dist/visualDiff/settle.js +50 -0
  94. package/dist/visualDiff/settle.test.d.ts +1 -0
  95. package/dist/visualDiff/settle.test.js +65 -0
  96. package/dist/visualDiff/snapshot.d.ts +4 -0
  97. package/dist/visualDiff/snapshot.js +84 -0
  98. package/dist/visualDiff/snapshot.test.d.ts +1 -0
  99. package/dist/visualDiff/snapshot.test.js +245 -0
  100. package/dist/visualDiff/types.d.ts +37 -0
  101. package/dist/visualDiff/types.js +1 -0
  102. package/package.json +2 -2
  103. package/scripts/wrapCSS.js +1 -1
  104. package/scripts/wrapImage.js +1 -1
  105. package/src/_generated_styles.ts +21 -1
  106. package/src/_generated_tree_icon.ts +1 -1
  107. package/src/adapters/HtmlElementTreeNode.ts +10 -7
  108. package/src/adapters/createTreeNode.ts +12 -51
  109. package/src/adapters/detectFramework.test.ts +73 -0
  110. package/src/adapters/detectFramework.ts +28 -0
  111. package/src/adapters/jsx/jsxAdapter.test.ts +240 -0
  112. package/src/adapters/jsx/jsxAdapter.ts +53 -106
  113. package/src/adapters/nextjs/parseNextjsDataAttributes.test.ts +212 -0
  114. package/src/adapters/nextjs/parseNextjsDataAttributes.ts +1 -1
  115. package/src/adapters/react/findDebugSource.ts +5 -6
  116. package/src/adapters/react/findFiberByHtmlElement.ts +3 -3
  117. package/src/adapters/react/getAllParentsElementsAndRootComponent.ts +3 -0
  118. package/src/adapters/react/reactAdapter.ts +1 -2
  119. package/src/adapters/resolveAdapter.ts +4 -14
  120. package/src/adapters/svelte/svelteAdapter.test.ts +334 -0
  121. package/src/adapters/vue/vueAdapter.test.ts +259 -0
  122. package/src/browserApi.test.ts +329 -0
  123. package/src/browserApi.ts +351 -4
  124. package/src/components/RecordingPillButton.tsx +301 -0
  125. package/src/components/RecordingResults.tsx +114 -13
  126. package/src/components/Runtime.tsx +176 -621
  127. package/src/components/SettingsPanel.tsx +339 -0
  128. package/src/consoleCapture.ts +113 -0
  129. package/src/functions/cssRuleInspector.test.ts +517 -0
  130. package/src/functions/cssRuleInspector.ts +708 -0
  131. package/src/functions/deduplicateLabels.test.ts +115 -0
  132. package/src/functions/enrichAncestrySourceMaps.ts +6 -3
  133. package/src/functions/extractComputedStyles.test.ts +681 -0
  134. package/src/functions/extractComputedStyles.ts +768 -0
  135. package/src/functions/formatAncestryChain.test.ts +23 -1
  136. package/src/functions/formatAncestryChain.ts +22 -1
  137. package/src/functions/getUsableName.test.ts +242 -0
  138. package/src/functions/isCombinationModifiersPressed.test.ts +156 -0
  139. package/src/functions/mergeRects.test.ts +111 -1
  140. package/src/functions/namedSnapshots.test.ts +106 -0
  141. package/src/functions/namedSnapshots.ts +232 -0
  142. package/src/functions/normalizeFilePath.test.ts +80 -0
  143. package/src/functions/parseDataId.test.ts +125 -0
  144. package/src/hooks/getStorage.ts +26 -0
  145. package/src/hooks/useEventListeners.ts +97 -0
  146. package/src/hooks/useLocatorStorage.test.ts +127 -0
  147. package/src/hooks/useLocatorStorage.ts +60 -0
  148. package/src/hooks/useRecordingState.ts +516 -0
  149. package/src/hooks/useSettings.ts +83 -0
  150. package/src/index.ts +10 -5
  151. package/src/initRuntime.ts +5 -0
  152. package/src/mcpBridge.test.ts +260 -0
  153. package/src/mcpBridge.ts +677 -0
  154. package/src/visualDiff/diff.test.ts +167 -0
  155. package/src/visualDiff/diff.ts +242 -0
  156. package/src/visualDiff/settle.test.ts +77 -0
  157. package/src/visualDiff/settle.ts +62 -0
  158. package/src/visualDiff/snapshot.test.ts +200 -0
  159. package/src/visualDiff/snapshot.ts +119 -0
  160. package/src/visualDiff/types.ts +40 -0
  161. package/tsconfig.json +3 -1
  162. package/vitest.config.ts +18 -0
  163. package/jest.config.ts +0 -195
@@ -0,0 +1,200 @@
1
+ import { describe, expect, test, beforeEach, afterEach, vi } from "vitest";
2
+ import { takeSnapshot, MAX_SNAPSHOT_ELEMENTS } from "./snapshot";
3
+
4
+ function stubRect(el: Element, rect: Partial<DOMRect>): void {
5
+ const full: DOMRect = {
6
+ x: rect.x ?? 0,
7
+ y: rect.y ?? 0,
8
+ width: rect.width ?? 100,
9
+ height: rect.height ?? 100,
10
+ top: rect.y ?? 0,
11
+ left: rect.x ?? 0,
12
+ right: (rect.x ?? 0) + (rect.width ?? 100),
13
+ bottom: (rect.y ?? 0) + (rect.height ?? 100),
14
+ toJSON() {
15
+ return this;
16
+ },
17
+ };
18
+ el.getBoundingClientRect = () => full;
19
+ }
20
+
21
+ describe("takeSnapshot", () => {
22
+ beforeEach(() => {
23
+ document.body.innerHTML = "";
24
+ Object.defineProperty(window, "innerWidth", {
25
+ writable: true,
26
+ configurable: true,
27
+ value: 1280,
28
+ });
29
+ Object.defineProperty(window, "innerHeight", {
30
+ writable: true,
31
+ configurable: true,
32
+ value: 720,
33
+ });
34
+ });
35
+
36
+ afterEach(() => {
37
+ document.body.innerHTML = "";
38
+ });
39
+
40
+ test("returns ElementSnapshot array with expected fields", () => {
41
+ const div = document.createElement("div");
42
+ div.id = "hello";
43
+ div.className = "foo bar";
44
+ div.textContent = "Hi there";
45
+ document.body.appendChild(div);
46
+ stubRect(div, { x: 10, y: 20, width: 100, height: 50 });
47
+
48
+ const snaps = takeSnapshot();
49
+ const found = snaps.find((s) => s.id === "hello");
50
+ expect(found).toBeDefined();
51
+ expect(found!.tagName).toBe("div");
52
+ expect(found!.classes).toEqual(["foo", "bar"]);
53
+ expect(found!.x).toBe(10);
54
+ expect(found!.y).toBe(20);
55
+ expect(found!.width).toBe(100);
56
+ expect(found!.height).toBe(50);
57
+ expect(found!.text).toBe("Hi there");
58
+ expect(found!.visible).toBe(true);
59
+ expect(found!.inViewport).toBe(true);
60
+ expect(typeof found!.key).toBe("string");
61
+ });
62
+
63
+ test("excludes elements inside #locatorjs-wrapper", () => {
64
+ const wrapper = document.createElement("div");
65
+ wrapper.id = "locatorjs-wrapper";
66
+ const child = document.createElement("span");
67
+ child.id = "overlay-child";
68
+ wrapper.appendChild(child);
69
+ document.body.appendChild(wrapper);
70
+ stubRect(child, { x: 0, y: 0, width: 50, height: 50 });
71
+
72
+ const snaps = takeSnapshot();
73
+ expect(snaps.find((s) => s.id === "overlay-child")).toBeUndefined();
74
+ expect(snaps.find((s) => s.id === "locatorjs-wrapper")).toBeUndefined();
75
+ });
76
+
77
+ test("elements outside viewport have inViewport: false and are skipped", () => {
78
+ const div = document.createElement("div");
79
+ div.id = "off-screen";
80
+ document.body.appendChild(div);
81
+ stubRect(div, { x: 5000, y: 5000, width: 100, height: 100 });
82
+
83
+ const snaps = takeSnapshot();
84
+ expect(snaps.find((s) => s.id === "off-screen")).toBeUndefined();
85
+ });
86
+
87
+ test("text is trimmed and capped at 80 chars", () => {
88
+ const div = document.createElement("div");
89
+ div.id = "long-text";
90
+ div.textContent = " " + "x".repeat(200) + " ";
91
+ document.body.appendChild(div);
92
+ stubRect(div, { x: 0, y: 0, width: 100, height: 100 });
93
+
94
+ const snaps = takeSnapshot();
95
+ const found = snaps.find((s) => s.id === "long-text");
96
+ expect(found).toBeDefined();
97
+ expect(found!.text!.length).toBe(80);
98
+ expect(found!.text!.startsWith("x")).toBe(true);
99
+ });
100
+
101
+ test("display:none elements have visible: false", () => {
102
+ const div = document.createElement("div");
103
+ div.id = "hidden";
104
+ div.style.display = "none";
105
+ document.body.appendChild(div);
106
+ stubRect(div, { x: 0, y: 0, width: 100, height: 100 });
107
+
108
+ const snaps = takeSnapshot();
109
+ const found = snaps.find((s) => s.id === "hidden");
110
+ expect(found?.visible).toBe(false);
111
+ });
112
+
113
+ test("disabled form elements have disabled: true", () => {
114
+ const btn = document.createElement("button");
115
+ btn.id = "btn";
116
+ btn.disabled = true;
117
+ document.body.appendChild(btn);
118
+ stubRect(btn, { x: 0, y: 0, width: 80, height: 30 });
119
+
120
+ const snaps = takeSnapshot();
121
+ const found = snaps.find((s) => s.id === "btn");
122
+ expect(found?.disabled).toBe(true);
123
+ });
124
+
125
+ test("caps at MAX_SNAPSHOT_ELEMENTS", () => {
126
+ vi.spyOn(console, "warn").mockImplementation(() => {});
127
+ for (let i = 0; i < MAX_SNAPSHOT_ELEMENTS + 200; i++) {
128
+ const d = document.createElement("div");
129
+ document.body.appendChild(d);
130
+ stubRect(d, { x: 0, y: 0, width: 10, height: 10 });
131
+ }
132
+ const snaps = takeSnapshot();
133
+ expect(snaps.length).toBeLessThanOrEqual(MAX_SNAPSHOT_ELEMENTS);
134
+ });
135
+
136
+ test("text is only captured for leaf elements (no element children)", () => {
137
+ const parent = document.createElement("div");
138
+ parent.id = "parent";
139
+ const child = document.createElement("span");
140
+ child.id = "child";
141
+ child.textContent = "leaf text";
142
+ parent.appendChild(child);
143
+ document.body.appendChild(parent);
144
+ stubRect(parent, { x: 0, y: 0, width: 100, height: 100 });
145
+ stubRect(child, { x: 0, y: 0, width: 50, height: 20 });
146
+
147
+ const snaps = takeSnapshot();
148
+ const parentSnap = snaps.find((s) => s.id === "parent");
149
+ const childSnap = snaps.find((s) => s.id === "child");
150
+ expect(parentSnap?.text).toBeUndefined();
151
+ expect(childSnap?.text).toBe("leaf text");
152
+ });
153
+
154
+ test("scoped snapshot only includes root + descendants", () => {
155
+ const outside = document.createElement("div");
156
+ outside.id = "outside";
157
+ document.body.appendChild(outside);
158
+ stubRect(outside, { x: 0, y: 0, width: 100, height: 100 });
159
+
160
+ const root = document.createElement("div");
161
+ root.id = "root";
162
+ const child = document.createElement("span");
163
+ child.id = "inside-child";
164
+ root.appendChild(child);
165
+ document.body.appendChild(root);
166
+ stubRect(root, { x: 10, y: 10, width: 100, height: 100 });
167
+ stubRect(child, { x: 10, y: 10, width: 50, height: 20 });
168
+
169
+ const snaps = takeSnapshot(root);
170
+ const ids = snaps.map((s) => s.id).filter(Boolean);
171
+ expect(ids).toContain("root");
172
+ expect(ids).toContain("inside-child");
173
+ expect(ids).not.toContain("outside");
174
+ });
175
+
176
+ test("strips locatorjs-* classes from the classes array", () => {
177
+ const div = document.createElement("div");
178
+ div.id = "with-locator-class";
179
+ div.className = "foo locatorjs-active-pointer bar";
180
+ document.body.appendChild(div);
181
+ stubRect(div, { x: 0, y: 0, width: 50, height: 50 });
182
+
183
+ const snaps = takeSnapshot();
184
+ const found = snaps.find((s) => s.id === "with-locator-class");
185
+ expect(found?.classes).toEqual(["foo", "bar"]);
186
+ });
187
+
188
+ test("assigns stable keys for the same element across snapshots", () => {
189
+ const div = document.createElement("div");
190
+ div.id = "stable";
191
+ document.body.appendChild(div);
192
+ stubRect(div, { x: 0, y: 0, width: 50, height: 50 });
193
+
194
+ const a = takeSnapshot();
195
+ const b = takeSnapshot();
196
+ const aKey = a.find((s) => s.id === "stable")!.key;
197
+ const bKey = b.find((s) => s.id === "stable")!.key;
198
+ expect(aKey).toBe(bKey);
199
+ });
200
+ });
@@ -0,0 +1,119 @@
1
+ import { getReferenceId } from "../functions/getReferenceId";
2
+ import { isLocatorsOwnElement } from "../functions/isLocatorsOwnElement";
3
+ import type { ElementSnapshot } from "./types";
4
+
5
+ export const MAX_SNAPSHOT_ELEMENTS = 2000;
6
+ const TEXT_LIMIT = 80;
7
+
8
+ let warnedOverflow = false;
9
+
10
+ function truncateText(raw: string | null): string | undefined {
11
+ if (!raw) return undefined;
12
+ const trimmed = raw.trim();
13
+ if (!trimmed) return undefined;
14
+ return trimmed.length > TEXT_LIMIT ? trimmed.slice(0, TEXT_LIMIT) : trimmed;
15
+ }
16
+
17
+ function snapshotElement(el: HTMLElement | SVGElement): ElementSnapshot | null {
18
+ const rect = el.getBoundingClientRect();
19
+ const style = getComputedStyle(el);
20
+
21
+ const viewportWidth =
22
+ typeof window !== "undefined" ? window.innerWidth : 0;
23
+ const viewportHeight =
24
+ typeof window !== "undefined" ? window.innerHeight : 0;
25
+
26
+ const inViewport =
27
+ rect.x + rect.width > 0 &&
28
+ rect.y + rect.height > 0 &&
29
+ rect.x < viewportWidth &&
30
+ rect.y < viewportHeight;
31
+
32
+ if (!inViewport) return null;
33
+
34
+ const opacity = parseFloat(style.opacity || "1");
35
+ const displayNone = style.display === "none";
36
+ const hidden = style.visibility === "hidden";
37
+ const zeroSize = rect.width <= 0 || rect.height <= 0;
38
+ const visible = !displayNone && !hidden && !zeroSize;
39
+
40
+ const rawClasses =
41
+ typeof el.className === "string"
42
+ ? el.className.split(/\s+/).filter(Boolean)
43
+ : Array.from(el.classList);
44
+ const classes = rawClasses.filter((c) => !c.startsWith("locatorjs-"));
45
+
46
+ const disabled =
47
+ (el as HTMLInputElement | HTMLButtonElement).disabled === true;
48
+
49
+ const hasElementChildren = el.children.length > 0;
50
+ const text = hasElementChildren ? undefined : truncateText(el.textContent);
51
+
52
+ return {
53
+ key: String(getReferenceId(el)),
54
+ tagName: el.tagName.toLowerCase(),
55
+ id: el.id || undefined,
56
+ classes,
57
+ x: rect.x,
58
+ y: rect.y,
59
+ width: rect.width,
60
+ height: rect.height,
61
+ visible,
62
+ opacity: Number.isFinite(opacity) ? opacity : 1,
63
+ inViewport,
64
+ pointerEvents: style.pointerEvents || "auto",
65
+ disabled,
66
+ text,
67
+ };
68
+ }
69
+
70
+ export function takeSnapshot(
71
+ root?: HTMLElement | SVGElement | null
72
+ ): ElementSnapshot[] {
73
+ if (typeof document === "undefined") return [];
74
+
75
+ const out: ElementSnapshot[] = [];
76
+ const candidates: Array<HTMLElement | SVGElement> = [];
77
+
78
+ if (root) {
79
+ if (root instanceof HTMLElement || root instanceof SVGElement) {
80
+ candidates.push(root);
81
+ }
82
+ const descendants = root.querySelectorAll<HTMLElement | SVGElement>("*");
83
+ for (let i = 0; i < descendants.length; i++) {
84
+ candidates.push(descendants[i]!);
85
+ }
86
+ } else {
87
+ const all = document.querySelectorAll<HTMLElement | SVGElement>("*");
88
+ for (let i = 0; i < all.length; i++) {
89
+ candidates.push(all[i]!);
90
+ }
91
+ }
92
+
93
+ for (let i = 0; i < candidates.length; i++) {
94
+ const el = candidates[i]!;
95
+ if (!(el instanceof HTMLElement) && !(el instanceof SVGElement)) continue;
96
+ if (el instanceof HTMLElement && isLocatorsOwnElement(el)) continue;
97
+
98
+ const snap = snapshotElement(el);
99
+ if (!snap) continue;
100
+ out.push(snap);
101
+
102
+ if (out.length >= MAX_SNAPSHOT_ELEMENTS) {
103
+ if (!warnedOverflow) {
104
+ warnedOverflow = true;
105
+ // eslint-disable-next-line no-console
106
+ console.warn(
107
+ `[treelocator/visualDiff] snapshot capped at ${MAX_SNAPSHOT_ELEMENTS} elements`
108
+ );
109
+ }
110
+ break;
111
+ }
112
+ }
113
+
114
+ return out;
115
+ }
116
+
117
+ export function __resetSnapshotWarningForTests(): void {
118
+ warnedOverflow = false;
119
+ }
@@ -0,0 +1,40 @@
1
+ export interface ElementSnapshot {
2
+ key: string;
3
+ tagName: string;
4
+ id?: string;
5
+ classes: string[];
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ visible: boolean;
11
+ opacity: number;
12
+ inViewport: boolean;
13
+ pointerEvents: string;
14
+ disabled: boolean;
15
+ text?: string;
16
+ }
17
+
18
+ export type DeltaChangeType = "+" | "-" | "~" | "→";
19
+
20
+ export interface DeltaEntry {
21
+ type: DeltaChangeType;
22
+ key: string;
23
+ label: string;
24
+ before?: ElementSnapshot;
25
+ after?: ElementSnapshot;
26
+ changedFields?: string[];
27
+ }
28
+
29
+ export interface DeltaReport {
30
+ elapsedMs: number;
31
+ settle: "clean" | "timeout";
32
+ counts: {
33
+ added: number;
34
+ removed: number;
35
+ changed: number;
36
+ moved: number;
37
+ };
38
+ entries: DeltaEntry[];
39
+ text: string;
40
+ }
package/tsconfig.json CHANGED
@@ -15,6 +15,8 @@
15
15
  "strictNullChecks": true,
16
16
  "noImplicitAny": true,
17
17
  "esModuleInterop": true,
18
- "skipLibCheck": true
18
+ "skipLibCheck": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true
19
21
  }
20
22
  }
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: "jsdom",
6
+ include: ["src/**/*.test.ts", "src/**/*.test.tsx"],
7
+ exclude: ["src/_generated_*"],
8
+ coverage: {
9
+ provider: "v8",
10
+ include: ["src/**/*.ts", "src/**/*.tsx"],
11
+ exclude: ["src/**/*.test.*", "src/_generated_*"],
12
+ thresholds: {
13
+ lines: 5,
14
+ functions: 5,
15
+ },
16
+ },
17
+ },
18
+ });
package/jest.config.ts DELETED
@@ -1,195 +0,0 @@
1
- /*
2
- * For a detailed explanation regarding each configuration property and type check, visit:
3
- * https://jestjs.io/docs/configuration
4
- */
5
-
6
- export default {
7
- // All imported modules in your tests should be mocked automatically
8
- // automock: false,
9
-
10
- // Stop running tests after `n` failures
11
- // bail: 0,
12
-
13
- // The directory where Jest should store its cached dependency information
14
- // cacheDirectory: "/private/var/folders/05/1z3zrcyx19jchm73d29d5kjr0000gn/T/jest_dx",
15
-
16
- // Automatically clear mock calls, instances, contexts and results before every test
17
- // clearMocks: false,
18
-
19
- // Indicates whether the coverage information should be collected while executing the test
20
- // collectCoverage: false,
21
-
22
- // An array of glob patterns indicating a set of files for which coverage information should be collected
23
- // collectCoverageFrom: undefined,
24
-
25
- // The directory where Jest should output its coverage files
26
- // coverageDirectory: undefined,
27
-
28
- // An array of regexp pattern strings used to skip coverage collection
29
- // coveragePathIgnorePatterns: [
30
- // "/node_modules/"
31
- // ],
32
-
33
- // Indicates which provider should be used to instrument code for coverage
34
- // coverageProvider: "babel",
35
-
36
- // A list of reporter names that Jest uses when writing coverage reports
37
- // coverageReporters: [
38
- // "json",
39
- // "text",
40
- // "lcov",
41
- // "clover"
42
- // ],
43
-
44
- // An object that configures minimum threshold enforcement for coverage results
45
- // coverageThreshold: undefined,
46
-
47
- // A path to a custom dependency extractor
48
- // dependencyExtractor: undefined,
49
-
50
- // Make calling deprecated APIs throw helpful error messages
51
- // errorOnDeprecated: false,
52
-
53
- // The default configuration for fake timers
54
- // fakeTimers: {
55
- // "enableGlobally": false
56
- // },
57
-
58
- // Force coverage collection from ignored files using an array of glob patterns
59
- // forceCoverageMatch: [],
60
-
61
- // A path to a module which exports an async function that is triggered once before all test suites
62
- // globalSetup: undefined,
63
-
64
- // A path to a module which exports an async function that is triggered once after all test suites
65
- // globalTeardown: undefined,
66
-
67
- // A set of global variables that need to be available in all test environments
68
- // globals: {},
69
-
70
- // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
71
- // maxWorkers: "50%",
72
-
73
- // An array of directory names to be searched recursively up from the requiring module's location
74
- // moduleDirectories: [
75
- // "node_modules"
76
- // ],
77
-
78
- // An array of file extensions your modules use
79
- // moduleFileExtensions: [
80
- // "js",
81
- // "mjs",
82
- // "cjs",
83
- // "jsx",
84
- // "ts",
85
- // "tsx",
86
- // "json",
87
- // "node"
88
- // ],
89
-
90
- // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
91
- // moduleNameMapper: {},
92
-
93
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
94
- // modulePathIgnorePatterns: [],
95
-
96
- // Activates notifications for test results
97
- // notify: false,
98
-
99
- // An enum that specifies notification mode. Requires { notify: true }
100
- // notifyMode: "failure-change",
101
-
102
- // A preset that is used as a base for Jest's configuration
103
- // preset: undefined,
104
-
105
- // Run tests from one or more projects
106
- // projects: undefined,
107
-
108
- // Use this configuration option to add custom reporters to Jest
109
- // reporters: undefined,
110
-
111
- // Automatically reset mock state before every test
112
- // resetMocks: false,
113
-
114
- // Reset the module registry before running each individual test
115
- // resetModules: false,
116
-
117
- // A path to a custom resolver
118
- // resolver: undefined,
119
-
120
- // Automatically restore mock state and implementation before every test
121
- // restoreMocks: false,
122
-
123
- // The root directory that Jest should scan for tests and modules within
124
- // rootDir: undefined,
125
-
126
- // A list of paths to directories that Jest should use to search for files in
127
- // roots: [
128
- // "<rootDir>"
129
- // ],
130
-
131
- // Allows you to use a custom runner instead of Jest's default test runner
132
- // runner: "jest-runner",
133
-
134
- // The paths to modules that run some code to configure or set up the testing environment before each test
135
- // setupFiles: [],
136
-
137
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
138
- // setupFilesAfterEnv: [],
139
-
140
- // The number of seconds after which a test is considered as slow and reported as such in the results.
141
- // slowTestThreshold: 5,
142
-
143
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
144
- // snapshotSerializers: [],
145
-
146
- // The test environment that will be used for testing
147
- testEnvironment: "jsdom",
148
-
149
- // Options that will be passed to the testEnvironment
150
- // testEnvironmentOptions: {},
151
-
152
- // Adds a location field to test results
153
- // testLocationInResults: false,
154
-
155
- // The glob patterns Jest uses to detect test files
156
- testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
157
-
158
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
159
- // testPathIgnorePatterns: [
160
- // "/node_modules/"
161
- // ],
162
-
163
- // The regexp pattern or array of patterns that Jest uses to detect test files
164
- // testRegex: [],
165
-
166
- // This option allows the use of a custom results processor
167
- // testResultsProcessor: undefined,
168
-
169
- // This option allows use of a custom test runner
170
- // testRunner: "jest-circus/runner",
171
-
172
- // A map from regular expressions to paths to transformers
173
- // transform: undefined,
174
- transform: {
175
- "\\.tsx?$": "babel-jest",
176
- },
177
-
178
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
179
- // transformIgnorePatterns: [
180
- // "/node_modules/",
181
- // "\\.pnp\\.[^\\/]+$"
182
- // ],
183
-
184
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
185
- // unmockedModulePathPatterns: undefined,
186
-
187
- // Indicates whether each individual test should be reported during the run
188
- // verbose: undefined,
189
-
190
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
191
- // watchPathIgnorePatterns: [],
192
-
193
- // Whether to use watchman for file crawling
194
- // watchman: true,
195
- };