@vielzeug/assay 2.2.0 → 26.10.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/README.md +8 -21
- package/dist/assay.cjs +1 -1
- package/dist/assay.cjs.map +1 -1
- package/dist/assay.iife.js +1 -1
- package/dist/assay.iife.js.map +1 -1
- package/dist/assay.js +1 -1
- package/dist/assay.js.map +1 -1
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -9
- package/dist/errors.js.map +1 -1
- package/dist/events.cjs +1 -1
- package/dist/events.cjs.map +1 -1
- package/dist/events.d.ts +18 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -32
- package/dist/events.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/query.cjs +1 -1
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +1 -37
- package/dist/query.js.map +1 -1
- package/dist/wait.cjs +1 -1
- package/dist/wait.cjs.map +1 -1
- package/dist/wait.d.ts +16 -13
- package/dist/wait.d.ts.map +1 -1
- package/dist/wait.js +1 -66
- package/dist/wait.js.map +1 -1
- package/package.json +13 -9
- package/dist/live-region.cjs +0 -2
- package/dist/live-region.cjs.map +0 -1
- package/dist/live-region.d.ts +0 -66
- package/dist/live-region.d.ts.map +0 -1
- package/dist/live-region.js +0 -65
- package/dist/live-region.js.map +0 -1
package/dist/events.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.cjs","names":[],"sources":["../src/events.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"events.cjs","names":[],"sources":["../src/events.ts"],"sourcesContent":["/**\n * # Confidence boundary — read first\n *\n * `dispatch` is a **low-level synthetic-event dispatch API**. It fires a caller-\n * supplied DOM `Event` synchronously and returns the `dispatchEvent`\n * result. It does **not** model real user interaction: there is no focus/blur\n * sequencing, no input-event coordination, no keyboard layout, no pointer\n * hit-testing, and no trust flag (`event.isTrusted` is always `false`).\n *\n * Use it to drive event handlers in unit/integration tests where you control\n * the exact event shape. For **behavioral confidence** — that a real click\n * actually activates a control, that focus management works end-to-end, that\n * keyboard shortcuts fire under a real input device — write Playwright tests.\n * Assay deliberately stops at the dispatch boundary; anything that depends on\n * the browser's interaction semantics belongs in a browser-driven suite.\n */\n\n/** Dispatch a pre-built `Event` instance unchanged. Returns the `dispatchEvent` result. */\nexport const dispatch = (target: EventTarget, event: Event): boolean => target.dispatchEvent(event);\n\n/** Synthetic convenience dispatchers. They share the same confidence boundary as `dispatch()`. */\nexport const fireBlur = (target: EventTarget, init: FocusEventInit = {}): boolean =>\n dispatch(target, new FocusEvent('blur', init));\n\nexport const fireChange = (target: EventTarget, init: EventInit = {}): boolean =>\n dispatch(target, new Event('change', { bubbles: true, ...init }));\n\nexport const fireClick = (target: EventTarget, init: MouseEventInit = {}): boolean =>\n dispatch(target, new MouseEvent('click', { bubbles: true, cancelable: true, ...init }));\n\nexport const fireCustom = <T>(target: EventTarget, type: string, init: CustomEventInit<T> = {}): boolean =>\n dispatch(target, new CustomEvent(type, { bubbles: true, cancelable: true, composed: false, ...init }));\n\nexport const fireFocus = (target: EventTarget, init: FocusEventInit = {}): boolean =>\n dispatch(target, new FocusEvent('focus', init));\n\nexport const fireInput = (target: EventTarget, init: InputEventInit = {}): boolean =>\n dispatch(target, new InputEvent('input', { bubbles: true, ...init }));\n\nexport const fireKeyDown = (target: EventTarget, init: KeyboardEventInit = {}): boolean =>\n dispatch(target, new KeyboardEvent('keydown', { bubbles: true, cancelable: true, ...init }));\n\nexport const fireKeyUp = (target: EventTarget, init: KeyboardEventInit = {}): boolean =>\n dispatch(target, new KeyboardEvent('keyup', { bubbles: true, cancelable: true, ...init }));\n\nexport const fireSubmit = (target: EventT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
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* # Confidence boundary — read first
|
|
3
|
+
*
|
|
4
|
+
* `dispatch` is a **low-level synthetic-event dispatch API**. It fires a caller-
|
|
5
|
+
* supplied DOM `Event` synchronously and returns the `dispatchEvent`
|
|
6
|
+
* result. It does **not** model real user interaction: there is no focus/blur
|
|
7
|
+
* sequencing, no input-event coordination, no keyboard layout, no pointer
|
|
8
|
+
* hit-testing, and no trust flag (`event.isTrusted` is always `false`).
|
|
9
|
+
*
|
|
10
|
+
* Use it to drive event handlers in unit/integration tests where you control
|
|
11
|
+
* the exact event shape. For **behavioral confidence** — that a real click
|
|
12
|
+
* actually activates a control, that focus management works end-to-end, that
|
|
13
|
+
* keyboard shortcuts fire under a real input device — write Playwright tests.
|
|
14
|
+
* Assay deliberately stops at the dispatch boundary; anything that depends on
|
|
15
|
+
* the browser's interaction semantics belongs in a browser-driven suite.
|
|
16
|
+
*/
|
|
17
|
+
/** Dispatch a pre-built `Event` instance unchanged. Returns the `dispatchEvent` result. */
|
|
3
18
|
export declare const dispatch: (target: EventTarget, event: Event) => boolean;
|
|
19
|
+
/** Synthetic convenience dispatchers. They share the same confidence boundary as `dispatch()`. */
|
|
4
20
|
export declare const fireBlur: (target: EventTarget, init?: FocusEventInit) => boolean;
|
|
5
21
|
export declare const fireChange: (target: EventTarget, init?: EventInit) => boolean;
|
|
6
22
|
export declare const fireClick: (target: EventTarget, init?: MouseEventInit) => boolean;
|
package/dist/events.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,2FAA2F;AAC3F,eAAO,MAAM,QAAQ,GAAI,QAAQ,WAAW,EAAE,OAAO,KAAK,KAAG,OAAsC,CAAC;AAEpG,kGAAkG;AAClG,eAAO,MAAM,QAAQ,GAAI,QAAQ,WAAW,EAAE,OAAM,cAAmB,KAAG,OAC1B,CAAC;AAEjD,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,EAAE,OAAM,SAAc,KAAG,OACJ,CAAC;AAEpE,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,EAAE,OAAM,cAAmB,KAAG,OACc,CAAC;AAE1F,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,QAAQ,WAAW,EAAE,MAAM,MAAM,EAAE,OAAM,eAAe,CAAC,CAAC,CAAM,KAAG,OACO,CAAC;AAEzG,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,EAAE,OAAM,cAAmB,KAAG,OAC1B,CAAC;AAElD,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,EAAE,OAAM,cAAmB,KAAG,OACJ,CAAC;AAExE,eAAO,MAAM,WAAW,GAAI,QAAQ,WAAW,EAAE,OAAM,iBAAsB,KAAG,OACc,CAAC;AAE/F,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,EAAE,OAAM,iBAAsB,KAAG,OACc,CAAC;AAE7F,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,EAAE,OAAM,eAAoB,KAAG,OACc,CAAC"}
|
package/dist/events.js
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var e = (e, t) => e.dispatchEvent(t), t = (t, n = {}) => e(t, new FocusEvent("blur", n)), n = (t, n = {}) => e(t, new Event("change", {
|
|
3
|
-
bubbles: !0,
|
|
4
|
-
...n
|
|
5
|
-
})), r = (t, n = {}) => e(t, new MouseEvent("click", {
|
|
6
|
-
bubbles: !0,
|
|
7
|
-
cancelable: !0,
|
|
8
|
-
...n
|
|
9
|
-
})), i = (t, n, r = {}) => e(t, new CustomEvent(n, {
|
|
10
|
-
bubbles: !0,
|
|
11
|
-
cancelable: !0,
|
|
12
|
-
composed: !1,
|
|
13
|
-
...r
|
|
14
|
-
})), a = (t, n = {}) => e(t, new FocusEvent("focus", n)), o = (t, n = {}) => e(t, new InputEvent("input", {
|
|
15
|
-
bubbles: !0,
|
|
16
|
-
...n
|
|
17
|
-
})), s = (t, n = {}) => e(t, new KeyboardEvent("keydown", {
|
|
18
|
-
bubbles: !0,
|
|
19
|
-
cancelable: !0,
|
|
20
|
-
...n
|
|
21
|
-
})), c = (t, n = {}) => e(t, new KeyboardEvent("keyup", {
|
|
22
|
-
bubbles: !0,
|
|
23
|
-
cancelable: !0,
|
|
24
|
-
...n
|
|
25
|
-
})), l = (t, n = {}) => e(t, new SubmitEvent("submit", {
|
|
26
|
-
bubbles: !0,
|
|
27
|
-
cancelable: !0,
|
|
28
|
-
...n
|
|
29
|
-
}));
|
|
30
|
-
//#endregion
|
|
31
|
-
export { e as dispatch, t as fireBlur, n as fireChange, r as fireClick, i as fireCustom, a as fireFocus, o as fireInput, s as fireKeyDown, c as fireKeyUp, l as fireSubmit };
|
|
32
|
-
|
|
1
|
+
var dispatch=(e,t)=>e.dispatchEvent(t),fireBlur=(e,t={})=>dispatch(e,new FocusEvent(`blur`,t)),fireChange=(e,t={})=>dispatch(e,new Event(`change`,{bubbles:!0,...t})),fireClick=(e,t={})=>dispatch(e,new MouseEvent(`click`,{bubbles:!0,cancelable:!0,...t})),fireCustom=(e,t,n={})=>dispatch(e,new CustomEvent(t,{bubbles:!0,cancelable:!0,composed:!1,...n})),fireFocus=(e,t={})=>dispatch(e,new FocusEvent(`focus`,t)),fireInput=(e,t={})=>dispatch(e,new InputEvent(`input`,{bubbles:!0,...t})),fireKeyDown=(e,t={})=>dispatch(e,new KeyboardEvent(`keydown`,{bubbles:!0,cancelable:!0,...t})),fireKeyUp=(e,t={})=>dispatch(e,new KeyboardEvent(`keyup`,{bubbles:!0,cancelable:!0,...t})),fireSubmit=(e,t={})=>dispatch(e,new SubmitEvent(`submit`,{bubbles:!0,cancelable:!0,...t}));export{dispatch,fireBlur,fireChange,fireClick,fireCustom,fireFocus,fireInput,fireKeyDown,fireKeyUp,fireSubmit};
|
|
33
2
|
//# sourceMappingURL=events.js.map
|
package/dist/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","names":[],"sources":["../src/events.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"events.js","names":[],"sources":["../src/events.ts"],"sourcesContent":["/**\n * # Confidence boundary — read first\n *\n * `dispatch` is a **low-level synthetic-event dispatch API**. It fires a caller-\n * supplied DOM `Event` synchronously and returns the `dispatchEvent`\n * result. It does **not** model real user interaction: there is no focus/blur\n * sequencing, no input-event coordination, no keyboard layout, no pointer\n * hit-testing, and no trust flag (`event.isTrusted` is always `false`).\n *\n * Use it to drive event handlers in unit/integration tests where you control\n * the exact event shape. For **behavioral confidence** — that a real click\n * actually activates a control, that focus management works end-to-end, that\n * keyboard shortcuts fire under a real input device — write Playwright tests.\n * Assay deliberately stops at the dispatch boundary; anything that depends on\n * the browser's interaction semantics belongs in a browser-driven suite.\n */\n\n/** Dispatch a pre-built `Event` instance unchanged. Returns the `dispatchEvent` result. */\nexport const dispatch = (target: EventTarget, event: Event): boolean => target.dispatchEvent(event);\n\n/** Synthetic convenience dispatchers. They share the same confidence boundary as `dispatch()`. */\nexport const fireBlur = (target: EventTarget, init: FocusEventInit = {}): boolean =>\n dispatch(target, new FocusEvent('blur', init));\n\nexport const fireChange = (target: EventTarget, init: EventInit = {}): boolean =>\n dispatch(target, new Event('change', { bubbles: true, ...init }));\n\nexport const fireClick = (target: EventTarget, init: MouseEventInit = {}): boolean =>\n dispatch(target, new MouseEvent('click', { bubbles: true, cancelable: true, ...init }));\n\nexport const fireCustom = <T>(target: EventTarget, type: string, init: CustomEventInit<T> = {}): boolean =>\n dispatch(target, new CustomEvent(type, { bubbles: true, cancelable: true, composed: false, ...init }));\n\nexport const fireFocus = (target: EventTarget, init: FocusEventInit = {}): boolean =>\n dispatch(target, new FocusEvent('focus', init));\n\nexport const fireInput = (target: EventTarget, init: InputEventInit = {}): boolean =>\n dispatch(target, new InputEvent('input', { bubbles: true, ...init }));\n\nexport const fireKeyDown = (target: EventTarget, init: KeyboardEventInit = {}): boolean =>\n dispatch(target, new KeyboardEvent('keydown', { bubbles: true, cancelable: true, ...init }));\n\nexport const fireKeyUp = (target: EventTarget, init: KeyboardEventInit = {}): boolean =>\n dispatch(target, new KeyboardEvent('keyup', { bubbles: true, cancelable: true, ...init }));\n\nexport const fireSubmit = (target: EventTarget, init: SubmitEventInit = {}): boolean =>\n dispatch(target, new SubmitEvent('submit', { bubbles: true, cancelable: true, ...init }));\n"],"mappings":"AAkBA,IAAa,UAAY,EAAqB,IAA0B,EAAO,cAAc,CAAK,EAGrF,UAAY,EAAqB,EAAuB,CAAC,IACpE,SAAS,EAAQ,IAAI,WAAW,OAAQ,CAAI,CAAC,EAElC,YAAc,EAAqB,EAAkB,CAAC,IACjE,SAAS,EAAQ,IAAI,MAAM,SAAU,CAAE,QAAS,GAAM,GAAG,CAAK,CAAC,CAAC,EAErD,WAAa,EAAqB,EAAuB,CAAC,IACrE,SAAS,EAAQ,IAAI,WAAW,QAAS,CAAE,QAAS,GAAM,WAAY,GAAM,GAAG,CAAK,CAAC,CAAC,EAE3E,YAAiB,EAAqB,EAAc,EAA2B,CAAC,IAC3F,SAAS,EAAQ,IAAI,YAAY,EAAM,CAAE,QAAS,GAAM,WAAY,GAAM,SAAU,GAAO,GAAG,CAAK,CAAC,CAAC,EAE1F,WAAa,EAAqB,EAAuB,CAAC,IACrE,SAAS,EAAQ,IAAI,WAAW,QAAS,CAAI,CAAC,EAEnC,WAAa,EAAqB,EAAuB,CAAC,IACrE,SAAS,EAAQ,IAAI,WAAW,QAAS,CAAE,QAAS,GAAM,GAAG,CAAK,CAAC,CAAC,EAEzD,aAAe,EAAqB,EAA0B,CAAC,IAC1E,SAAS,EAAQ,IAAI,cAAc,UAAW,CAAE,QAAS,GAAM,WAAY,GAAM,GAAG,CAAK,CAAC,CAAC,EAEhF,WAAa,EAAqB,EAA0B,CAAC,IACxE,SAAS,EAAQ,IAAI,cAAc,QAAS,CAAE,QAAS,GAAM,WAAY,GAAM,GAAG,CAAK,CAAC,CAAC,EAE9E,YAAc,EAAqB,EAAwB,CAAC,IACvE,SAAS,EAAQ,IAAI,YAAY,SAAU,CAAE,QAAS,GAAM,WAAY,GAAM,GAAG,CAAK,CAAC,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./events.cjs"),n=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./errors.cjs"),t=require("./events.cjs"),n=require("./query.cjs"),r=require("./wait.cjs");exports.AssayError=e.AssayError,exports.AssayQueryError=e.AssayQueryError,exports.AssayTimeoutError=e.AssayTimeoutError,exports.delay=r.delay,exports.dispatch=t.dispatch,exports.eventually=r.eventually,exports.fireBlur=t.fireBlur,exports.fireChange=t.fireChange,exports.fireClick=t.fireClick,exports.fireCustom=t.fireCustom,exports.fireFocus=t.fireFocus,exports.fireInput=t.fireInput,exports.fireKeyDown=t.fireKeyDown,exports.fireKeyUp=t.fireKeyUp,exports.fireSubmit=t.fireSubmit,exports.getSlotted=n.getSlotted,exports.queryAllInShadow=n.queryAllInShadow,exports.queryInShadow=n.queryInShadow,exports.queryPart=n.queryPart,exports.waitForEvent=r.waitForEvent,exports.waitUntil=r.waitUntil,exports.within=n.within;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { AssayError, AssayQueryError, AssayTimeoutError } from './errors';
|
|
2
2
|
export { dispatch, fireBlur, fireChange, fireClick, fireCustom, fireFocus, fireInput, fireKeyDown, fireKeyUp, fireSubmit, } from './events';
|
|
3
|
-
export { type LiveRegionPoliteness, type LiveRegionQueryOptions, queryAllLiveRegions, queryLiveRegion, type WaitForLiveRegionOptions, waitForLiveRegion, waitForLiveRegionCleared, } from './live-region';
|
|
4
3
|
export { getSlotted, type QueryScope, queryAllInShadow, queryInShadow, queryPart, within } from './query';
|
|
5
|
-
export { type DelayOptions, delay,
|
|
4
|
+
export { type DelayOptions, delay, type EventuallyOptions, eventually, type WaitOptions, waitForEvent, waitUntil, } from './wait';
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE1E,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE1E,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC1G,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,EACL,KAAK,iBAAiB,EACtB,UAAU,EACV,KAAK,WAAW,EAChB,YAAY,EACZ,SAAS,GACV,MAAM,QAAQ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { dispatch as r, fireBlur as i, fireChange as a, fireClick as o, fireCustom as s, fireFocus as c, fireInput as l, fireKeyDown as u, fireKeyUp as d, fireSubmit as f } from "./events.js";
|
|
3
|
-
import { delay as p, nextTick as m, retry as h, waitForEvent as g, waitUntil as _ } from "./wait.js";
|
|
4
|
-
import { queryAllLiveRegions as v, queryLiveRegion as y, waitForLiveRegion as b, waitForLiveRegionCleared as x } from "./live-region.js";
|
|
5
|
-
import { getSlotted as S, queryAllInShadow as C, queryInShadow as w, queryPart as T, within as E } from "./query.js";
|
|
6
|
-
export { e as AssayError, t as AssayQueryError, n as AssayTimeoutError, p as delay, r as dispatch, i as fireBlur, a as fireChange, o as fireClick, s as fireCustom, c as fireFocus, l as fireInput, u as fireKeyDown, d as fireKeyUp, f as fireSubmit, S as getSlotted, m as nextTick, C as queryAllInShadow, v as queryAllLiveRegions, w as queryInShadow, y as queryLiveRegion, T as queryPart, h as retry, g as waitForEvent, b as waitForLiveRegion, x as waitForLiveRegionCleared, _ as waitUntil, E as within };
|
|
1
|
+
import{AssayError as e,AssayQueryError as t,AssayTimeoutError as n}from"./errors.js";import{dispatch as r,fireBlur as i,fireChange as a,fireClick as o,fireCustom as s,fireFocus as c,fireInput as l,fireKeyDown as u,fireKeyUp as d,fireSubmit as f}from"./events.js";import{getSlotted as p,queryAllInShadow as m,queryInShadow as h,queryPart as g,within as _}from"./query.js";import{delay as v,eventually as y,waitForEvent as b,waitUntil as x}from"./wait.js";export{e as AssayError,t as AssayQueryError,n as AssayTimeoutError,v as delay,r as dispatch,y as eventually,i as fireBlur,a as fireChange,o as fireClick,s as fireCustom,c as fireFocus,l as fireInput,u as fireKeyDown,d as fireKeyUp,f as fireSubmit,p as getSlotted,m as queryAllInShadow,h as queryInShadow,g as queryPart,b as waitForEvent,x as waitUntil,_ as within};
|
package/dist/query.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs");var
|
|
1
|
+
const e=require("./errors.cjs");var describeRoot=e=>e instanceof Element?e.outerHTML.slice(0,500):e instanceof ShadowRoot?`<shadow-root>${e.innerHTML.slice(0,500)}</shadow-root>`:e.nodeName,requireMatch=(t,n,r)=>{if(t)return t;throw new e.AssayQueryError(`Unable to find ${n} within ${describeRoot(r)}.`)},query=(e,t)=>e.querySelector(t),queryAll=(e,t)=>Array.from(e.querySelectorAll(t)),queryByTestId=(e,t)=>queryAll(e,`[data-testid]`).find(e=>e.getAttribute(`data-testid`)===t)??null,queryAllByTestId=(e,t)=>queryAll(e,`[data-testid]`).filter(e=>e.getAttribute(`data-testid`)===t),queryByText=(e,t,n=`*`)=>{for(let r of e.querySelectorAll(n))if(r.textContent?.trim()===t)return r;return null},queryAllByText=(e,t,n=`*`)=>queryAll(e,n).filter(e=>e.textContent?.trim()===t);function queryInShadow(e,t){return e.shadowRoot?query(e.shadowRoot,t):null}function queryAllInShadow(e,t){return e.shadowRoot?queryAll(e.shadowRoot,t):[]}function queryPart(e,t){return queryAllInShadow(e,`[part]`).find(e=>e.getAttribute(`part`)?.split(/\s+/).includes(t))??null}function getSlotted(e,t){return Array.from(e.children).filter(e=>t===void 0?!e.getAttribute(`slot`):e.getAttribute(`slot`)===t)}function within(e){return{get:t=>requireMatch(query(e,t),`"${t}"`,e),getByTestId:t=>requireMatch(queryByTestId(e,t),`data-testid "${t}"`,e),getByText:(t,n=`*`)=>requireMatch(queryByText(e,t,n),`text "${t}" matching "${n}"`,e),query:t=>query(e,t),queryAll:t=>queryAll(e,t),queryAllByTestId:t=>queryAllByTestId(e,t),queryAllByText:(t,n=`*`)=>queryAllByText(e,t,n),queryByTestId:t=>queryByTestId(e,t),queryByText:(t,n=`*`)=>queryByText(e,t,n)}}exports.getSlotted=getSlotted,exports.queryAllInShadow=queryAllInShadow,exports.queryInShadow=queryInShadow,exports.queryPart=queryPart,exports.within=within;
|
|
2
2
|
//# sourceMappingURL=query.cjs.map
|
package/dist/query.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.cjs","names":[],"sources":["../src/query.ts"],"sourcesContent":["import { AssayQueryError } from './errors';\n\n/** DOM query helpers for test environments. */\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Scoped query helpers for any queryable DOM root — see {@link within}. */\nexport interface QueryScope {\n get<E extends Element = Element>(selector: string): E;\n getByTestId<E extends Element = Element>(testId: string): E;\n getByText<E extends Element = Element>(text: string, selector?: string): E;\n query<E extends Element = Element>(selector: string): E | null;\n queryAll<E extends Element = Element>(selector: string): E[];\n queryAllByTestId<E extends Element = Element>(testId: string): E[];\n queryAllByText<E extends Element = Element>(text: string, selector?: string): E[];\n queryByTestId<E extends Element = Element>(testId: string): E | null;\n queryByText<E extends Element = Element>(text: string, selector?: string): E | null;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\ntype QueryRoot = ParentNode;\n\nconst describeRoot = (root: QueryRoot): string => {\n if (root instanceof Element) return root.outerHTML.slice(0, 500);\n\n if (root instanceof ShadowRoot) return `<shadow-root>${root.innerHTML.slice(0, 500)}</shadow-root>`;\n\n return root.nodeName;\n};\n\nconst requireMatch = <E extends Element>(element: E | null, description: string, root: QueryRoot): E => {\n if (element) return element;\n\n throw new AssayQueryError(`Unable to find ${description} within ${describeRoot(root)}.`);\n};\n\nconst query = <E extends Element = Element>(root: QueryRoot, selector: string): E | null =>\n root.querySelector<E>(selector);\n\nconst queryAll = <E extends Element = Element>(root: QueryRoot, selector: string): E[] => {\n return Array.from(root.querySelectorAll<E>(selector));\n};\n\nconst queryByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E | null =>\n queryAll<E>(root, '[data-testid]').find((element) => element.getAttribute('data-testid') === testId) ?? null;\n\nconst queryAllByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E[] =>\n queryAll<E>(root, '[data-testid]').filter((element) => element.getAttribute('data-testid') === testId);\n\nconst queryByText = <E extends Element = Element>(root: QueryRoot, text: string, selector = '*'): E | null => {\n for (const
|
|
1
|
+
{"version":3,"file":"query.cjs","names":[],"sources":["../src/query.ts"],"sourcesContent":["import { AssayQueryError } from './errors';\n\n/** DOM query helpers for test environments. */\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Scoped query helpers for any queryable DOM root — see {@link within}. */\nexport interface QueryScope {\n get<E extends Element = Element>(selector: string): E;\n getByTestId<E extends Element = Element>(testId: string): E;\n getByText<E extends Element = Element>(text: string, selector?: string): E;\n query<E extends Element = Element>(selector: string): E | null;\n queryAll<E extends Element = Element>(selector: string): E[];\n queryAllByTestId<E extends Element = Element>(testId: string): E[];\n queryAllByText<E extends Element = Element>(text: string, selector?: string): E[];\n queryByTestId<E extends Element = Element>(testId: string): E | null;\n queryByText<E extends Element = Element>(text: string, selector?: string): E | null;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\ntype QueryRoot = ParentNode;\n\nconst describeRoot = (root: QueryRoot): string => {\n if (root instanceof Element) return root.outerHTML.slice(0, 500);\n\n if (root instanceof ShadowRoot) return `<shadow-root>${root.innerHTML.slice(0, 500)}</shadow-root>`;\n\n return root.nodeName;\n};\n\nconst requireMatch = <E extends Element>(element: E | null, description: string, root: QueryRoot): E => {\n if (element) return element;\n\n throw new AssayQueryError(`Unable to find ${description} within ${describeRoot(root)}.`);\n};\n\nconst query = <E extends Element = Element>(root: QueryRoot, selector: string): E | null =>\n root.querySelector<E>(selector);\n\nconst queryAll = <E extends Element = Element>(root: QueryRoot, selector: string): E[] => {\n return Array.from(root.querySelectorAll<E>(selector));\n};\n\nconst queryByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E | null =>\n queryAll<E>(root, '[data-testid]').find((element) => element.getAttribute('data-testid') === testId) ?? null;\n\nconst queryAllByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E[] =>\n queryAll<E>(root, '[data-testid]').filter((element) => element.getAttribute('data-testid') === testId);\n\nconst queryByText = <E extends Element = Element>(root: QueryRoot, text: string, selector = '*'): E | null => {\n for (const element of root.querySelectorAll<E>(selector)) {\n if (element.textContent?.trim() === text) return element;\n }\n\n return null;\n};\n\nconst queryAllByText = <E extends Element = Element>(root: QueryRoot, text: string, selector = '*'): E[] =>\n queryAll<E>(root, selector).filter((element) => element.textContent?.trim() === text);\n\n/**\n * Queries the shadow root of a custom element for a matching CSS selector.\n * Returns `null` if the element has no shadow root or no match is found — safe to call on\n * both open-shadow custom elements and plain elements without checking `shadowRoot` first.\n */\nexport function queryInShadow<E extends Element = Element>(host: Element, selector: string): E | null {\n return host.shadowRoot ? query<E>(host.shadowRoot, selector) : null;\n}\n\n/** Queries all matching elements inside the shadow root of a custom element. */\nexport function queryAllInShadow<E extends Element = Element>(host: Element, selector: string): E[] {\n return host.shadowRoot ? queryAll<E>(host.shadowRoot, selector) : [];\n}\n\n/**\n * Queries a shadow DOM element by its CSS `part` attribute — shorthand for\n * `queryInShadow(host, '[part=\"name\"]')`.\n *\n * @example\n * const btn = queryPart(carousel, 'prev-btn');\n * expect(btn).not.toBeNull();\n */\nexport function queryPart<E extends Element = Element>(host: Element, part: string): E | null {\n return (\n queryAllInShadow<E>(host, '[part]').find((element) => element.getAttribute('part')?.split(/\\s+/).includes(part)) ??\n null\n );\n}\n\n/**\n * Returns the light-DOM children assigned to a named slot, or every child assigned to the\n * default slot when no name is given.\n *\n * @example\n * const slides = getSlotted(carousel);\n * expect(slides).toHaveLength(3);\n */\nexport function getSlotted<E extends Element = Element>(host: Element, slotName?: string): E[] {\n return Array.from(host.children).filter((element) =>\n slotName === undefined ? !element.getAttribute('slot') : element.getAttribute('slot') === slotName,\n ) as E[];\n}\n\n// ─── API ─────────────────────────────────────────────────────────────────────\n\n/**\n * Create query helpers scoped to a DOM root — useful for light DOM and shadow roots.\n *\n * @example\n * const view = within(fixture.shadow!);\n * expect(view.get('.title').textContent).toBe('Hello');\n */\nexport function within(root: QueryRoot): QueryScope {\n return {\n get: <E extends Element = Element>(selector: string) =>\n requireMatch(query<E>(root, selector), `\"${selector}\"`, root),\n getByTestId: <E extends Element = Element>(testId: string) =>\n requireMatch(queryByTestId<E>(root, testId), `data-testid \"${testId}\"`, root),\n getByText: <E extends Element = Element>(text: string, selector = '*') =>\n requireMatch(queryByText<E>(root, text, selector), `text \"${text}\" matching \"${selector}\"`, root),\n query: <E extends Element = Element>(selector: string) => query<E>(root, selector),\n queryAll: <E extends Element = Element>(selector: string) => queryAll<E>(root, selector),\n queryAllByTestId: <E extends Element = Element>(testId: string) => queryAllByTestId<E>(root, testId),\n queryAllByText: <E extends Element = Element>(text: string, selector = '*') =>\n queryAllByText<E>(root, text, selector),\n queryByTestId: <E extends Element = Element>(testId: string) => queryByTestId<E>(root, testId),\n queryByText: <E extends Element = Element>(text: string, selector = '*') => queryByText<E>(root, text, selector),\n };\n}\n"],"mappings":"gCAuBA,IAAM,aAAgB,GAChB,aAAgB,QAAgB,EAAK,UAAU,MAAM,EAAG,GAAG,EAE3D,aAAgB,WAAmB,gBAAgB,EAAK,UAAU,MAAM,EAAG,GAAG,EAAE,gBAE7E,EAAK,SAGR,cAAmC,EAAmB,EAAqB,IAAuB,CACtG,GAAI,EAAS,OAAO,EAEpB,MAAM,IAAI,EAAA,gBAAgB,kBAAkB,EAAY,UAAU,aAAa,CAAI,EAAE,EAAE,CACzF,EAEM,OAAsC,EAAiB,IAC3D,EAAK,cAAiB,CAAQ,EAE1B,UAAyC,EAAiB,IACvD,MAAM,KAAK,EAAK,iBAAoB,CAAQ,CAAC,EAGhD,eAA8C,EAAiB,IACnE,SAAY,EAAM,eAAe,CAAC,CAAC,KAAM,GAAY,EAAQ,aAAa,aAAa,IAAM,CAAM,GAAK,KAEpG,kBAAiD,EAAiB,IACtE,SAAY,EAAM,eAAe,CAAC,CAAC,OAAQ,GAAY,EAAQ,aAAa,aAAa,IAAM,CAAM,EAEjG,aAA4C,EAAiB,EAAc,EAAW,MAAkB,CAC5G,IAAK,IAAM,KAAW,EAAK,iBAAoB,CAAQ,EACrD,GAAI,EAAQ,aAAa,KAAK,IAAM,EAAM,OAAO,EAGnD,OAAO,IACT,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E,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAEpG;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,EAAE,CAElG;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAK5F;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAI7F;AAID;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAgBlD"}
|
package/dist/query.js
CHANGED
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/query.ts
|
|
3
|
-
var t = (e) => e instanceof Element ? e.outerHTML.slice(0, 500) : e instanceof ShadowRoot ? `<shadow-root>${e.innerHTML.slice(0, 500)}</shadow-root>` : e.nodeName, n = (n, r, i) => {
|
|
4
|
-
if (n) return n;
|
|
5
|
-
throw new e(`Unable to find ${r} within ${t(i)}.`);
|
|
6
|
-
}, r = (e, t) => e.querySelector(t), i = (e, t) => Array.from(e.querySelectorAll(t)), a = (e, t) => i(e, "[data-testid]").find((e) => e.getAttribute("data-testid") === t) ?? null, o = (e, t) => i(e, "[data-testid]").filter((e) => e.getAttribute("data-testid") === t), s = (e, t, n = "*") => {
|
|
7
|
-
for (let r of e.querySelectorAll(n)) if (r.textContent?.trim() === t) return r;
|
|
8
|
-
return null;
|
|
9
|
-
}, c = (e, t, n = "*") => Array.from(e.querySelectorAll(n)).filter((e) => e.textContent?.trim() === t);
|
|
10
|
-
function l(e, t) {
|
|
11
|
-
return e.shadowRoot ? r(e.shadowRoot, t) : null;
|
|
12
|
-
}
|
|
13
|
-
function u(e, t) {
|
|
14
|
-
return e.shadowRoot ? i(e.shadowRoot, t) : [];
|
|
15
|
-
}
|
|
16
|
-
function d(e, t) {
|
|
17
|
-
return u(e, "[part]").find((e) => e.getAttribute("part")?.split(/\s+/).includes(t)) ?? null;
|
|
18
|
-
}
|
|
19
|
-
function f(e, t) {
|
|
20
|
-
return Array.from(e.children).filter((e) => t === void 0 ? !e.getAttribute("slot") : e.getAttribute("slot") === t);
|
|
21
|
-
}
|
|
22
|
-
function p(e) {
|
|
23
|
-
return {
|
|
24
|
-
get: (t) => n(r(e, t), `"${t}"`, e),
|
|
25
|
-
getByTestId: (t) => n(a(e, t), `data-testid "${t}"`, e),
|
|
26
|
-
getByText: (t, r = "*") => n(s(e, t, r), `text "${t}" matching "${r}"`, e),
|
|
27
|
-
query: (t) => r(e, t),
|
|
28
|
-
queryAll: (t) => i(e, t),
|
|
29
|
-
queryAllByTestId: (t) => o(e, t),
|
|
30
|
-
queryAllByText: (t, n = "*") => c(e, t, n),
|
|
31
|
-
queryByTestId: (t) => a(e, t),
|
|
32
|
-
queryByText: (t, n = "*") => s(e, t, n)
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
export { f as getSlotted, u as queryAllInShadow, l as queryInShadow, d as queryPart, p as within };
|
|
37
|
-
|
|
1
|
+
import{AssayQueryError as e}from"./errors.js";var describeRoot=e=>e instanceof Element?e.outerHTML.slice(0,500):e instanceof ShadowRoot?`<shadow-root>${e.innerHTML.slice(0,500)}</shadow-root>`:e.nodeName,requireMatch=(t,n,r)=>{if(t)return t;throw new e(`Unable to find ${n} within ${describeRoot(r)}.`)},query=(e,t)=>e.querySelector(t),queryAll=(e,t)=>Array.from(e.querySelectorAll(t)),queryByTestId=(e,t)=>queryAll(e,`[data-testid]`).find(e=>e.getAttribute(`data-testid`)===t)??null,queryAllByTestId=(e,t)=>queryAll(e,`[data-testid]`).filter(e=>e.getAttribute(`data-testid`)===t),queryByText=(e,t,n=`*`)=>{for(let r of e.querySelectorAll(n))if(r.textContent?.trim()===t)return r;return null},queryAllByText=(e,t,n=`*`)=>queryAll(e,n).filter(e=>e.textContent?.trim()===t);function queryInShadow(e,t){return e.shadowRoot?query(e.shadowRoot,t):null}function queryAllInShadow(e,t){return e.shadowRoot?queryAll(e.shadowRoot,t):[]}function queryPart(e,t){return queryAllInShadow(e,`[part]`).find(e=>e.getAttribute(`part`)?.split(/\s+/).includes(t))??null}function getSlotted(e,t){return Array.from(e.children).filter(e=>t===void 0?!e.getAttribute(`slot`):e.getAttribute(`slot`)===t)}function within(e){return{get:t=>requireMatch(query(e,t),`"${t}"`,e),getByTestId:t=>requireMatch(queryByTestId(e,t),`data-testid "${t}"`,e),getByText:(t,n=`*`)=>requireMatch(queryByText(e,t,n),`text "${t}" matching "${n}"`,e),query:t=>query(e,t),queryAll:t=>queryAll(e,t),queryAllByTestId:t=>queryAllByTestId(e,t),queryAllByText:(t,n=`*`)=>queryAllByText(e,t,n),queryByTestId:t=>queryByTestId(e,t),queryByText:(t,n=`*`)=>queryByText(e,t,n)}}export{getSlotted,queryAllInShadow,queryInShadow,queryPart,within};
|
|
38
2
|
//# sourceMappingURL=query.js.map
|
package/dist/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.js","names":[],"sources":["../src/query.ts"],"sourcesContent":["import { AssayQueryError } from './errors';\n\n/** DOM query helpers for test environments. */\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Scoped query helpers for any queryable DOM root — see {@link within}. */\nexport interface QueryScope {\n get<E extends Element = Element>(selector: string): E;\n getByTestId<E extends Element = Element>(testId: string): E;\n getByText<E extends Element = Element>(text: string, selector?: string): E;\n query<E extends Element = Element>(selector: string): E | null;\n queryAll<E extends Element = Element>(selector: string): E[];\n queryAllByTestId<E extends Element = Element>(testId: string): E[];\n queryAllByText<E extends Element = Element>(text: string, selector?: string): E[];\n queryByTestId<E extends Element = Element>(testId: string): E | null;\n queryByText<E extends Element = Element>(text: string, selector?: string): E | null;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\ntype QueryRoot = ParentNode;\n\nconst describeRoot = (root: QueryRoot): string => {\n if (root instanceof Element) return root.outerHTML.slice(0, 500);\n\n if (root instanceof ShadowRoot) return `<shadow-root>${root.innerHTML.slice(0, 500)}</shadow-root>`;\n\n return root.nodeName;\n};\n\nconst requireMatch = <E extends Element>(element: E | null, description: string, root: QueryRoot): E => {\n if (element) return element;\n\n throw new AssayQueryError(`Unable to find ${description} within ${describeRoot(root)}.`);\n};\n\nconst query = <E extends Element = Element>(root: QueryRoot, selector: string): E | null =>\n root.querySelector<E>(selector);\n\nconst queryAll = <E extends Element = Element>(root: QueryRoot, selector: string): E[] => {\n return Array.from(root.querySelectorAll<E>(selector));\n};\n\nconst queryByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E | null =>\n queryAll<E>(root, '[data-testid]').find((element) => element.getAttribute('data-testid') === testId) ?? null;\n\nconst queryAllByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E[] =>\n queryAll<E>(root, '[data-testid]').filter((element) => element.getAttribute('data-testid') === testId);\n\nconst queryByText = <E extends Element = Element>(root: QueryRoot, text: string, selector = '*'): E | null => {\n for (const
|
|
1
|
+
{"version":3,"file":"query.js","names":[],"sources":["../src/query.ts"],"sourcesContent":["import { AssayQueryError } from './errors';\n\n/** DOM query helpers for test environments. */\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Scoped query helpers for any queryable DOM root — see {@link within}. */\nexport interface QueryScope {\n get<E extends Element = Element>(selector: string): E;\n getByTestId<E extends Element = Element>(testId: string): E;\n getByText<E extends Element = Element>(text: string, selector?: string): E;\n query<E extends Element = Element>(selector: string): E | null;\n queryAll<E extends Element = Element>(selector: string): E[];\n queryAllByTestId<E extends Element = Element>(testId: string): E[];\n queryAllByText<E extends Element = Element>(text: string, selector?: string): E[];\n queryByTestId<E extends Element = Element>(testId: string): E | null;\n queryByText<E extends Element = Element>(text: string, selector?: string): E | null;\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\ntype QueryRoot = ParentNode;\n\nconst describeRoot = (root: QueryRoot): string => {\n if (root instanceof Element) return root.outerHTML.slice(0, 500);\n\n if (root instanceof ShadowRoot) return `<shadow-root>${root.innerHTML.slice(0, 500)}</shadow-root>`;\n\n return root.nodeName;\n};\n\nconst requireMatch = <E extends Element>(element: E | null, description: string, root: QueryRoot): E => {\n if (element) return element;\n\n throw new AssayQueryError(`Unable to find ${description} within ${describeRoot(root)}.`);\n};\n\nconst query = <E extends Element = Element>(root: QueryRoot, selector: string): E | null =>\n root.querySelector<E>(selector);\n\nconst queryAll = <E extends Element = Element>(root: QueryRoot, selector: string): E[] => {\n return Array.from(root.querySelectorAll<E>(selector));\n};\n\nconst queryByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E | null =>\n queryAll<E>(root, '[data-testid]').find((element) => element.getAttribute('data-testid') === testId) ?? null;\n\nconst queryAllByTestId = <E extends Element = Element>(root: QueryRoot, testId: string): E[] =>\n queryAll<E>(root, '[data-testid]').filter((element) => element.getAttribute('data-testid') === testId);\n\nconst queryByText = <E extends Element = Element>(root: QueryRoot, text: string, selector = '*'): E | null => {\n for (const element of root.querySelectorAll<E>(selector)) {\n if (element.textContent?.trim() === text) return element;\n }\n\n return null;\n};\n\nconst queryAllByText = <E extends Element = Element>(root: QueryRoot, text: string, selector = '*'): E[] =>\n queryAll<E>(root, selector).filter((element) => element.textContent?.trim() === text);\n\n/**\n * Queries the shadow root of a custom element for a matching CSS selector.\n * Returns `null` if the element has no shadow root or no match is found — safe to call on\n * both open-shadow custom elements and plain elements without checking `shadowRoot` first.\n */\nexport function queryInShadow<E extends Element = Element>(host: Element, selector: string): E | null {\n return host.shadowRoot ? query<E>(host.shadowRoot, selector) : null;\n}\n\n/** Queries all matching elements inside the shadow root of a custom element. */\nexport function queryAllInShadow<E extends Element = Element>(host: Element, selector: string): E[] {\n return host.shadowRoot ? queryAll<E>(host.shadowRoot, selector) : [];\n}\n\n/**\n * Queries a shadow DOM element by its CSS `part` attribute — shorthand for\n * `queryInShadow(host, '[part=\"name\"]')`.\n *\n * @example\n * const btn = queryPart(carousel, 'prev-btn');\n * expect(btn).not.toBeNull();\n */\nexport function queryPart<E extends Element = Element>(host: Element, part: string): E | null {\n return (\n queryAllInShadow<E>(host, '[part]').find((element) => element.getAttribute('part')?.split(/\\s+/).includes(part)) ??\n null\n );\n}\n\n/**\n * Returns the light-DOM children assigned to a named slot, or every child assigned to the\n * default slot when no name is given.\n *\n * @example\n * const slides = getSlotted(carousel);\n * expect(slides).toHaveLength(3);\n */\nexport function getSlotted<E extends Element = Element>(host: Element, slotName?: string): E[] {\n return Array.from(host.children).filter((element) =>\n slotName === undefined ? !element.getAttribute('slot') : element.getAttribute('slot') === slotName,\n ) as E[];\n}\n\n// ─── API ─────────────────────────────────────────────────────────────────────\n\n/**\n * Create query helpers scoped to a DOM root — useful for light DOM and shadow roots.\n *\n * @example\n * const view = within(fixture.shadow!);\n * expect(view.get('.title').textContent).toBe('Hello');\n */\nexport function within(root: QueryRoot): QueryScope {\n return {\n get: <E extends Element = Element>(selector: string) =>\n requireMatch(query<E>(root, selector), `\"${selector}\"`, root),\n getByTestId: <E extends Element = Element>(testId: string) =>\n requireMatch(queryByTestId<E>(root, testId), `data-testid \"${testId}\"`, root),\n getByText: <E extends Element = Element>(text: string, selector = '*') =>\n requireMatch(queryByText<E>(root, text, selector), `text \"${text}\" matching \"${selector}\"`, root),\n query: <E extends Element = Element>(selector: string) => query<E>(root, selector),\n queryAll: <E extends Element = Element>(selector: string) => queryAll<E>(root, selector),\n queryAllByTestId: <E extends Element = Element>(testId: string) => queryAllByTestId<E>(root, testId),\n queryAllByText: <E extends Element = Element>(text: string, selector = '*') =>\n queryAllByText<E>(root, text, selector),\n queryByTestId: <E extends Element = Element>(testId: string) => queryByTestId<E>(root, testId),\n queryByText: <E extends Element = Element>(text: string, selector = '*') => queryByText<E>(root, text, selector),\n };\n}\n"],"mappings":"8CAuBA,IAAM,aAAgB,GAChB,aAAgB,QAAgB,EAAK,UAAU,MAAM,EAAG,GAAG,EAE3D,aAAgB,WAAmB,gBAAgB,EAAK,UAAU,MAAM,EAAG,GAAG,EAAE,gBAE7E,EAAK,SAGR,cAAmC,EAAmB,EAAqB,IAAuB,CACtG,GAAI,EAAS,OAAO,EAEpB,MAAM,IAAI,EAAgB,kBAAkB,EAAY,UAAU,aAAa,CAAI,EAAE,EAAE,CACzF,EAEM,OAAsC,EAAiB,IAC3D,EAAK,cAAiB,CAAQ,EAE1B,UAAyC,EAAiB,IACvD,MAAM,KAAK,EAAK,iBAAoB,CAAQ,CAAC,EAGhD,eAA8C,EAAiB,IACnE,SAAY,EAAM,eAAe,CAAC,CAAC,KAAM,GAAY,EAAQ,aAAa,aAAa,IAAM,CAAM,GAAK,KAEpG,kBAAiD,EAAiB,IACtE,SAAY,EAAM,eAAe,CAAC,CAAC,OAAQ,GAAY,EAAQ,aAAa,aAAa,IAAM,CAAM,EAEjG,aAA4C,EAAiB,EAAc,EAAW,MAAkB,CAC5G,IAAK,IAAM,KAAW,EAAK,iBAAoB,CAAQ,EACrD,GAAI,EAAQ,aAAa,KAAK,IAAM,EAAM,OAAO,EAGnD,OAAO,IACT,EAEM,gBAA+C,EAAiB,EAAc,EAAW,MAC7F,SAAY,EAAM,CAAQ,CAAC,CAAC,OAAQ,GAAY,EAAQ,aAAa,KAAK,IAAM,CAAI,EAOtF,SAAgB,cAA2C,EAAe,EAA4B,CACpG,OAAO,EAAK,WAAa,MAAS,EAAK,WAAY,CAAQ,EAAI,IACjE,CAGA,SAAgB,iBAA8C,EAAe,EAAuB,CAClG,OAAO,EAAK,WAAa,SAAY,EAAK,WAAY,CAAQ,EAAI,CAAC,CACrE,CAUA,SAAgB,UAAuC,EAAe,EAAwB,CAC5F,OACE,iBAAoB,EAAM,QAAQ,CAAC,CAAC,KAAM,GAAY,EAAQ,aAAa,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC,SAAS,CAAI,CAAC,GAC/G,IAEJ,CAUA,SAAgB,WAAwC,EAAe,EAAwB,CAC7F,OAAO,MAAM,KAAK,EAAK,QAAQ,CAAC,CAAC,OAAQ,GACvC,IAAa,IAAA,GAAY,CAAC,EAAQ,aAAa,MAAM,EAAI,EAAQ,aAAa,MAAM,IAAM,CAC5F,CACF,CAWA,SAAgB,OAAO,EAA6B,CAClD,MAAO,CACL,IAAmC,GACjC,aAAa,MAAS,EAAM,CAAQ,EAAG,IAAI,EAAS,GAAI,CAAI,EAC9D,YAA2C,GACzC,aAAa,cAAiB,EAAM,CAAM,EAAG,gBAAgB,EAAO,GAAI,CAAI,EAC9E,WAAyC,EAAc,EAAW,MAChE,aAAa,YAAe,EAAM,EAAM,CAAQ,EAAG,SAAS,EAAK,cAAc,EAAS,GAAI,CAAI,EAClG,MAAqC,GAAqB,MAAS,EAAM,CAAQ,EACjF,SAAwC,GAAqB,SAAY,EAAM,CAAQ,EACvF,iBAAgD,GAAmB,iBAAoB,EAAM,CAAM,EACnG,gBAA8C,EAAc,EAAW,MACrE,eAAkB,EAAM,EAAM,CAAQ,EACxC,cAA6C,GAAmB,cAAiB,EAAM,CAAM,EAC7F,aAA2C,EAAc,EAAW,MAAQ,YAAe,EAAM,EAAM,CAAQ,CACjH,CACF"}
|
package/dist/wait.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs");
|
|
1
|
+
const e=require("./errors.cjs");let t=require("@vielzeug/arsenal");var n=Symbol(`assay.deadline`),r=2147483647,now=()=>performance.now(),validateDuration=(e,t,n)=>{if(!Number.isFinite(t)||t>r||(n?t<0:t<=0))throw RangeError(`${e} must be a ${n?`non-negative`:`positive`} finite number no greater than ${r}`)},validateWait=(e,t)=>{validateDuration(`interval`,e,!1),validateDuration(`timeout`,t,!0)},runBounded=(e,r,i)=>new Promise((a,o)=>{if(i?.aborted){o((0,t.abortError)(i,`The operation was aborted.`));return}let s=!1,cleanup=()=>!s&&(s=!0,clearTimeout(c),i?.removeEventListener(`abort`,abort),!0),resolveOnce=e=>{cleanup()&&a(e)},rejectOnce=e=>{cleanup()&&o(e)},c=setTimeout(()=>rejectOnce(n),Math.max(0,r-now())),abort=()=>rejectOnce((0,t.abortError)(i,`The operation was aborted.`));i?.addEventListener(`abort`,abort,{once:!0});try{Promise.resolve(e()).then(resolveOnce,rejectOnce)}catch(e){rejectOnce(e)}}),delay=(e=0,n={})=>(validateDuration(`ms`,e,!0),(0,t.sleep)(e,n.signal));async function waitUntil(r,{interval:i=50,signal:a,timeout:o=1e3}={}){validateWait(i,o);let s=now()+o,c=!0;for(;;){if(a?.aborted)throw(0,t.abortError)(a,`The operation was aborted.`);if(!c&&now()>=s)throw new e.AssayTimeoutError(`waitUntil timed out after ${o}ms`);c=!1;let l;try{l=await runBounded(r,s,a)}catch(t){throw t===n?new e.AssayTimeoutError(`waitUntil timed out after ${o}ms`):t}if(l)return;let u=s-now();if(u<=0)throw new e.AssayTimeoutError(`waitUntil timed out after ${o}ms`);await(0,t.sleep)(Math.min(i,u),a)}}async function eventually(r,{interval:i=50,message:a,signal:o,timeout:s=1e3}={}){validateWait(i,s);let c=now()+s,l=!0,u;for(;;){if(o?.aborted)throw(0,t.abortError)(o,`The operation was aborted.`);if(!l&&now()>=c)break;l=!1;try{await runBounded(r,c,o);return}catch(e){if(o?.aborted)throw(0,t.abortError)(o,`The operation was aborted.`);if(e===n)break;u=e}let e=c-now();if(e<=0)break;await(0,t.sleep)(Math.min(i,e),o)}let d=`eventually timed out after ${s}ms`,f=a?`${a} (${d})`:d,p=u instanceof Error?u.message:u==null?``:String(u);throw new e.AssayTimeoutError(p?`${f}\n${p}`:f,{cause:u})}function waitForEvent(n,r,{signal:i,timeout:a=1e3}={}){return validateDuration(`timeout`,a,!0),new Promise((o,s)=>{if(i?.aborted){s((0,t.abortError)(i,`The operation was aborted.`));return}let dispose=()=>{clearTimeout(c),i?.removeEventListener(`abort`,onAbort),n.removeEventListener(r,onEvent)},onEvent=e=>{dispose(),o(e)},c=setTimeout(()=>{dispose(),s(new e.AssayTimeoutError(`waitForEvent: "${r}" timed out after ${a}ms`))},a),onAbort=()=>{dispose(),s((0,t.abortError)(i,`The operation was aborted.`))};n.addEventListener(r,onEvent,{once:!0}),i?.addEventListener(`abort`,onAbort,{once:!0})})}exports.delay=delay,exports.eventually=eventually,exports.waitForEvent=waitForEvent,exports.waitUntil=waitUntil;
|
|
2
2
|
//# sourceMappingURL=wait.cjs.map
|
package/dist/wait.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait.cjs","names":[],"sources":["../src/wait.ts"],"sourcesContent":["import { AssayTimeoutError } from './errors';\n\nexport interface WaitOptions {\n /** Polling interval in ms (default: 50). */\n interval?: number;\n /** Cancel the pending wait. */\n signal?: AbortSignal;\n /** Maximum wait time in ms (default: 1000). */\n timeout?: number;\n}\n\nexport interface
|
|
1
|
+
{"version":3,"file":"wait.cjs","names":[],"sources":["../src/wait.ts"],"sourcesContent":["import { abortError, sleep } from '@vielzeug/arsenal';\n\nimport { AssayTimeoutError } from './errors';\n\nexport interface DelayOptions {\n signal?: AbortSignal;\n}\n\nexport interface WaitOptions {\n /** Polling interval in ms (default: 50). */\n interval?: number;\n /** Cancel the pending wait. */\n signal?: AbortSignal;\n /** Maximum wait time in ms (default: 1000). */\n timeout?: number;\n}\n\nexport interface EventuallyOptions extends WaitOptions {\n /** Context included in the timeout error. */\n message?: string;\n}\n\nconst DEADLINE = Symbol('assay.deadline');\nconst MAX_TIMER_MS = 2_147_483_647;\nconst now = (): number => performance.now();\n\nconst validateDuration = (name: string, value: number, allowZero: boolean): void => {\n if (!Number.isFinite(value) || value > MAX_TIMER_MS || (allowZero ? value < 0 : value <= 0)) {\n throw new RangeError(\n `${name} must be a ${allowZero ? 'non-negative' : 'positive'} finite number no greater than ${MAX_TIMER_MS}`,\n );\n }\n};\n\nconst validateWait = (interval: number, timeout: number): void => {\n validateDuration('interval', interval, false);\n validateDuration('timeout', timeout, true);\n};\n\nconst runBounded = <T>(run: () => T | Promise<T>, deadline: number, signal?: AbortSignal): Promise<T> =>\n new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(abortError(signal, 'The operation was aborted.'));\n return;\n }\n\n let settled = false;\n const cleanup = (): boolean => {\n if (settled) return false;\n settled = true;\n clearTimeout(timer);\n signal?.removeEventListener('abort', abort);\n return true;\n };\n const resolveOnce = (value: T): void => {\n if (cleanup()) resolve(value);\n };\n const rejectOnce = (error: unknown): void => {\n if (cleanup()) reject(error);\n };\n const timer = setTimeout(() => rejectOnce(DEADLINE), Math.max(0, deadline - now()));\n const abort = () => rejectOnce(abortError(signal, 'The operation was aborted.'));\n\n signal?.addEventListener('abort', abort, { once: true });\n\n try {\n Promise.resolve(run()).then(resolveOnce, rejectOnce);\n } catch (error) {\n rejectOnce(error);\n }\n });\n\nexport const delay = (ms = 0, options: DelayOptions = {}): Promise<void> => {\n validateDuration('ms', ms, true);\n return sleep(ms, options.signal);\n};\n\nexport async function waitUntil(\n predicate: () => boolean | Promise<boolean>,\n { interval = 50, signal, timeout = 1000 }: WaitOptions = {},\n): Promise<void> {\n validateWait(interval, timeout);\n const deadline = now() + timeout;\n let first = true;\n\n for (;;) {\n if (signal?.aborted) throw abortError(signal, 'The operation was aborted.');\n if (!first && now() >= deadline) throw new AssayTimeoutError(`waitUntil timed out after ${timeout}ms`);\n first = false;\n\n let matched: boolean;\n try {\n matched = await runBounded(predicate, deadline, signal);\n } catch (error) {\n if (error === DEADLINE) throw new AssayTimeoutError(`waitUntil timed out after ${timeout}ms`);\n throw error;\n }\n if (matched) return;\n\n const remaining = deadline - now();\n if (remaining <= 0) throw new AssayTimeoutError(`waitUntil timed out after ${timeout}ms`);\n await sleep(Math.min(interval, remaining), signal);\n }\n}\n\n/**\n * Retry an assertion until it stops throwing or the timeout elapses.\n *\n * Polls the assertion on a fixed interval and preserves the last failure as the\n * timeout cause. Pending asynchronous assertions remain bounded by the same\n * deadline. Use `waitUntil()` for boolean conditions, `delay()` for explicit\n * timer dependencies, and `nextTick()` for one queued microtask boundary.\n *\n * @example\n * await eventually(() => expect(region.textContent).toBe('Saved'));\n */\nexport async function eventually(\n assertion: () => void | Promise<void>,\n { interval = 50, message, signal, timeout = 1000 }: EventuallyOptions = {},\n): Promise<void> {\n validateWait(interval, timeout);\n const deadline = now() + timeout;\n let first = true;\n let lastError: unknown;\n\n for (;;) {\n if (signal?.aborted) throw abortError(signal, 'The operation was aborted.');\n if (!first && now() >= deadline) break;\n first = false;\n\n try {\n await runBounded(assertion, deadline, signal);\n return;\n } catch (error) {\n if (signal?.aborted) throw abortError(signal, 'The operation was aborted.');\n if (error === DEADLINE) break;\n lastError = error;\n }\n\n const remaining = deadline - now();\n if (remaining <= 0) break;\n await sleep(Math.min(interval, remaining), signal);\n }\n\n const timing = `eventually timed out after ${timeout}ms`;\n const context = message ? `${message} (${timing})` : timing;\n const detail = lastError instanceof Error ? lastError.message : lastError == null ? '' : String(lastError);\n\n throw new AssayTimeoutError(detail ? `${context}\\n${detail}` : context, { cause: lastError });\n}\n\n/** Resolve with the next event of `type`, or reject when it times out or is aborted. */\nexport function waitForEvent<T extends Event = Event>(\n target: EventTarget,\n type: string,\n { signal, timeout = 1000 }: Omit<WaitOptions, 'interval'> = {},\n): Promise<T> {\n validateDuration('timeout', timeout, true);\n\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(abortError(signal, 'The operation was aborted.'));\n return;\n }\n\n const dispose = () => {\n clearTimeout(timer);\n signal?.removeEventListener('abort', onAbort);\n target.removeEventListener(type, onEvent);\n };\n const onEvent = (event: Event): void => {\n dispose();\n resolve(event as T);\n };\n const timer = setTimeout(() => {\n dispose();\n reject(new AssayTimeoutError(`waitForEvent: \"${type}\" timed out after ${timeout}ms`));\n }, timeout);\n const onAbort = () => {\n dispose();\n reject(abortError(signal, 'The operation was aborted.'));\n };\n\n target.addEventListener(type, onEvent, { once: true });\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n"],"mappings":"mEAsBA,IAAM,EAAW,OAAO,gBAAgB,EAClC,EAAe,WACf,QAAoB,YAAY,IAAI,EAEpC,kBAAoB,EAAc,EAAe,IAA6B,CAClF,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,EAAQ,IAAiB,EAAY,EAAQ,EAAI,GAAS,GACvF,MAAU,WACR,GAAG,EAAK,aAAa,EAAY,eAAiB,WAAW,iCAAiC,GAChG,CAEJ,EAEM,cAAgB,EAAkB,IAA0B,CAChE,iBAAiB,WAAY,EAAU,EAAK,EAC5C,iBAAiB,UAAW,EAAS,EAAI,CAC3C,EAEM,YAAiB,EAA2B,EAAkB,IAClE,IAAI,SAAS,EAAS,IAAW,CAC/B,GAAI,GAAQ,QAAS,CACnB,GAAA,EAAO,EAAA,WAAA,CAAW,EAAQ,4BAA4B,CAAC,EACvD,MACF,CAEA,IAAI,EAAU,GACR,YACJ,CAAI,IACJ,EAAU,GACV,aAAa,CAAK,EAClB,GAAQ,oBAAoB,QAAS,KAAK,EACnC,IAEH,YAAe,GAAmB,CAClC,QAAQ,GAAG,EAAQ,CAAK,CAC9B,EACM,WAAc,GAAyB,CACvC,QAAQ,GAAG,EAAO,CAAK,CAC7B,EACM,EAAQ,eAAiB,WAAW,CAAQ,EAAG,KAAK,IAAI,EAAG,EAAW,IAAI,CAAC,CAAC,EAC5E,UAAc,YAAA,EAAW,EAAA,WAAA,CAAW,EAAQ,4BAA4B,CAAC,EAE/E,GAAQ,iBAAiB,QAAS,MAAO,CAAE,KAAM,EAAK,CAAC,EAEvD,GAAI,CACF,QAAQ,QAAQ,EAAI,CAAC,CAAC,CAAC,KAAK,YAAa,UAAU,CACrD,OAAS,EAAO,CACd,WAAW,CAAK,CAClB,CACF,CAAC,EAEU,OAAS,EAAK,EAAG,EAAwB,CA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|
|
2
|
+
signal?: AbortSignal;
|
|
3
|
+
}
|
|
1
4
|
export interface WaitOptions {
|
|
2
5
|
/** Polling interval in ms (default: 50). */
|
|
3
6
|
interval?: number;
|
|
@@ -6,24 +9,24 @@ export interface WaitOptions {
|
|
|
6
9
|
/** Maximum wait time in ms (default: 1000). */
|
|
7
10
|
timeout?: number;
|
|
8
11
|
}
|
|
9
|
-
export interface
|
|
12
|
+
export interface EventuallyOptions extends WaitOptions {
|
|
10
13
|
/** Context included in the timeout error. */
|
|
11
14
|
message?: string;
|
|
12
15
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
signal?: AbortSignal;
|
|
16
|
-
}
|
|
16
|
+
export declare const delay: (ms?: number, options?: DelayOptions) => Promise<void>;
|
|
17
|
+
export declare function waitUntil(predicate: () => boolean | Promise<boolean>, { interval, signal, timeout }?: WaitOptions): Promise<void>;
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* Retry an assertion until it stops throwing or the timeout elapses.
|
|
20
|
+
*
|
|
21
|
+
* Polls the assertion on a fixed interval and preserves the last failure as the
|
|
22
|
+
* timeout cause. Pending asynchronous assertions remain bounded by the same
|
|
23
|
+
* deadline. Use `waitUntil()` for boolean conditions, `delay()` for explicit
|
|
24
|
+
* timer dependencies, and `nextTick()` for one queued microtask boundary.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* await eventually(() => expect(region.textContent).toBe('Saved'));
|
|
19
28
|
*/
|
|
20
|
-
export declare
|
|
21
|
-
/** Poll until a synchronous or asynchronous predicate returns `true`. */
|
|
22
|
-
export declare function waitUntil(predicate: () => boolean | Promise<boolean>, { interval, signal, timeout }?: WaitOptions): Promise<void>;
|
|
23
|
-
/** Retry an assertion until it stops throwing. */
|
|
24
|
-
export declare function retry(assertion: () => void | Promise<void>, { interval, message, signal, timeout }?: RetryOptions): Promise<void>;
|
|
29
|
+
export declare function eventually(assertion: () => void | Promise<void>, { interval, message, signal, timeout }?: EventuallyOptions): Promise<void>;
|
|
25
30
|
/** Resolve with the next event of `type`, or reject when it times out or is aborted. */
|
|
26
31
|
export declare function waitForEvent<T extends Event = Event>(target: EventTarget, type: string, { signal, timeout }?: Omit<WaitOptions, 'interval'>): Promise<T>;
|
|
27
|
-
/** Resolve after one microtask tick. */
|
|
28
|
-
export declare const nextTick: () => Promise<void>;
|
|
29
32
|
//# sourceMappingURL=wait.d.ts.map
|
package/dist/wait.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAoDD,eAAO,MAAM,KAAK,GAAI,WAAM,EAAE,UAAS,YAAiB,KAAG,OAAO,CAAC,IAAI,CAGtE,CAAC;AAEF,wBAAsB,SAAS,CAC7B,SAAS,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,EAC3C,EAAE,QAAa,EAAE,MAAM,EAAE,OAAc,EAAE,GAAE,WAAgB,GAC1D,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EACrC,EAAE,QAAa,EAAE,OAAO,EAAE,MAAM,EAAE,OAAc,EAAE,GAAE,iBAAsB,GACzE,OAAO,CAAC,IAAI,CAAC,CA8Bf;AAED,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAClD,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,MAAM,EACZ,EAAE,MAAM,EAAE,OAAc,EAAE,GAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAM,GAC7D,OAAO,CAAC,CAAC,CAAC,CA8BZ"}
|
package/dist/wait.js
CHANGED
|
@@ -1,67 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
//#region src/wait.ts
|
|
3
|
-
var t = (e) => e.reason ?? new DOMException("The operation was aborted.", "AbortError"), n = (e = 0, { signal: n } = {}) => new Promise((r, i) => {
|
|
4
|
-
if (n?.aborted) {
|
|
5
|
-
i(t(n));
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
let a = setTimeout(o, e);
|
|
9
|
-
function o() {
|
|
10
|
-
n?.removeEventListener("abort", s), r();
|
|
11
|
-
}
|
|
12
|
-
function s() {
|
|
13
|
-
clearTimeout(a), i(t(n));
|
|
14
|
-
}
|
|
15
|
-
n?.addEventListener("abort", s, { once: !0 });
|
|
16
|
-
});
|
|
17
|
-
async function r(r, { interval: i = 50, signal: a, timeout: o = 1e3 } = {}) {
|
|
18
|
-
let s = Date.now() + o;
|
|
19
|
-
for (;;) {
|
|
20
|
-
if (a?.aborted) throw t(a);
|
|
21
|
-
if (await r()) return;
|
|
22
|
-
if (Date.now() >= s) break;
|
|
23
|
-
await n(i, { signal: a });
|
|
24
|
-
}
|
|
25
|
-
throw new e(`waitUntil timed out after ${o}ms`);
|
|
26
|
-
}
|
|
27
|
-
async function i(r, { interval: i = 50, message: a, signal: o, timeout: s = 1e3 } = {}) {
|
|
28
|
-
let c = Date.now() + s, l;
|
|
29
|
-
for (;;) {
|
|
30
|
-
if (o?.aborted) throw t(o);
|
|
31
|
-
try {
|
|
32
|
-
await r();
|
|
33
|
-
return;
|
|
34
|
-
} catch (e) {
|
|
35
|
-
l = e;
|
|
36
|
-
}
|
|
37
|
-
if (Date.now() >= c) break;
|
|
38
|
-
await n(i, { signal: o });
|
|
39
|
-
}
|
|
40
|
-
let u = `retry timed out after ${s}ms`, d = a ? `${a} (${u})` : u, f = l instanceof Error ? l.message : l == null ? "" : String(l);
|
|
41
|
-
throw new e(f ? `${d}\n${f}` : d, { cause: l });
|
|
42
|
-
}
|
|
43
|
-
function a(n, r, { signal: i, timeout: a = 1e3 } = {}) {
|
|
44
|
-
return new Promise((o, s) => {
|
|
45
|
-
if (i?.aborted) {
|
|
46
|
-
s(t(i));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
let c = () => {
|
|
50
|
-
clearTimeout(u), i?.removeEventListener("abort", d), n.removeEventListener(r, l);
|
|
51
|
-
}, l = (e) => {
|
|
52
|
-
c(), o(e);
|
|
53
|
-
}, u = setTimeout(() => {
|
|
54
|
-
c(), s(new e(`waitForEvent: "${r}" timed out after ${a}ms`));
|
|
55
|
-
}, a), d = () => {
|
|
56
|
-
c(), s(t(i));
|
|
57
|
-
};
|
|
58
|
-
n.addEventListener(r, l, { once: !0 }), i?.addEventListener("abort", d, { once: !0 });
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
var o = () => new Promise((e) => {
|
|
62
|
-
queueMicrotask(e);
|
|
63
|
-
});
|
|
64
|
-
//#endregion
|
|
65
|
-
export { n as delay, o as nextTick, i as retry, a as waitForEvent, r as waitUntil };
|
|
66
|
-
|
|
1
|
+
import{AssayTimeoutError as e}from"./errors.js";import{abortError as t,sleep as n}from"@vielzeug/arsenal";var r=Symbol(`assay.deadline`),i=2147483647,now=()=>performance.now(),validateDuration=(e,t,n)=>{if(!Number.isFinite(t)||t>i||(n?t<0:t<=0))throw RangeError(`${e} must be a ${n?`non-negative`:`positive`} finite number no greater than ${i}`)},validateWait=(e,t)=>{validateDuration(`interval`,e,!1),validateDuration(`timeout`,t,!0)},runBounded=(e,n,i)=>new Promise((a,o)=>{if(i?.aborted){o(t(i,`The operation was aborted.`));return}let s=!1,cleanup=()=>!s&&(s=!0,clearTimeout(c),i?.removeEventListener(`abort`,abort),!0),resolveOnce=e=>{cleanup()&&a(e)},rejectOnce=e=>{cleanup()&&o(e)},c=setTimeout(()=>rejectOnce(r),Math.max(0,n-now())),abort=()=>rejectOnce(t(i,`The operation was aborted.`));i?.addEventListener(`abort`,abort,{once:!0});try{Promise.resolve(e()).then(resolveOnce,rejectOnce)}catch(e){rejectOnce(e)}}),delay=(e=0,t={})=>(validateDuration(`ms`,e,!0),n(e,t.signal));async function waitUntil(i,{interval:a=50,signal:o,timeout:s=1e3}={}){validateWait(a,s);let c=now()+s,l=!0;for(;;){if(o?.aborted)throw t(o,`The operation was aborted.`);if(!l&&now()>=c)throw new e(`waitUntil timed out after ${s}ms`);l=!1;let u;try{u=await runBounded(i,c,o)}catch(t){throw t===r?new e(`waitUntil timed out after ${s}ms`):t}if(u)return;let d=c-now();if(d<=0)throw new e(`waitUntil timed out after ${s}ms`);await n(Math.min(a,d),o)}}async function eventually(i,{interval:a=50,message:o,signal:s,timeout:c=1e3}={}){validateWait(a,c);let l=now()+c,u=!0,d;for(;;){if(s?.aborted)throw t(s,`The operation was aborted.`);if(!u&&now()>=l)break;u=!1;try{await runBounded(i,l,s);return}catch(e){if(s?.aborted)throw t(s,`The operation was aborted.`);if(e===r)break;d=e}let e=l-now();if(e<=0)break;await n(Math.min(a,e),s)}let f=`eventually timed out after ${c}ms`,p=o?`${o} (${f})`:f,m=d instanceof Error?d.message:d==null?``:String(d);throw new e(m?`${p}\n${m}`:p,{cause:d})}function waitForEvent(n,r,{signal:i,timeout:a=1e3}={}){return validateDuration(`timeout`,a,!0),new Promise((o,s)=>{if(i?.aborted){s(t(i,`The operation was aborted.`));return}let dispose=()=>{clearTimeout(c),i?.removeEventListener(`abort`,onAbort),n.removeEventListener(r,onEvent)},onEvent=e=>{dispose(),o(e)},c=setTimeout(()=>{dispose(),s(new e(`waitForEvent: "${r}" timed out after ${a}ms`))},a),onAbort=()=>{dispose(),s(t(i,`The operation was aborted.`))};n.addEventListener(r,onEvent,{once:!0}),i?.addEventListener(`abort`,onAbort,{once:!0})})}export{delay,eventually,waitForEvent,waitUntil};
|
|
67
2
|
//# sourceMappingURL=wait.js.map
|
package/dist/wait.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait.js","names":[],"sources":["../src/wait.ts"],"sourcesContent":["import { AssayTimeoutError } from './errors';\n\nexport interface WaitOptions {\n /** Polling interval in ms (default: 50). */\n interval?: number;\n /** Cancel the pending wait. */\n signal?: AbortSignal;\n /** Maximum wait time in ms (default: 1000). */\n timeout?: number;\n}\n\nexport interface
|
|
1
|
+
{"version":3,"file":"wait.js","names":[],"sources":["../src/wait.ts"],"sourcesContent":["import { abortError, sleep } from '@vielzeug/arsenal';\n\nimport { AssayTimeoutError } from './errors';\n\nexport interface DelayOptions {\n signal?: AbortSignal;\n}\n\nexport interface WaitOptions {\n /** Polling interval in ms (default: 50). */\n interval?: number;\n /** Cancel the pending wait. */\n signal?: AbortSignal;\n /** Maximum wait time in ms (default: 1000). */\n timeout?: number;\n}\n\nexport interface EventuallyOptions extends WaitOptions {\n /** Context included in the timeout error. */\n message?: string;\n}\n\nconst DEADLINE = Symbol('assay.deadline');\nconst MAX_TIMER_MS = 2_147_483_647;\nconst now = (): number => performance.now();\n\nconst validateDuration = (name: string, value: number, allowZero: boolean): void => {\n if (!Number.isFinite(value) || value > MAX_TIMER_MS || (allowZero ? value < 0 : value <= 0)) {\n throw new RangeError(\n `${name} must be a ${allowZero ? 'non-negative' : 'positive'} finite number no greater than ${MAX_TIMER_MS}`,\n );\n }\n};\n\nconst validateWait = (interval: number, timeout: number): void => {\n validateDuration('interval', interval, false);\n validateDuration('timeout', timeout, true);\n};\n\nconst runBounded = <T>(run: () => T | Promise<T>, deadline: number, signal?: AbortSignal): Promise<T> =>\n new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(abortError(signal, 'The operation was aborted.'));\n return;\n }\n\n let settled = false;\n const cleanup = (): boolean => {\n if (settled) return false;\n settled = true;\n clearTimeout(timer);\n signal?.removeEventListener('abort', abort);\n return true;\n };\n const resolveOnce = (value: T): void => {\n if (cleanup()) resolve(value);\n };\n const rejectOnce = (error: unknown): void => {\n if (cleanup()) reject(error);\n };\n const timer = setTimeout(() => rejectOnce(DEADLINE), Math.max(0, deadline - now()));\n const abort = () => rejectOnce(abortError(signal, 'The operation was aborted.'));\n\n signal?.addEventListener('abort', abort, { once: true });\n\n try {\n Promise.resolve(run()).then(resolveOnce, rejectOnce);\n } catch (error) {\n rejectOnce(error);\n }\n });\n\nexport const delay = (ms = 0, options: DelayOptions = {}): Promise<void> => {\n validateDuration('ms', ms, true);\n return sleep(ms, options.signal);\n};\n\nexport async function waitUntil(\n predicate: () => boolean | Promise<boolean>,\n { interval = 50, signal, timeout = 1000 }: WaitOptions = {},\n): Promise<void> {\n validateWait(interval, timeout);\n const deadline = now() + timeout;\n let first = true;\n\n for (;;) {\n if (signal?.aborted) throw abortError(signal, 'The operation was aborted.');\n if (!first && now() >= deadline) throw new AssayTimeoutError(`waitUntil timed out after ${timeout}ms`);\n first = false;\n\n let matched: boolean;\n try {\n matched = await runBounded(predicate, deadline, signal);\n } catch (error) {\n if (error === DEADLINE) throw new AssayTimeoutError(`waitUntil timed out after ${timeout}ms`);\n throw error;\n }\n if (matched) return;\n\n const remaining = deadline - now();\n if (remaining <= 0) throw new AssayTimeoutError(`waitUntil timed out after ${timeout}ms`);\n await sleep(Math.min(interval, remaining), signal);\n }\n}\n\n/**\n * Retry an assertion until it stops throwing or the timeout elapses.\n *\n * Polls the assertion on a fixed interval and preserves the last failure as the\n * timeout cause. Pending asynchronous assertions remain bounded by the same\n * deadline. Use `waitUntil()` for boolean conditions, `delay()` for explicit\n * timer dependencies, and `nextTick()` for one queued microtask boundary.\n *\n * @example\n * await eventually(() => expect(region.textContent).toBe('Saved'));\n */\nexport async function eventually(\n assertion: () => void | Promise<void>,\n { interval = 50, message, signal, timeout = 1000 }: EventuallyOptions = {},\n): Promise<void> {\n validateWait(interval, timeout);\n const deadline = now() + timeout;\n let first = true;\n let lastError: unknown;\n\n for (;;) {\n if (signal?.aborted) throw abortError(signal, 'The operation was aborted.');\n if (!first && now() >= deadline) break;\n first = false;\n\n try {\n await runBounded(assertion, deadline, signal);\n return;\n } catch (error) {\n if (signal?.aborted) throw abortError(signal, 'The operation was aborted.');\n if (error === DEADLINE) break;\n lastError = error;\n }\n\n const remaining = deadline - now();\n if (remaining <= 0) break;\n await sleep(Math.min(interval, remaining), signal);\n }\n\n const timing = `eventually timed out after ${timeout}ms`;\n const context = message ? `${message} (${timing})` : timing;\n const detail = lastError instanceof Error ? lastError.message : lastError == null ? '' : String(lastError);\n\n throw new AssayTimeoutError(detail ? `${context}\\n${detail}` : context, { cause: lastError });\n}\n\n/** Resolve with the next event of `type`, or reject when it times out or is aborted. */\nexport function waitForEvent<T extends Event = Event>(\n target: EventTarget,\n type: string,\n { signal, timeout = 1000 }: Omit<WaitOptions, 'interval'> = {},\n): Promise<T> {\n validateDuration('timeout', timeout, true);\n\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(abortError(signal, 'The operation was aborted.'));\n return;\n }\n\n const dispose = () => {\n clearTimeout(timer);\n signal?.removeEventListener('abort', onAbort);\n target.removeEventListener(type, onEvent);\n };\n const onEvent = (event: Event): void => {\n dispose();\n resolve(event as T);\n };\n const timer = setTimeout(() => {\n dispose();\n reject(new AssayTimeoutError(`waitForEvent: \"${type}\" timed out after ${timeout}ms`));\n }, timeout);\n const onAbort = () => {\n dispose();\n reject(abortError(signal, 'The operation was aborted.'));\n };\n\n target.addEventListener(type, onEvent, { once: true });\n signal?.addEventListener('abort', onAbort, { once: true });\n });\n}\n"],"mappings":"0GAsBA,IAAM,EAAW,OAAO,gBAAgB,EAClC,EAAe,WACf,QAAoB,YAAY,IAAI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