@sigx/lynx-testing 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fire-event.d.ts +1 -1
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +99 -0
- package/dist/fire-event.js.map +1 -0
- package/dist/flush.js +40 -0
- package/dist/flush.js.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -304
- package/dist/index.js.map +1 -1
- package/dist/mt/index.js +232 -105
- package/dist/mt/index.js.map +1 -1
- package/dist/mt/setup.js +105 -2
- package/dist/mt/setup.js.map +1 -0
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +38 -0
- package/dist/queries.js.map +1 -0
- package/dist/render.d.ts +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +31 -0
- package/dist/render.js.map +1 -0
- package/dist/test-node.js +75 -0
- package/dist/test-node.js.map +1 -0
- package/dist/test-renderer.d.ts +1 -1
- package/dist/test-renderer.d.ts.map +1 -1
- package/dist/test-renderer.js +102 -0
- package/dist/test-renderer.js.map +1 -0
- package/package.json +11 -10
- package/dist/setup-BUzWSuVx.js +0 -55
- package/dist/setup-BUzWSuVx.js.map +0 -1
package/dist/fire-event.d.ts
CHANGED
package/dist/fire-event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"fire-event.d.ts","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,UAAU,cAAc;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IAC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AAmB,GAAG,IAAI;IAI7D,6BAA6B;IAC7B,MAAM,OAAO,QAAQ,SAAS,oBAAoB,GAAG,IAAI;IAoBzD,4BAA4B;IAC5B,KAAK,OAAO,QAAQ,SAAS,mBAAmB,GAAG,IAAI;IAYvD,gCAAgC;IAChC,SAAS,OAAO,QAAQ,GAAG,IAAI;CAWhC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** Create a normalized touch object with defaults. */
|
|
2
|
+
export function touch(pageX, pageY, identifier = 1) {
|
|
3
|
+
return { identifier, x: pageX, y: pageY, pageX, pageY, clientX: pageX, clientY: pageY };
|
|
4
|
+
}
|
|
5
|
+
function dispatchHandler(node, handlerKey, event) {
|
|
6
|
+
const handler = node._handlers.get(handlerKey);
|
|
7
|
+
if (handler)
|
|
8
|
+
handler(event);
|
|
9
|
+
}
|
|
10
|
+
function normalizeTouchEvent(data) {
|
|
11
|
+
return {
|
|
12
|
+
type: 'touch',
|
|
13
|
+
timestamp: Date.now(),
|
|
14
|
+
touches: data?.touches ?? [],
|
|
15
|
+
changedTouches: data?.changedTouches ?? data?.touches ?? [],
|
|
16
|
+
target: { id: '', dataset: {}, uid: 0 },
|
|
17
|
+
currentTarget: { id: '', dataset: {}, uid: 0 },
|
|
18
|
+
detail: {},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export const fireEvent = {
|
|
22
|
+
/** Fire bindtap / onTap event. */
|
|
23
|
+
tap(node, data) {
|
|
24
|
+
const x = data?.x ?? 0;
|
|
25
|
+
const y = data?.y ?? 0;
|
|
26
|
+
const event = {
|
|
27
|
+
type: 'tap',
|
|
28
|
+
timestamp: Date.now(),
|
|
29
|
+
target: { id: '', dataset: {}, uid: 0 },
|
|
30
|
+
currentTarget: { id: '', dataset: {}, uid: 0 },
|
|
31
|
+
detail: { x, y },
|
|
32
|
+
touches: [touch(x, y)],
|
|
33
|
+
changedTouches: [touch(x, y)],
|
|
34
|
+
};
|
|
35
|
+
dispatchHandler(node, 'bindtap', event);
|
|
36
|
+
dispatchHandler(node, 'onTap', event);
|
|
37
|
+
},
|
|
38
|
+
/** Fire bindtouchstart event. */
|
|
39
|
+
touchStart(node, data) {
|
|
40
|
+
dispatchHandler(node, 'bindtouchstart', normalizeTouchEvent(data));
|
|
41
|
+
},
|
|
42
|
+
/** Fire bindtouchmove event. */
|
|
43
|
+
touchMove(node, data) {
|
|
44
|
+
dispatchHandler(node, 'bindtouchmove', normalizeTouchEvent(data));
|
|
45
|
+
},
|
|
46
|
+
/** Fire bindtouchend event. */
|
|
47
|
+
touchEnd(node, data) {
|
|
48
|
+
dispatchHandler(node, 'bindtouchend', normalizeTouchEvent(data));
|
|
49
|
+
},
|
|
50
|
+
/** Fire bindtouchcancel event. */
|
|
51
|
+
touchCancel(node, data) {
|
|
52
|
+
dispatchHandler(node, 'bindtouchcancel', normalizeTouchEvent(data));
|
|
53
|
+
},
|
|
54
|
+
/** Fire bindscroll event. */
|
|
55
|
+
scroll(node, data) {
|
|
56
|
+
const event = {
|
|
57
|
+
type: 'scroll',
|
|
58
|
+
timestamp: Date.now(),
|
|
59
|
+
target: { id: '', dataset: {}, uid: 0 },
|
|
60
|
+
currentTarget: { id: '', dataset: {}, uid: 0 },
|
|
61
|
+
detail: {
|
|
62
|
+
scrollTop: 0,
|
|
63
|
+
scrollLeft: 0,
|
|
64
|
+
scrollHeight: 0,
|
|
65
|
+
scrollWidth: 0,
|
|
66
|
+
deltaX: 0,
|
|
67
|
+
deltaY: 0,
|
|
68
|
+
...data?.detail,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
dispatchHandler(node, 'bindscroll', event);
|
|
72
|
+
dispatchHandler(node, 'onScroll', event);
|
|
73
|
+
},
|
|
74
|
+
/** Fire bindinput event. */
|
|
75
|
+
input(node, data) {
|
|
76
|
+
const event = {
|
|
77
|
+
type: 'input',
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
target: { id: '', dataset: {}, uid: 0 },
|
|
80
|
+
currentTarget: { id: '', dataset: {}, uid: 0 },
|
|
81
|
+
detail: { value: '', ...data?.detail },
|
|
82
|
+
};
|
|
83
|
+
dispatchHandler(node, 'bindinput', event);
|
|
84
|
+
dispatchHandler(node, 'onInput', event);
|
|
85
|
+
},
|
|
86
|
+
/** Fire bindlongpress event. */
|
|
87
|
+
longPress(node) {
|
|
88
|
+
const event = {
|
|
89
|
+
type: 'longpress',
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
target: { id: '', dataset: {}, uid: 0 },
|
|
92
|
+
currentTarget: { id: '', dataset: {}, uid: 0 },
|
|
93
|
+
detail: {},
|
|
94
|
+
};
|
|
95
|
+
dispatchHandler(node, 'bindlongpress', event);
|
|
96
|
+
dispatchHandler(node, 'onLongpress', event);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=fire-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fire-event.js","sourceRoot":"","sources":["../src/fire-event.ts"],"names":[],"mappings":"AAqCA,sDAAsD;AACtD,MAAM,UAAU,KAAK,CACnB,KAAa,EACb,KAAa,EACb,UAAU,GAAG,CAAC;IAEd,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC1F,CAAC;AAED,SAAS,eAAe,CAAC,IAAc,EAAE,UAAkB,EAAE,KAAc;IACzE,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,OAAO;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,mBAAmB,CAAC,IAA0B;IACrD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,OAAO,EAAE,IAAI,EAAE,OA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MAAM,KAAK,GAAG;YACZ,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;YACvC,aAAa,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;YAC9C,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE;SACvC,CAAC;QACF,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QAC1C,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,gCAAgC;IAChC,SAAS,CAAC,IAAc;QACtB,MAAM,KAAK,GAAG;YACZ,IAAI,EAAE,WAAW;YACjB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;YACvC,aAAa,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;YAC9C,MAAM,EAAE,EAAE;SACX,CAAC;QACF,eAAe,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC;QAC9C,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;CACF,CAAC"}
|
package/dist/flush.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for waiting on reactive updates in tests.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Wait for all pending reactive effects and microtasks to complete.
|
|
6
|
+
* Use after mutating signal state to ensure the rendered tree is updated.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* state.count = 5;
|
|
11
|
+
* await waitForUpdate();
|
|
12
|
+
* expect(getByText(container, '5')).toBeTruthy();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function waitForUpdate() {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
// Microtask (Promise.resolve) runs reactive effects,
|
|
18
|
+
// then setTimeout(0) ensures any scheduled flushes complete.
|
|
19
|
+
Promise.resolve()
|
|
20
|
+
.then(() => new Promise(r => setTimeout(r, 0)))
|
|
21
|
+
.then(resolve);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Run a callback and wait for reactive effects to flush.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* await act(() => {
|
|
30
|
+
* state.count++;
|
|
31
|
+
* state.name = 'Alice';
|
|
32
|
+
* });
|
|
33
|
+
* // Tree is now updated
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export async function act(fn) {
|
|
37
|
+
await fn();
|
|
38
|
+
await waitForUpdate();
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=flush.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flush.js","sourceRoot":"","sources":["../src/flush.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,qDAAqD;QACrD,6DAA6D;QAC7D,OAAO,CAAC,OAAO,EAAE;aACd,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;aACpD,IAAI,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,EAA8B;IACtD,MAAM,EAAE,EAAE,CAAC;IACX,MAAM,aAAa,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { render } from './render';
|
|
2
|
-
export type { RenderResult } from './render';
|
|
3
|
-
export { TestNode } from './test-node';
|
|
4
|
-
export { fireEvent, touch } from './fire-event';
|
|
5
|
-
export { waitForUpdate, act } from './flush';
|
|
6
|
-
export { getByType, getAllByType, getByText, queryByType, queryByText, getByProp, } from './queries';
|
|
1
|
+
export { render } from './render.js';
|
|
2
|
+
export type { RenderResult } from './render.js';
|
|
3
|
+
export { TestNode } from './test-node.js';
|
|
4
|
+
export { fireEvent, touch } from './fire-event.js';
|
|
5
|
+
export { waitForUpdate, act } from './flush.js';
|
|
6
|
+
export { getByType, getAllByType, getByText, queryByType, queryByText, getByProp, } from './queries.js';
|
|
7
7
|
//# 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,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,SAAS,EACT,YAAY,EACZ,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,GACV,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,305 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
children = [];
|
|
7
|
-
parent = null;
|
|
8
|
-
text;
|
|
9
|
-
_handlers = /* @__PURE__ */ new Map();
|
|
10
|
-
_style = {};
|
|
11
|
-
_class = "";
|
|
12
|
-
constructor(e) {
|
|
13
|
-
this.type = e;
|
|
14
|
-
}
|
|
15
|
-
findByType(e) {
|
|
16
|
-
for (let t of this.children) {
|
|
17
|
-
if (t.type === e) return t;
|
|
18
|
-
let n = t.findByType(e);
|
|
19
|
-
if (n) return n;
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
findAllByType(e) {
|
|
24
|
-
let t = [];
|
|
25
|
-
for (let n of this.children) n.type === e && t.push(n), t.push(...n.findAllByType(e));
|
|
26
|
-
return t;
|
|
27
|
-
}
|
|
28
|
-
findByText(e) {
|
|
29
|
-
if (this.text !== void 0 && String(this.text).includes(e)) return this;
|
|
30
|
-
for (let t of this.children) {
|
|
31
|
-
let n = t.findByText(e);
|
|
32
|
-
if (n) return n;
|
|
33
|
-
}
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
textContent() {
|
|
37
|
-
return this.text === void 0 ? this.children.map((e) => e.textContent()).join("") : String(this.text);
|
|
38
|
-
}
|
|
39
|
-
toDebugString(e = 0) {
|
|
40
|
-
let t = " ".repeat(e);
|
|
41
|
-
if (this.type === "#text") return `${t}${JSON.stringify(this.text)}`;
|
|
42
|
-
if (this.type === "#comment") return `${t}<!-- -->`;
|
|
43
|
-
let n = Object.keys(this.props).length > 0 ? " " + Object.entries(this.props).map(([e, t]) => `${e}=${JSON.stringify(t)}`).join(" ") : "";
|
|
44
|
-
if (this.children.length === 0) return `${t}<${this.type}${n} />`;
|
|
45
|
-
let r = this.children.map((t) => t.toDebugString(e + 1)).join("\n");
|
|
46
|
-
return `${t}<${this.type}${n}>\n${r}\n${t}</${this.type}>`;
|
|
47
|
-
}
|
|
48
|
-
}, n = e({
|
|
49
|
-
createElement(e) {
|
|
50
|
-
return new t(e);
|
|
51
|
-
},
|
|
52
|
-
createText(e) {
|
|
53
|
-
let n = new t("#text");
|
|
54
|
-
return n.text = e, n;
|
|
55
|
-
},
|
|
56
|
-
createComment(e) {
|
|
57
|
-
return new t("#comment");
|
|
58
|
-
},
|
|
59
|
-
setText(e, t) {
|
|
60
|
-
e.text = t;
|
|
61
|
-
},
|
|
62
|
-
setElementText(e, n) {
|
|
63
|
-
e.children = [];
|
|
64
|
-
let r = new t("#text");
|
|
65
|
-
r.text = n, r.parent = e, e.children.push(r);
|
|
66
|
-
},
|
|
67
|
-
insert(e, t, n) {
|
|
68
|
-
if (e.parent) {
|
|
69
|
-
let t = e.parent.children.indexOf(e);
|
|
70
|
-
t !== -1 && e.parent.children.splice(t, 1);
|
|
71
|
-
}
|
|
72
|
-
if (e.parent = t, n) {
|
|
73
|
-
let r = t.children.indexOf(n);
|
|
74
|
-
if (r !== -1) {
|
|
75
|
-
t.children.splice(r, 0, e);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
t.children.push(e);
|
|
80
|
-
},
|
|
81
|
-
remove(e) {
|
|
82
|
-
if (e.parent) {
|
|
83
|
-
let t = e.parent.children.indexOf(e);
|
|
84
|
-
t !== -1 && e.parent.children.splice(t, 1), e.parent = null;
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
patchProp(e, t, n, r) {
|
|
88
|
-
t === "style" ? (e._style = r ?? {}, e.props[t] = r) : t === "class" ? (e._class = r ?? "", e.props[t] = r) : t.startsWith("bind") || t.startsWith("catch") || t.startsWith("on") || t.startsWith("main-thread-bind") || t.startsWith("main-thread-catch") || t.startsWith("global-") ? (typeof r == "function" ? e._handlers.set(t, r) : e._handlers.delete(t), e.props[t] = r) : r == null ? delete e.props[t] : e.props[t] = r;
|
|
89
|
-
},
|
|
90
|
-
parentNode(e) {
|
|
91
|
-
return e.parent;
|
|
92
|
-
},
|
|
93
|
-
nextSibling(e) {
|
|
94
|
-
if (!e.parent) return null;
|
|
95
|
-
let t = e.parent.children.indexOf(e);
|
|
96
|
-
return e.parent.children[t + 1] ?? null;
|
|
97
|
-
},
|
|
98
|
-
cloneNode(e) {
|
|
99
|
-
return new t(e.type);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
//#endregion
|
|
103
|
-
//#region src/queries.ts
|
|
104
|
-
function r(e, t) {
|
|
105
|
-
let n = e.findByType(t);
|
|
106
|
-
if (!n) throw Error(`No element found with type "${t}"`);
|
|
107
|
-
return n;
|
|
108
|
-
}
|
|
109
|
-
function i(e, t) {
|
|
110
|
-
return e.findAllByType(t);
|
|
111
|
-
}
|
|
112
|
-
function a(e, t) {
|
|
113
|
-
let n = e.findByText(t);
|
|
114
|
-
if (!n) throw Error(`No element found with text "${t}"`);
|
|
115
|
-
return n;
|
|
116
|
-
}
|
|
117
|
-
function o(e, t) {
|
|
118
|
-
return e.findByType(t);
|
|
119
|
-
}
|
|
120
|
-
function s(e, t) {
|
|
121
|
-
return e.findByText(t);
|
|
122
|
-
}
|
|
123
|
-
function c(e, t, n) {
|
|
124
|
-
function r(e) {
|
|
125
|
-
if (e.props[t] === n) return e;
|
|
126
|
-
for (let t of e.children) {
|
|
127
|
-
let e = r(t);
|
|
128
|
-
if (e) return e;
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
let i = r(e);
|
|
133
|
-
if (!i) throw Error(`No element found with ${t}="${n}"`);
|
|
134
|
-
return i;
|
|
135
|
-
}
|
|
136
|
-
//#endregion
|
|
137
|
-
//#region src/render.ts
|
|
138
|
-
function l(e, l) {
|
|
139
|
-
let u = new t("root");
|
|
140
|
-
return n.render(e, u, l?.appContext ?? void 0), {
|
|
141
|
-
container: u,
|
|
142
|
-
unmount: () => {
|
|
143
|
-
n.render(null, u);
|
|
144
|
-
},
|
|
145
|
-
getByType: (e) => r(u, e),
|
|
146
|
-
getAllByType: (e) => i(u, e),
|
|
147
|
-
getByText: (e) => a(u, e),
|
|
148
|
-
queryByType: (e) => o(u, e),
|
|
149
|
-
queryByText: (e) => s(u, e),
|
|
150
|
-
getByProp: (e, t) => c(u, e, t),
|
|
151
|
-
debug: () => u.toDebugString()
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/fire-event.ts
|
|
156
|
-
function u(e, t, n = 1) {
|
|
157
|
-
return {
|
|
158
|
-
identifier: n,
|
|
159
|
-
x: e,
|
|
160
|
-
y: t,
|
|
161
|
-
pageX: e,
|
|
162
|
-
pageY: t,
|
|
163
|
-
clientX: e,
|
|
164
|
-
clientY: t
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
function d(e, t, n) {
|
|
168
|
-
let r = e._handlers.get(t);
|
|
169
|
-
r && r(n);
|
|
170
|
-
}
|
|
171
|
-
function f(e) {
|
|
172
|
-
return {
|
|
173
|
-
type: "touch",
|
|
174
|
-
timestamp: Date.now(),
|
|
175
|
-
touches: e?.touches ?? [],
|
|
176
|
-
changedTouches: e?.changedTouches ?? e?.touches ?? [],
|
|
177
|
-
target: {
|
|
178
|
-
id: "",
|
|
179
|
-
dataset: {},
|
|
180
|
-
uid: 0
|
|
181
|
-
},
|
|
182
|
-
currentTarget: {
|
|
183
|
-
id: "",
|
|
184
|
-
dataset: {},
|
|
185
|
-
uid: 0
|
|
186
|
-
},
|
|
187
|
-
detail: {}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
var p = {
|
|
191
|
-
tap(e, t) {
|
|
192
|
-
let n = t?.x ?? 0, r = t?.y ?? 0, i = {
|
|
193
|
-
type: "tap",
|
|
194
|
-
timestamp: Date.now(),
|
|
195
|
-
target: {
|
|
196
|
-
id: "",
|
|
197
|
-
dataset: {},
|
|
198
|
-
uid: 0
|
|
199
|
-
},
|
|
200
|
-
currentTarget: {
|
|
201
|
-
id: "",
|
|
202
|
-
dataset: {},
|
|
203
|
-
uid: 0
|
|
204
|
-
},
|
|
205
|
-
detail: {
|
|
206
|
-
x: n,
|
|
207
|
-
y: r
|
|
208
|
-
},
|
|
209
|
-
touches: [u(n, r)],
|
|
210
|
-
changedTouches: [u(n, r)]
|
|
211
|
-
};
|
|
212
|
-
d(e, "bindtap", i), d(e, "onTap", i);
|
|
213
|
-
},
|
|
214
|
-
touchStart(e, t) {
|
|
215
|
-
d(e, "bindtouchstart", f(t));
|
|
216
|
-
},
|
|
217
|
-
touchMove(e, t) {
|
|
218
|
-
d(e, "bindtouchmove", f(t));
|
|
219
|
-
},
|
|
220
|
-
touchEnd(e, t) {
|
|
221
|
-
d(e, "bindtouchend", f(t));
|
|
222
|
-
},
|
|
223
|
-
touchCancel(e, t) {
|
|
224
|
-
d(e, "bindtouchcancel", f(t));
|
|
225
|
-
},
|
|
226
|
-
scroll(e, t) {
|
|
227
|
-
let n = {
|
|
228
|
-
type: "scroll",
|
|
229
|
-
timestamp: Date.now(),
|
|
230
|
-
target: {
|
|
231
|
-
id: "",
|
|
232
|
-
dataset: {},
|
|
233
|
-
uid: 0
|
|
234
|
-
},
|
|
235
|
-
currentTarget: {
|
|
236
|
-
id: "",
|
|
237
|
-
dataset: {},
|
|
238
|
-
uid: 0
|
|
239
|
-
},
|
|
240
|
-
detail: {
|
|
241
|
-
scrollTop: 0,
|
|
242
|
-
scrollLeft: 0,
|
|
243
|
-
scrollHeight: 0,
|
|
244
|
-
scrollWidth: 0,
|
|
245
|
-
deltaX: 0,
|
|
246
|
-
deltaY: 0,
|
|
247
|
-
...t?.detail
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
d(e, "bindscroll", n), d(e, "onScroll", n);
|
|
251
|
-
},
|
|
252
|
-
input(e, t) {
|
|
253
|
-
let n = {
|
|
254
|
-
type: "input",
|
|
255
|
-
timestamp: Date.now(),
|
|
256
|
-
target: {
|
|
257
|
-
id: "",
|
|
258
|
-
dataset: {},
|
|
259
|
-
uid: 0
|
|
260
|
-
},
|
|
261
|
-
currentTarget: {
|
|
262
|
-
id: "",
|
|
263
|
-
dataset: {},
|
|
264
|
-
uid: 0
|
|
265
|
-
},
|
|
266
|
-
detail: {
|
|
267
|
-
value: "",
|
|
268
|
-
...t?.detail
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
d(e, "bindinput", n), d(e, "onInput", n);
|
|
272
|
-
},
|
|
273
|
-
longPress(e) {
|
|
274
|
-
let t = {
|
|
275
|
-
type: "longpress",
|
|
276
|
-
timestamp: Date.now(),
|
|
277
|
-
target: {
|
|
278
|
-
id: "",
|
|
279
|
-
dataset: {},
|
|
280
|
-
uid: 0
|
|
281
|
-
},
|
|
282
|
-
currentTarget: {
|
|
283
|
-
id: "",
|
|
284
|
-
dataset: {},
|
|
285
|
-
uid: 0
|
|
286
|
-
},
|
|
287
|
-
detail: {}
|
|
288
|
-
};
|
|
289
|
-
d(e, "bindlongpress", t), d(e, "onLongpress", t);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
//#endregion
|
|
293
|
-
//#region src/flush.ts
|
|
294
|
-
function m() {
|
|
295
|
-
return new Promise((e) => {
|
|
296
|
-
Promise.resolve().then(() => new Promise((e) => setTimeout(e, 0))).then(e);
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
async function h(e) {
|
|
300
|
-
await e(), await m();
|
|
301
|
-
}
|
|
302
|
-
//#endregion
|
|
303
|
-
export { t as TestNode, h as act, p as fireEvent, i as getAllByType, c as getByProp, a as getByText, r as getByType, s as queryByText, o as queryByType, l as render, u as touch, m as waitForUpdate };
|
|
304
|
-
|
|
1
|
+
export { render } from './render.js';
|
|
2
|
+
export { TestNode } from './test-node.js';
|
|
3
|
+
export { fireEvent, touch } from './fire-event.js';
|
|
4
|
+
export { waitForUpdate, act } from './flush.js';
|
|
5
|
+
export { getByType, getAllByType, getByText, queryByType, queryByText, getByProp, } from './queries.js';
|
|
305
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/test-node.ts","../src/test-renderer.ts","../src/queries.ts","../src/render.ts","../src/fire-event.ts","../src/flush.ts"],"sourcesContent":["/**\n * TestNode — lightweight in-memory tree node for test rendering.\n * Replaces ShadowElement + Lynx PAPI for testing purposes.\n */\nexport class TestNode {\n type: string;\n props: Record<string, unknown> = {};\n children: TestNode[] = [];\n parent: TestNode | null = null;\n text?: string;\n\n /** Event handlers keyed by prop name (e.g. 'bindtap', 'bindtouchstart'). */\n _handlers: Map<string, Function> = new Map();\n\n /** Style object (last value from patchProp 'style'). */\n _style: Record<string, unknown> = {};\n\n /** Class string. */\n _class = '';\n\n constructor(type: string) {\n this.type = type;\n }\n\n // -- Tree queries --\n\n /** Find first descendant matching element type. */\n findByType(type: string): TestNode | null {\n for (const child of this.children) {\n if (child.type === type) return child;\n const found = child.findByType(type);\n if (found) return found;\n }\n return null;\n }\n\n /** Find all descendants matching element type. */\n findAllByType(type: string): TestNode[] {\n const results: TestNode[] = [];\n for (const child of this.children) {\n if (child.type === type) results.push(child);\n results.push(...child.findAllByType(type));\n }\n return results;\n }\n\n /** Find first descendant containing the given text. */\n findByText(text: string): TestNode | null {\n if (this.text !== undefined && String(this.text).includes(text)) return this;\n for (const child of this.children) {\n const found = child.findByText(text);\n if (found) return found;\n }\n return null;\n }\n\n /** Get all text content from this node and descendants. */\n textContent(): string {\n if (this.text !== undefined) return String(this.text);\n return this.children.map(c => c.textContent()).join('');\n }\n\n /** Debug: serialize tree to a readable string. */\n toDebugString(indent = 0): string {\n const pad = ' '.repeat(indent);\n if (this.type === '#text') return `${pad}${JSON.stringify(this.text)}`;\n if (this.type === '#comment') return `${pad}<!-- -->`;\n const attrs = Object.keys(this.props).length > 0\n ? ' ' + Object.entries(this.props).map(([k, v]) => `${k}=${JSON.stringify(v)}`).join(' ')\n : '';\n if (this.children.length === 0) return `${pad}<${this.type}${attrs} />`;\n const childStr = this.children.map(c => c.toDebugString(indent + 1)).join('\\n');\n return `${pad}<${this.type}${attrs}>\\n${childStr}\\n${pad}</${this.type}>`;\n }\n}\n","/**\n * Test renderer — implements RendererOptions<TestNode, TestNode> for\n * in-memory rendering without Lynx PAPI.\n */\nimport { createRenderer } from '@sigx/runtime-core/internals';\nimport type { RendererOptions } from '@sigx/runtime-core/internals';\nimport { TestNode } from './test-node';\n\nconst nodeOps: RendererOptions<TestNode, TestNode> = {\n createElement(type: string): TestNode {\n return new TestNode(type);\n },\n\n createText(text: string): TestNode {\n const node = new TestNode('#text');\n node.text = text;\n return node;\n },\n\n createComment(_text: string): TestNode {\n return new TestNode('#comment');\n },\n\n setText(node: TestNode, text: string): void {\n node.text = text;\n },\n\n setElementText(el: TestNode, text: string): void {\n el.children = [];\n const textNode = new TestNode('#text');\n textNode.text = text;\n textNode.parent = el;\n el.children.push(textNode);\n },\n\n insert(child: TestNode, parent: TestNode, anchor?: TestNode | null): void {\n // Remove from old parent\n if (child.parent) {\n const idx = child.parent.children.indexOf(child);\n if (idx !== -1) child.parent.children.splice(idx, 1);\n }\n child.parent = parent;\n\n if (anchor) {\n const anchorIdx = parent.children.indexOf(anchor);\n if (anchorIdx !== -1) {\n parent.children.splice(anchorIdx, 0, child);\n return;\n }\n }\n parent.children.push(child);\n },\n\n remove(child: TestNode): void {\n if (child.parent) {\n const idx = child.parent.children.indexOf(child);\n if (idx !== -1) child.parent.children.splice(idx, 1);\n child.parent = null;\n }\n },\n\n patchProp(\n el: TestNode,\n key: string,\n _prevValue: unknown,\n nextValue: unknown,\n ): void {\n if (key === 'style') {\n el._style = (nextValue as Record<string, unknown>) ?? {};\n el.props[key] = nextValue;\n } else if (key === 'class') {\n el._class = (nextValue as string) ?? '';\n el.props[key] = nextValue;\n } else if (\n key.startsWith('bind') ||\n key.startsWith('catch') ||\n key.startsWith('on') ||\n key.startsWith('main-thread-bind') ||\n key.startsWith('main-thread-catch') ||\n key.startsWith('global-')\n ) {\n // Event handler\n if (typeof nextValue === 'function') {\n el._handlers.set(key, nextValue as Function);\n } else {\n el._handlers.delete(key);\n }\n el.props[key] = nextValue;\n } else {\n if (nextValue != null) {\n el.props[key] = nextValue;\n } else {\n delete el.props[key];\n }\n }\n },\n\n parentNode(node: TestNode): TestNode | null {\n return node.parent;\n },\n\n nextSibling(node: TestNode): TestNode | null {\n if (!node.parent) return null;\n const idx = node.parent.children.indexOf(node);\n return node.parent.children[idx + 1] ?? null;\n },\n\n cloneNode(node: TestNode): TestNode {\n return new TestNode(node.type);\n },\n};\n\nexport const testRenderer = createRenderer<TestNode, TestNode>(nodeOps);\nexport { nodeOps as testNodeOps };\n","/**\n * Query helpers for finding nodes in a TestNode tree.\n */\nimport { TestNode } from './test-node';\n\nexport function getByType(container: TestNode, type: string): TestNode {\n const node = container.findByType(type);\n if (!node) throw new Error(`No element found with type \"${type}\"`);\n return node;\n}\n\nexport function getAllByType(container: TestNode, type: string): TestNode[] {\n return container.findAllByType(type);\n}\n\nexport function getByText(container: TestNode, text: string): TestNode {\n const node = container.findByText(text);\n if (!node) throw new Error(`No element found with text \"${text}\"`);\n return node;\n}\n\nexport function queryByType(container: TestNode, type: string): TestNode | null {\n return container.findByType(type);\n}\n\nexport function queryByText(container: TestNode, text: string): TestNode | null {\n return container.findByText(text);\n}\n\nexport function getByProp(\n container: TestNode,\n key: string,\n value: unknown,\n): TestNode {\n function find(node: TestNode): TestNode | null {\n if (node.props[key] === value) return node;\n for (const child of node.children) {\n const found = find(child);\n if (found) return found;\n }\n return null;\n }\n const node = find(container);\n if (!node) throw new Error(`No element found with ${key}=\"${value}\"`);\n return node;\n}\n","/**\n * render() — mount a sigx Lynx component into a TestNode tree for testing.\n */\nimport type { JSXElement, AppContext } from '@sigx/lynx';\nimport { testRenderer } from './test-renderer';\nimport { TestNode } from './test-node';\nimport * as queries from './queries';\n\nexport interface RenderResult {\n /** The root container node. */\n container: TestNode;\n /** Unmount the component and clean up. */\n unmount: () => void;\n /** Find first node by element type (throws if not found). */\n getByType: (type: string) => TestNode;\n /** Find all nodes by element type. */\n getAllByType: (type: string) => TestNode[];\n /** Find first node containing text (throws if not found). */\n getByText: (text: string) => TestNode;\n /** Find first node by element type (returns null if not found). */\n queryByType: (type: string) => TestNode | null;\n /** Find first node containing text (returns null if not found). */\n queryByText: (text: string) => TestNode | null;\n /** Find first node by prop key/value (throws if not found). */\n getByProp: (key: string, value: unknown) => TestNode;\n /** Debug print the tree. */\n debug: () => string;\n}\n\n/**\n * Render a JSX element into an in-memory TestNode tree.\n *\n * @example\n * ```tsx\n * const { getByText, container } = render(<MyComponent name=\"World\" />);\n * expect(getByText('Hello World')).toBeTruthy();\n * ```\n */\nexport function render(\n element: JSXElement,\n options?: { appContext?: AppContext },\n): RenderResult {\n const container = new TestNode('root');\n\n testRenderer.render(element, container, options?.appContext ?? undefined);\n\n const unmount = () => {\n testRenderer.render(null, container);\n };\n\n return {\n container,\n unmount,\n getByType: (type) => queries.getByType(container, type),\n getAllByType: (type) => queries.getAllByType(container, type),\n getByText: (text) => queries.getByText(container, text),\n queryByType: (type) => queries.queryByType(container, type),\n queryByText: (text) => queries.queryByText(container, text),\n getByProp: (key, value) => queries.getByProp(container, key, value),\n debug: () => container.toDebugString(),\n };\n}\n","/**\n * Fire synthetic events on TestNode elements.\n */\nimport { TestNode } from './test-node';\n\ninterface SyntheticTouch {\n identifier?: number;\n x?: number;\n y?: number;\n pageX?: number;\n pageY?: number;\n clientX?: number;\n clientY?: number;\n}\n\ninterface SyntheticTouchEvent {\n touches?: SyntheticTouch[];\n changedTouches?: SyntheticTouch[];\n}\n\ninterface SyntheticScrollEvent {\n detail?: {\n scrollTop?: number;\n scrollLeft?: number;\n scrollHeight?: number;\n scrollWidth?: number;\n deltaX?: number;\n deltaY?: number;\n };\n}\n\ninterface SyntheticInputEvent {\n detail?: {\n value?: string;\n };\n}\n\n/** Create a normalized touch object with defaults. */\nexport function touch(\n pageX: number,\n pageY: number,\n identifier = 1,\n): SyntheticTouch {\n return { identifier, x: pageX, y: pageY, pageX, pageY, clientX: pageX, clientY: pageY };\n}\n\nfunction dispatchHandler(node: TestNode, handlerKey: string, event: unknown): void {\n const handler = node._handlers.get(handlerKey);\n if (handler) handler(event);\n}\n\nfunction normalizeTouchEvent(data?: SyntheticTouchEvent): object {\n return {\n type: 'touch',\n timestamp: Date.now(),\n touches: data?.touches ?? [],\n changedTouches: data?.changedTouches ?? data?.touches ?? [],\n target: { id: '', dataset: {}, uid: 0 },\n currentTarget: { id: '', dataset: {}, uid: 0 },\n detail: {},\n };\n}\n\nexport const fireEvent = {\n /** Fire bindtap / onTap event. */\n tap(node: TestNode, data?: { x?: number; y?: number }): void {\n const x = data?.x ?? 0;\n const y = data?.y ?? 0;\n const event = {\n type: 'tap',\n timestamp: Date.now(),\n target: { id: '', dataset: {}, uid: 0 },\n currentTarget: { id: '', dataset: {}, uid: 0 },\n detail: { x, y },\n touches: [touch(x, y)],\n changedTouches: [touch(x, y)],\n };\n dispatchHandler(node, 'bindtap', event);\n dispatchHandler(node, 'onTap', event);\n },\n\n /** Fire bindtouchstart event. */\n touchStart(node: TestNode, data?: SyntheticTouchEvent): void {\n dispatchHandler(node, 'bindtouchstart', normalizeTouchEvent(data));\n },\n\n /** Fire bindtouchmove event. */\n touchMove(node: TestNode, data?: SyntheticTouchEvent): void {\n dispatchHandler(node, 'bindtouchmove', normalizeTouchEvent(data));\n },\n\n /** Fire bindtouchend event. */\n touchEnd(node: TestNode, data?: SyntheticTouchEvent): void {\n dispatchHandler(node, 'bindtouchend', normalizeTouchEvent(data));\n },\n\n /** Fire bindtouchcancel event. */\n touchCancel(node: TestNode, data?: SyntheticTouchEvent): void {\n dispatchHandler(node, 'bindtouchcancel', normalizeTouchEvent(data));\n },\n\n /** Fire bindscroll event. */\n scroll(node: TestNode, data?: SyntheticScrollEvent): void {\n const event = {\n type: 'scroll',\n timestamp: Date.now(),\n target: { id: '', dataset: {}, uid: 0 },\n currentTarget: { id: '', dataset: {}, uid: 0 },\n detail: {\n scrollTop: 0,\n scrollLeft: 0,\n scrollHeight: 0,\n scrollWidth: 0,\n deltaX: 0,\n deltaY: 0,\n ...data?.detail,\n },\n };\n dispatchHandler(node, 'bindscroll', event);\n dispatchHandler(node, 'onScroll', event);\n },\n\n /** Fire bindinput event. */\n input(node: TestNode, data?: SyntheticInputEvent): void {\n const event = {\n type: 'input',\n timestamp: Date.now(),\n target: { id: '', dataset: {}, uid: 0 },\n currentTarget: { id: '', dataset: {}, uid: 0 },\n detail: { value: '', ...data?.detail },\n };\n dispatchHandler(node, 'bindinput', event);\n dispatchHandler(node, 'onInput', event);\n },\n\n /** Fire bindlongpress event. */\n longPress(node: TestNode): void {\n const event = {\n type: 'longpress',\n timestamp: Date.now(),\n target: { id: '', dataset: {}, uid: 0 },\n currentTarget: { id: '', dataset: {}, uid: 0 },\n detail: {},\n };\n dispatchHandler(node, 'bindlongpress', event);\n dispatchHandler(node, 'onLongpress', event);\n },\n};\n","/**\n * Utilities for waiting on reactive updates in tests.\n */\n\n/**\n * Wait for all pending reactive effects and microtasks to complete.\n * Use after mutating signal state to ensure the rendered tree is updated.\n *\n * @example\n * ```ts\n * state.count = 5;\n * await waitForUpdate();\n * expect(getByText(container, '5')).toBeTruthy();\n * ```\n */\nexport function waitForUpdate(): Promise<void> {\n return new Promise<void>((resolve) => {\n // Microtask (Promise.resolve) runs reactive effects,\n // then setTimeout(0) ensures any scheduled flushes complete.\n Promise.resolve()\n .then(() => new Promise<void>(r => setTimeout(r, 0)))\n .then(resolve);\n });\n}\n\n/**\n * Run a callback and wait for reactive effects to flush.\n *\n * @example\n * ```ts\n * await act(() => {\n * state.count++;\n * state.name = 'Alice';\n * });\n * // Tree is now updated\n * ```\n */\nexport async function act(fn: () => void | Promise<void>): Promise<void> {\n await fn();\n await waitForUpdate();\n}\n"],"mappings":";;AAIA,IAAa,IAAb,MAAsB;CACpB;CACA,QAAiC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