what-core 0.13.11 → 0.15.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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
@@ -0,0 +1,720 @@
1
+ // src/testing.js
2
+ import { signal, effect, flushSync, createRoot, __devtools, __setDevToolsHooks, __depsOf, __subsOf, __ownerPath } from "./reactive.js";
3
+ import { mount } from "./dom.js";
4
+ import { h } from "./h.js";
5
+ import { capture } from "./diagnostics.js";
6
+ import { settled } from "./async.js";
7
+ var container = null;
8
+ var mountedTrees = /* @__PURE__ */ new Set();
9
+ function trackMount(mountTree) {
10
+ const stopWatching = watchCreations();
11
+ let dispose;
12
+ try {
13
+ dispose = mountTree();
14
+ } catch (err) {
15
+ stopWatching();
16
+ throw err;
17
+ }
18
+ const unmount = () => {
19
+ if (!mountedTrees.has(unmount)) return;
20
+ mountedTrees.delete(unmount);
21
+ try {
22
+ dispose();
23
+ } finally {
24
+ stopWatching();
25
+ }
26
+ };
27
+ mountedTrees.add(unmount);
28
+ return unmount;
29
+ }
30
+ function setupDOM() {
31
+ if (typeof document !== "undefined") {
32
+ container = document.createElement("div");
33
+ container.id = "test-root";
34
+ document.body.appendChild(container);
35
+ }
36
+ return container;
37
+ }
38
+ function cleanup() {
39
+ for (const unmount of [...mountedTrees]) {
40
+ try {
41
+ unmount();
42
+ } catch {
43
+ }
44
+ }
45
+ if (container) {
46
+ container.innerHTML = "";
47
+ if (container.parentNode) {
48
+ container.parentNode.removeChild(container);
49
+ }
50
+ container = null;
51
+ }
52
+ }
53
+ function render(vnode, options = {}) {
54
+ const { container: customContainer } = options;
55
+ const target = customContainer || setupDOM();
56
+ if (!target) {
57
+ throw new Error("No DOM container available. Are you running in Node.js without jsdom?");
58
+ }
59
+ const unmount = trackMount(() => mount(vnode, target));
60
+ return {
61
+ container: target,
62
+ unmount,
63
+ // Query helpers
64
+ getByText: (text) => queryByText(target, text),
65
+ getByTestId: (id) => target.querySelector(`[data-testid="${id}"]`),
66
+ getByRole: (role) => target.querySelector(`[role="${role}"]`),
67
+ getAllByText: (text) => queryAllByText(target, text),
68
+ queryByText: (text) => queryByText(target, text),
69
+ queryByTestId: (id) => target.querySelector(`[data-testid="${id}"]`),
70
+ // Debug
71
+ debug: () => console.log(target.innerHTML),
72
+ // Async utilities
73
+ findByText: (text, timeout) => waitFor(() => queryByText(target, text), { timeout }),
74
+ findByTestId: (id, timeout) => waitFor(() => target.querySelector(`[data-testid="${id}"]`), { timeout })
75
+ };
76
+ }
77
+ function renderTest(Component, props) {
78
+ const target = setupDOM();
79
+ if (!target) {
80
+ throw new Error("No DOM container available. Are you running in Node.js without jsdom?");
81
+ }
82
+ const signalRegistry = {};
83
+ let rootDispose = null;
84
+ let unmountFn;
85
+ createRoot((dispose) => {
86
+ rootDispose = dispose;
87
+ const vnode = h(Component, props || {});
88
+ unmountFn = trackMount(() => mount(vnode, target));
89
+ });
90
+ return {
91
+ container: target,
92
+ // Proxy to access component signals by name
93
+ signals: new Proxy(signalRegistry, {
94
+ get(obj, prop) {
95
+ if (prop in obj) return obj[prop];
96
+ return void 0;
97
+ },
98
+ set(obj, prop, value) {
99
+ obj[prop] = value;
100
+ return true;
101
+ }
102
+ }),
103
+ // Synchronous flush: run all pending effects immediately
104
+ update() {
105
+ flushSync();
106
+ },
107
+ unmount() {
108
+ if (unmountFn) unmountFn();
109
+ if (rootDispose) rootDispose();
110
+ cleanup();
111
+ },
112
+ // Query helpers
113
+ getByText: (text) => queryByText(target, text),
114
+ getByTestId: (id) => target.querySelector(`[data-testid="${id}"]`),
115
+ queryByText: (text) => queryByText(target, text),
116
+ debug: () => console.log(target.innerHTML)
117
+ };
118
+ }
119
+ function flushEffects() {
120
+ flushSync();
121
+ }
122
+ var hookListeners = {
123
+ onSignalUpdate: /* @__PURE__ */ new Set(),
124
+ onEffectRun: /* @__PURE__ */ new Set(),
125
+ onEffectCreate: /* @__PURE__ */ new Set(),
126
+ onEffectDispose: /* @__PURE__ */ new Set()
127
+ };
128
+ var hookBase = null;
129
+ var hookWrapper = null;
130
+ function ensureWrapper() {
131
+ if (!(process.env.NODE_ENV !== "production")) return;
132
+ if (hookWrapper !== null && __devtools === hookWrapper) return;
133
+ const base = __devtools;
134
+ const wrapper = { ...base || {} };
135
+ for (const hook of Object.keys(hookListeners)) {
136
+ wrapper[hook] = (...args) => {
137
+ for (const listener of hookListeners[hook]) listener(...args);
138
+ base?.[hook]?.(...args);
139
+ };
140
+ }
141
+ hookBase = base;
142
+ hookWrapper = wrapper;
143
+ __setDevToolsHooks(wrapper);
144
+ }
145
+ function listenToHook(name, fn) {
146
+ if (!(process.env.NODE_ENV !== "production")) return () => {
147
+ };
148
+ hookListeners[name].add(fn);
149
+ ensureWrapper();
150
+ return () => {
151
+ hookListeners[name].delete(fn);
152
+ if (Object.values(hookListeners).some((set) => set.size > 0)) return;
153
+ if (__devtools === hookWrapper) __setDevToolsHooks(hookBase);
154
+ hookWrapper = null;
155
+ hookBase = null;
156
+ };
157
+ }
158
+ var created = /* @__PURE__ */ new Set();
159
+ var watchers = 0;
160
+ var unwatch = () => {
161
+ };
162
+ function recordCreation(node) {
163
+ created.add(node);
164
+ }
165
+ function forgetCreation(node) {
166
+ created.delete(node);
167
+ }
168
+ function watchCreations() {
169
+ if (!(process.env.NODE_ENV !== "production")) return () => {
170
+ };
171
+ if (watchers++ === 0) {
172
+ const stopCreate = listenToHook("onEffectCreate", recordCreation);
173
+ const stopDispose = listenToHook("onEffectDispose", forgetCreation);
174
+ unwatch = () => {
175
+ stopCreate();
176
+ stopDispose();
177
+ created.clear();
178
+ };
179
+ } else {
180
+ ensureWrapper();
181
+ }
182
+ let watching = true;
183
+ return () => {
184
+ if (!watching) return;
185
+ watching = false;
186
+ if (--watchers === 0) unwatch();
187
+ };
188
+ }
189
+ function componentPath(node) {
190
+ const path = __ownerPath(node).filter((scope) => scope[0] === "<");
191
+ return path.length ? path : null;
192
+ }
193
+ var UNNAMED = "(unnamed)";
194
+ function trackSignals(fn) {
195
+ if (!(process.env.NODE_ENV !== "production")) {
196
+ throw new Error(
197
+ '[what] trackSignals() requires a development build. Signal debug names and the dependency graph API are stripped in production, so there is nothing to report. Run your tests with NODE_ENV !== "production".'
198
+ );
199
+ }
200
+ const accessed = [];
201
+ const written = [];
202
+ const addOnce = (list, name) => {
203
+ if (!list.includes(name)) list.push(name);
204
+ };
205
+ const stopWrites = listenToHook("onSignalUpdate", (sig) => addOnce(written, sig?._debugName || UNNAMED));
206
+ const probe = signal(0, "__trackSignals_probe__");
207
+ const root = { current: null };
208
+ let thrown = null;
209
+ const collectReads = (node, seen) => {
210
+ for (const dep of __depsOf(node)) {
211
+ if (seen.has(dep)) continue;
212
+ seen.add(dep);
213
+ if (typeof dep === "function") {
214
+ addOnce(accessed, dep._debugName || UNNAMED);
215
+ } else {
216
+ collectReads(dep, seen);
217
+ }
218
+ }
219
+ };
220
+ try {
221
+ createRoot((disposeRoot) => {
222
+ root.current = disposeRoot;
223
+ effect(() => {
224
+ probe();
225
+ fn();
226
+ });
227
+ });
228
+ const seen = /* @__PURE__ */ new Set([probe]);
229
+ for (const reader of __subsOf(probe)) collectReads(reader, seen);
230
+ } catch (err) {
231
+ thrown = err;
232
+ } finally {
233
+ root.current?.();
234
+ stopWrites();
235
+ }
236
+ if (thrown) throw thrown;
237
+ return { accessed, written };
238
+ }
239
+ function effectName(node) {
240
+ return (node.fn?.inner ?? node.fn)?.name || "(anonymous)";
241
+ }
242
+ function captureDiagnostics(fn) {
243
+ if (!(process.env.NODE_ENV !== "production")) {
244
+ throw new Error(
245
+ '[what] captureDiagnostics() requires a development build: production builds report no diagnostics, so an empty result would look like a pass. Run your tests with NODE_ENV !== "production".'
246
+ );
247
+ }
248
+ const cap = capture({ quiet: true });
249
+ const stopWatching = watchCreations();
250
+ const seen = /* @__PURE__ */ new Map();
251
+ for (const node of created) seen.set(node, 0);
252
+ const stopRuns = listenToHook("onEffectRun", (node) => {
253
+ seen.set(node, (seen.get(node) ?? 0) + 1);
254
+ });
255
+ const finish = () => {
256
+ stopRuns();
257
+ for (const node of created) if (!seen.has(node)) seen.set(node, 0);
258
+ stopWatching();
259
+ const runs = {};
260
+ const effects = [];
261
+ for (const [node, ran] of seen) {
262
+ const name = effectName(node);
263
+ if (ran > 0) runs[name] = (runs[name] || 0) + ran;
264
+ effects.push({
265
+ name,
266
+ kind: "subHead" in node ? "computed" : "effect",
267
+ owner: componentPath(node),
268
+ runs: ran
269
+ });
270
+ }
271
+ return { events: cap.stop(), runs, effects };
272
+ };
273
+ let result;
274
+ try {
275
+ result = fn();
276
+ } catch (err) {
277
+ finish();
278
+ throw err;
279
+ }
280
+ if (result && typeof result.then === "function") {
281
+ return result.then(
282
+ (value) => ({ ...finish(), result: value }),
283
+ (err) => {
284
+ finish();
285
+ throw err;
286
+ }
287
+ );
288
+ }
289
+ return { ...finish(), result };
290
+ }
291
+ function describeEvents(events) {
292
+ return events.map((e) => {
293
+ const lines = [` ${e.code}${e.count > 1 ? ` \xD7${e.count}` : ""} ${e.message}`];
294
+ if (e.owner?.length) lines.push(` in ${e.owner.join(" \u203A ")}`);
295
+ if (e.loc) lines.push(` at ${e.loc}`);
296
+ lines.push(` fix: ${e.fix}`);
297
+ return lines.join("\n");
298
+ }).join("\n");
299
+ }
300
+ function expectNoDiagnostics(captured, { allow = [] } = {}) {
301
+ const unexpected = captured.events.filter((e) => !allow.includes(e.code));
302
+ if (unexpected.length) {
303
+ throw new Error(`Expected no diagnostics, got ${unexpected.length}:
304
+ ${describeEvents(unexpected)}`);
305
+ }
306
+ }
307
+ var COUNT_OPTIONS = ["exact", "min", "max"];
308
+ function readCount(helper, options, names) {
309
+ if (options === null || typeof options !== "object") {
310
+ throw new TypeError(`[what] ${helper}() takes an options object: { ${names.join(", ")} }.`);
311
+ }
312
+ for (const key of Object.keys(options)) {
313
+ if (!names.includes(key)) {
314
+ throw new TypeError(`[what] ${helper}(): unknown option "${key}". The options are ${names.join(", ")}.`);
315
+ }
316
+ }
317
+ for (const key of COUNT_OPTIONS) {
318
+ const n = options[key];
319
+ if (n !== void 0 && !(Number.isInteger(n) && n >= 0)) {
320
+ throw new TypeError(`[what] ${helper}(): ${key} must be a whole number of 0 or more, got ${String(n)}.`);
321
+ }
322
+ }
323
+ const { exact, min, max } = options;
324
+ if (exact !== void 0 && (min !== void 0 || max !== void 0)) {
325
+ throw new TypeError(`[what] ${helper}(): exact cannot be combined with min or max.`);
326
+ }
327
+ if (min !== void 0 && max !== void 0 && min > max) {
328
+ throw new TypeError(`[what] ${helper}(): min (${min}) is greater than max (${max}).`);
329
+ }
330
+ const lo = exact ?? min ?? (max === void 0 ? 1 : 0);
331
+ const hi = exact ?? max ?? Infinity;
332
+ let text = `between ${lo} and ${hi} times`;
333
+ if (lo === hi) text = `exactly ${lo} time(s)`;
334
+ else if (hi === Infinity) text = `at least ${lo} time(s)`;
335
+ else if (lo === 0) text = `at most ${hi} time(s)`;
336
+ return { lo, hi, text };
337
+ }
338
+ function readName(helper, key, value) {
339
+ if (value !== void 0 && (typeof value !== "string" || value === "")) {
340
+ throw new TypeError(`[what] ${helper}(): ${key} must be a non-empty string, got ${String(value)}.`);
341
+ }
342
+ return value;
343
+ }
344
+ function expectDiagnostic(captured, options) {
345
+ const count = readCount("expectDiagnostic", options, ["code", ...COUNT_OPTIONS]);
346
+ const code = readName("expectDiagnostic", "code", options.code);
347
+ if (code === void 0) throw new TypeError("[what] expectDiagnostic(): code, the ERR_* code to expect, is required.");
348
+ if (captured.events.some((e) => e.code !== code)) {
349
+ throw new Error(`Expected exactly ${code}, got:
350
+ ${describeEvents(captured.events)}`);
351
+ }
352
+ const reported = captured.events.reduce((sum, e) => sum + e.count, 0);
353
+ if (reported < count.lo || reported > count.hi) {
354
+ const got = reported ? `${reported}:
355
+ ${describeEvents(captured.events)}` : "none.";
356
+ throw new Error(`Expected ${code} ${count.text}, got ${got}`);
357
+ }
358
+ }
359
+ function describeRuns(effects) {
360
+ const lines = /* @__PURE__ */ new Map();
361
+ for (const e of effects) {
362
+ if (e.runs === 0) continue;
363
+ const where = e.owner === null ? " \xB7 outside any component" : ` in ${e.owner.join(" \u203A ")}`;
364
+ const label = `${e.name}${e.kind === "computed" ? " (computed)" : ""}`;
365
+ const key = `${label}
366
+ ${where}`;
367
+ const line = lines.get(key);
368
+ if (line) line.runs += e.runs;
369
+ else lines.set(key, { label, where, runs: e.runs });
370
+ }
371
+ if (lines.size === 0) return "No effect ran during the capture.";
372
+ const sorted = [...lines.values()].sort((a, b) => b.runs - a.runs);
373
+ return `All runs:
374
+ ${sorted.map((l) => ` ${l.label}: ${l.runs}${l.where}`).join("\n")}`;
375
+ }
376
+ function expectRuns(captured, options = {}) {
377
+ const count = readCount("expectRuns", options, ["effect", "component", ...COUNT_OPTIONS]);
378
+ const name = readName("expectRuns", "effect", options.effect);
379
+ const component = readName("expectRuns", "component", options.component);
380
+ const tag = component === void 0 ? null : `<${component}>`;
381
+ let matched = name === void 0 && tag === null;
382
+ let ran = 0;
383
+ for (const e of captured.effects) {
384
+ if (name !== void 0 && e.name !== name) continue;
385
+ if (tag !== null && !e.owner?.includes(tag)) continue;
386
+ matched = true;
387
+ ran += e.runs;
388
+ }
389
+ const subject = name === void 0 ? tag === null ? "all effects together" : `effects in ${tag}` : `effect "${name}"${tag === null ? "" : ` in ${tag}`}`;
390
+ const they = name === void 0 ? "they" : "it";
391
+ const runs = describeRuns(captured.effects);
392
+ if (!matched) {
393
+ const which = `${name === void 0 ? "" : ` named "${name}"`}${tag === null ? "" : ` created in ${tag}`}`;
394
+ throw new Error(
395
+ `Expected ${subject} to run ${count.text}, but no effect${which} ran or was known to exist during the capture. An effect that did not run is known only when it was created inside a render()/renderTest() tree or the capture.
396
+ ${runs}`
397
+ );
398
+ }
399
+ if (ran >= count.lo && ran <= count.hi) return;
400
+ throw new Error(`Expected ${subject} to run ${count.text}, ${they} ran ${ran}.
401
+ ${runs}`);
402
+ }
403
+ function mockSignal(name, initialValue) {
404
+ const history = [initialValue];
405
+ let setCount = 0;
406
+ const s = signal(initialValue, name);
407
+ const origSet = s.set;
408
+ s.set = function(next) {
409
+ const nextVal = typeof next === "function" ? next(s.peek()) : next;
410
+ if (!Object.is(s.peek(), nextVal)) {
411
+ setCount++;
412
+ history.push(nextVal);
413
+ }
414
+ return origSet(nextVal);
415
+ };
416
+ const origFn = s;
417
+ const mock = function(...args) {
418
+ if (args.length === 0) {
419
+ return origFn();
420
+ }
421
+ const nextVal = typeof args[0] === "function" ? args[0](origFn.peek()) : args[0];
422
+ if (!Object.is(origFn.peek(), nextVal)) {
423
+ setCount++;
424
+ history.push(nextVal);
425
+ }
426
+ return origFn(nextVal);
427
+ };
428
+ mock._signal = true;
429
+ mock.peek = s.peek;
430
+ mock.set = s.set;
431
+ mock.subscribe = s.subscribe;
432
+ if (s._debugName) mock._debugName = s._debugName;
433
+ Object.defineProperty(mock, "history", {
434
+ get() {
435
+ return history;
436
+ }
437
+ });
438
+ Object.defineProperty(mock, "setCount", {
439
+ get() {
440
+ return setCount;
441
+ }
442
+ });
443
+ mock.reset = function(value) {
444
+ const resetVal = value !== void 0 ? value : initialValue;
445
+ history.length = 0;
446
+ history.push(resetVal);
447
+ setCount = 0;
448
+ origFn(resetVal);
449
+ };
450
+ return mock;
451
+ }
452
+ function queryByText(container2, text) {
453
+ const regex = text instanceof RegExp ? text : null;
454
+ const walker = document.createTreeWalker(container2, NodeFilter.SHOW_TEXT, null);
455
+ while (walker.nextNode()) {
456
+ const node = walker.currentNode;
457
+ const content = node.textContent || "";
458
+ const matches = regex ? regex.test(content) : content.includes(text);
459
+ if (matches) {
460
+ return node.parentElement;
461
+ }
462
+ }
463
+ return null;
464
+ }
465
+ function queryAllByText(container2, text) {
466
+ const results = [];
467
+ const regex = text instanceof RegExp ? text : null;
468
+ const walker = document.createTreeWalker(container2, NodeFilter.SHOW_TEXT, null);
469
+ while (walker.nextNode()) {
470
+ const node = walker.currentNode;
471
+ const content = node.textContent || "";
472
+ const matches = regex ? regex.test(content) : content.includes(text);
473
+ if (matches) {
474
+ results.push(node.parentElement);
475
+ }
476
+ }
477
+ return results;
478
+ }
479
+ var fireEvent = {
480
+ click(element) {
481
+ const event = new MouseEvent("click", {
482
+ bubbles: true,
483
+ cancelable: true,
484
+ view: typeof window !== "undefined" ? window : void 0
485
+ });
486
+ element.dispatchEvent(event);
487
+ return event;
488
+ },
489
+ change(element, value) {
490
+ element.value = value;
491
+ const event = new Event("input", { bubbles: true });
492
+ element.dispatchEvent(event);
493
+ const changeEvent = new Event("change", { bubbles: true });
494
+ element.dispatchEvent(changeEvent);
495
+ return changeEvent;
496
+ },
497
+ input(element, value) {
498
+ element.value = value;
499
+ const event = new Event("input", { bubbles: true });
500
+ element.dispatchEvent(event);
501
+ return event;
502
+ },
503
+ submit(element) {
504
+ const event = new Event("submit", { bubbles: true, cancelable: true });
505
+ element.dispatchEvent(event);
506
+ return event;
507
+ },
508
+ focus(element) {
509
+ element.focus();
510
+ const event = new FocusEvent("focus", { bubbles: true });
511
+ element.dispatchEvent(event);
512
+ return event;
513
+ },
514
+ blur(element) {
515
+ element.blur();
516
+ const event = new FocusEvent("blur", { bubbles: true });
517
+ element.dispatchEvent(event);
518
+ return event;
519
+ },
520
+ keyDown(element, key, options = {}) {
521
+ const event = new KeyboardEvent("keydown", {
522
+ bubbles: true,
523
+ cancelable: true,
524
+ key,
525
+ ...options
526
+ });
527
+ element.dispatchEvent(event);
528
+ return event;
529
+ },
530
+ keyUp(element, key, options = {}) {
531
+ const event = new KeyboardEvent("keyup", {
532
+ bubbles: true,
533
+ cancelable: true,
534
+ key,
535
+ ...options
536
+ });
537
+ element.dispatchEvent(event);
538
+ return event;
539
+ },
540
+ mouseEnter(element) {
541
+ const event = new MouseEvent("mouseenter", { bubbles: true });
542
+ element.dispatchEvent(event);
543
+ return event;
544
+ },
545
+ mouseLeave(element) {
546
+ const event = new MouseEvent("mouseleave", { bubbles: true });
547
+ element.dispatchEvent(event);
548
+ return event;
549
+ }
550
+ };
551
+ async function waitFor(callback, options = {}) {
552
+ const { timeout = 1e3, interval = 50 } = options;
553
+ const startTime = Date.now();
554
+ while (Date.now() - startTime < timeout) {
555
+ try {
556
+ const result = callback();
557
+ if (result) return result;
558
+ } catch {
559
+ }
560
+ await new Promise((r) => setTimeout(r, interval));
561
+ }
562
+ throw new Error(`waitFor timed out after ${timeout}ms`);
563
+ }
564
+ async function waitForElementToBeRemoved(callback, options = {}) {
565
+ const { timeout = 1e3, interval = 50 } = options;
566
+ const startTime = Date.now();
567
+ let element = callback();
568
+ if (!element) {
569
+ throw new Error("Element not found");
570
+ }
571
+ while (Date.now() - startTime < timeout) {
572
+ element = callback();
573
+ if (!element) return;
574
+ await new Promise((r) => setTimeout(r, interval));
575
+ }
576
+ throw new Error(`Element still present after ${timeout}ms`);
577
+ }
578
+ async function act(callback) {
579
+ const result = await callback();
580
+ flushSync();
581
+ await /** @type {Promise<void>} */
582
+ new Promise((r) => queueMicrotask(() => r()));
583
+ await /** @type {Promise<void>} */
584
+ new Promise((r) => setTimeout(() => r(), 0));
585
+ await settled();
586
+ return result;
587
+ }
588
+ function createTestSignal(initial) {
589
+ const s = signal(initial);
590
+ const history = [initial];
591
+ effect(() => {
592
+ history.push(s());
593
+ });
594
+ return {
595
+ signal: s,
596
+ get value() {
597
+ return s();
598
+ },
599
+ set value(v) {
600
+ s.set(v);
601
+ },
602
+ history,
603
+ reset() {
604
+ history.length = 0;
605
+ history.push(s());
606
+ }
607
+ };
608
+ }
609
+ function mockComponent(name = "MockComponent") {
610
+ const calls = [];
611
+ function Mock(props) {
612
+ calls.push({ props, timestamp: Date.now() });
613
+ return h(
614
+ "div",
615
+ { "data-testid": `mock-${name}` },
616
+ JSON.stringify(props, null, 2)
617
+ );
618
+ }
619
+ Mock.displayName = name;
620
+ Mock.calls = calls;
621
+ Mock.lastCall = () => calls[calls.length - 1];
622
+ Mock.reset = () => {
623
+ calls.length = 0;
624
+ };
625
+ return Mock;
626
+ }
627
+ var expect = {
628
+ toBeInTheDocument(element) {
629
+ if (!element || !element.isConnected) {
630
+ throw new Error("Expected element to be in the document");
631
+ }
632
+ },
633
+ toHaveTextContent(element, text) {
634
+ if (!element) {
635
+ throw new Error("Element not found");
636
+ }
637
+ const content = element.textContent;
638
+ const matches = text instanceof RegExp ? text.test(content) : content.includes(text);
639
+ if (!matches) {
640
+ throw new Error(`Expected "${content}" to contain "${text}"`);
641
+ }
642
+ },
643
+ toHaveAttribute(element, attr, value) {
644
+ if (!element) {
645
+ throw new Error("Element not found");
646
+ }
647
+ const attrValue = element.getAttribute(attr);
648
+ if (value !== void 0 && attrValue !== value) {
649
+ throw new Error(`Expected attribute "${attr}" to be "${value}", got "${attrValue}"`);
650
+ }
651
+ if (value === void 0 && attrValue === null) {
652
+ throw new Error(`Expected element to have attribute "${attr}"`);
653
+ }
654
+ },
655
+ toHaveClass(element, className) {
656
+ if (!element) {
657
+ throw new Error("Element not found");
658
+ }
659
+ if (!element.classList.contains(className)) {
660
+ throw new Error(`Expected element to have class "${className}"`);
661
+ }
662
+ },
663
+ toBeVisible(element) {
664
+ if (!element) {
665
+ throw new Error("Element not found");
666
+ }
667
+ if (window.getComputedStyle(element).visibility === "hidden") throw new Error("Expected element to be visible");
668
+ for (let el = element; el && el.nodeType === 1; el = el.parentElement) {
669
+ const style = window.getComputedStyle(el);
670
+ if (style.display === "none" || style.opacity === "0") throw new Error("Expected element to be visible");
671
+ }
672
+ },
673
+ toBeDisabled(element) {
674
+ if (!element) {
675
+ throw new Error("Element not found");
676
+ }
677
+ if (!element.disabled && !element.matches(":disabled")) {
678
+ throw new Error("Expected element to be disabled");
679
+ }
680
+ },
681
+ toHaveValue(element, value) {
682
+ if (!element) {
683
+ throw new Error("Element not found");
684
+ }
685
+ if (element.value !== value) {
686
+ throw new Error(`Expected value to be "${value}", got "${element.value}"`);
687
+ }
688
+ }
689
+ };
690
+ var screen = {
691
+ getByText: (text) => queryByText(document.body, text),
692
+ getByTestId: (id) => document.querySelector(`[data-testid="${id}"]`),
693
+ getByRole: (role) => document.querySelector(`[role="${role}"]`),
694
+ getAllByText: (text) => queryAllByText(document.body, text),
695
+ queryByText: (text) => queryByText(document.body, text),
696
+ queryByTestId: (id) => document.querySelector(`[data-testid="${id}"]`),
697
+ debug: () => console.log(document.body.innerHTML)
698
+ };
699
+ export {
700
+ act,
701
+ captureDiagnostics,
702
+ cleanup,
703
+ createTestSignal,
704
+ expect,
705
+ expectDiagnostic,
706
+ expectNoDiagnostics,
707
+ expectRuns,
708
+ fireEvent,
709
+ flushEffects,
710
+ mockComponent,
711
+ mockSignal,
712
+ render,
713
+ renderTest,
714
+ screen,
715
+ settled,
716
+ setupDOM,
717
+ trackSignals,
718
+ waitFor,
719
+ waitForElementToBeRemoved
720
+ };