@react-three-dom/playwright 0.1.2 → 0.2.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/dist/index.cjs +1272 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +565 -74
- package/dist/index.d.ts +565 -74
- package/dist/index.js +1266 -153
- package/dist/index.js.map +1 -1
- package/package.json +11 -9
package/dist/index.js
CHANGED
|
@@ -3,6 +3,48 @@ import { test as test$1, expect as expect$1 } from '@playwright/test';
|
|
|
3
3
|
// src/fixtures.ts
|
|
4
4
|
|
|
5
5
|
// src/waiters.ts
|
|
6
|
+
async function waitForReadyBridge(page, timeout) {
|
|
7
|
+
const deadline = Date.now() + timeout;
|
|
8
|
+
const pollMs = 100;
|
|
9
|
+
while (Date.now() < deadline) {
|
|
10
|
+
const state = await page.evaluate(() => {
|
|
11
|
+
const api = window.__R3F_DOM__;
|
|
12
|
+
if (!api) return { exists: false };
|
|
13
|
+
return {
|
|
14
|
+
exists: true,
|
|
15
|
+
ready: api._ready,
|
|
16
|
+
error: api._error ?? null,
|
|
17
|
+
count: api.getCount()
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
if (state.exists && state.ready) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (state.exists && !state.ready && state.error) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`[react-three-dom] Bridge initialization failed: ${state.error}
|
|
26
|
+
The <ThreeDom> component mounted but threw during setup. Check the browser console for the full stack trace.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
await page.waitForTimeout(pollMs);
|
|
30
|
+
}
|
|
31
|
+
const finalState = await page.evaluate(() => {
|
|
32
|
+
const api = window.__R3F_DOM__;
|
|
33
|
+
if (!api) return { exists: false, ready: false, error: null };
|
|
34
|
+
return { exists: true, ready: api._ready, error: api._error ?? null };
|
|
35
|
+
});
|
|
36
|
+
if (finalState.exists && finalState.error) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`[react-three-dom] Bridge initialization failed: ${finalState.error}
|
|
39
|
+
The <ThreeDom> component mounted but threw during setup.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
throw new Error(
|
|
43
|
+
`[react-three-dom] Timed out after ${timeout}ms waiting for the bridge to be ready.
|
|
44
|
+
Bridge exists: ${finalState.exists}, ready: ${finalState.ready}.
|
|
45
|
+
Ensure <ThreeDom> is mounted inside your <Canvas> component.`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
6
48
|
async function waitForSceneReady(page, options = {}) {
|
|
7
49
|
const {
|
|
8
50
|
stableChecks = 3,
|
|
@@ -10,9 +52,7 @@ async function waitForSceneReady(page, options = {}) {
|
|
|
10
52
|
timeout = 1e4
|
|
11
53
|
} = options;
|
|
12
54
|
const deadline = Date.now() + timeout;
|
|
13
|
-
await page
|
|
14
|
-
timeout
|
|
15
|
-
});
|
|
55
|
+
await waitForReadyBridge(page, timeout);
|
|
16
56
|
let lastCount = -1;
|
|
17
57
|
let stableRuns = 0;
|
|
18
58
|
while (Date.now() < deadline) {
|
|
@@ -36,15 +76,13 @@ async function waitForObject(page, idOrUuid, options = {}) {
|
|
|
36
76
|
objectTimeout = 4e4,
|
|
37
77
|
pollIntervalMs = 200
|
|
38
78
|
} = options;
|
|
39
|
-
await page
|
|
40
|
-
timeout: bridgeTimeout
|
|
41
|
-
});
|
|
79
|
+
await waitForReadyBridge(page, bridgeTimeout);
|
|
42
80
|
const deadline = Date.now() + objectTimeout;
|
|
43
81
|
while (Date.now() < deadline) {
|
|
44
82
|
const found = await page.evaluate(
|
|
45
83
|
(id) => {
|
|
46
84
|
const api = window.__R3F_DOM__;
|
|
47
|
-
if (!api) return false;
|
|
85
|
+
if (!api || !api._ready) return false;
|
|
48
86
|
return (api.getByTestId(id) ?? api.getByUuid(id)) !== null;
|
|
49
87
|
},
|
|
50
88
|
idOrUuid
|
|
@@ -52,8 +90,18 @@ async function waitForObject(page, idOrUuid, options = {}) {
|
|
|
52
90
|
if (found) return;
|
|
53
91
|
await page.waitForTimeout(pollIntervalMs);
|
|
54
92
|
}
|
|
93
|
+
const diagnostics = await page.evaluate(() => {
|
|
94
|
+
const api = window.__R3F_DOM__;
|
|
95
|
+
if (!api) return { bridgeExists: false, ready: false, count: 0, error: null };
|
|
96
|
+
return {
|
|
97
|
+
bridgeExists: true,
|
|
98
|
+
ready: api._ready,
|
|
99
|
+
count: api.getCount(),
|
|
100
|
+
error: api._error ?? null
|
|
101
|
+
};
|
|
102
|
+
});
|
|
55
103
|
throw new Error(
|
|
56
|
-
`waitForObject("${idOrUuid}") timed out after ${objectTimeout}ms. Is the object rendered with userData.testId or
|
|
104
|
+
`waitForObject("${idOrUuid}") timed out after ${objectTimeout}ms. Bridge: ${diagnostics.bridgeExists ? "exists" : "missing"}, ready: ${diagnostics.ready}, objectCount: ${diagnostics.count}` + (diagnostics.error ? `, error: ${diagnostics.error}` : "") + `. Is the object rendered with userData.testId="${idOrUuid}" or uuid="${idOrUuid}"?`
|
|
57
105
|
);
|
|
58
106
|
}
|
|
59
107
|
async function waitForIdle(page, options = {}) {
|
|
@@ -61,6 +109,7 @@ async function waitForIdle(page, options = {}) {
|
|
|
61
109
|
idleFrames = 10,
|
|
62
110
|
timeout = 1e4
|
|
63
111
|
} = options;
|
|
112
|
+
await waitForReadyBridge(page, timeout);
|
|
64
113
|
const settled = await page.evaluate(
|
|
65
114
|
([frames, timeoutMs]) => {
|
|
66
115
|
return new Promise((resolve) => {
|
|
@@ -72,8 +121,17 @@ async function waitForIdle(page, options = {}) {
|
|
|
72
121
|
resolve(false);
|
|
73
122
|
return;
|
|
74
123
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
124
|
+
const api = window.__R3F_DOM__;
|
|
125
|
+
if (!api || !api._ready) {
|
|
126
|
+
if (api && api._error) {
|
|
127
|
+
resolve(`Bridge error: ${api._error}`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
requestAnimationFrame(check);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const snap = api.snapshot();
|
|
134
|
+
const json = JSON.stringify(snap.tree);
|
|
77
135
|
if (json === lastJson && json !== "") {
|
|
78
136
|
stableCount++;
|
|
79
137
|
if (stableCount >= frames) {
|
|
@@ -91,76 +149,269 @@ async function waitForIdle(page, options = {}) {
|
|
|
91
149
|
},
|
|
92
150
|
[idleFrames, timeout]
|
|
93
151
|
);
|
|
152
|
+
if (typeof settled === "string") {
|
|
153
|
+
throw new Error(`waitForIdle failed: ${settled}`);
|
|
154
|
+
}
|
|
94
155
|
if (!settled) {
|
|
95
156
|
throw new Error(`waitForIdle timed out after ${timeout}ms`);
|
|
96
157
|
}
|
|
97
158
|
}
|
|
98
|
-
async function
|
|
99
|
-
|
|
159
|
+
async function waitForNewObject(page, options = {}) {
|
|
160
|
+
const {
|
|
161
|
+
type,
|
|
162
|
+
nameContains,
|
|
163
|
+
pollIntervalMs = 100,
|
|
164
|
+
timeout = 1e4
|
|
165
|
+
} = options;
|
|
166
|
+
const baselineUuids = await page.evaluate(() => {
|
|
100
167
|
const api = window.__R3F_DOM__;
|
|
101
|
-
if (!api)
|
|
102
|
-
api.
|
|
168
|
+
if (!api) return [];
|
|
169
|
+
const snap = api.snapshot();
|
|
170
|
+
const uuids = [];
|
|
171
|
+
function collect(node) {
|
|
172
|
+
uuids.push(node.uuid);
|
|
173
|
+
for (const child of node.children) {
|
|
174
|
+
collect(child);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
collect(snap.tree);
|
|
178
|
+
return uuids;
|
|
179
|
+
});
|
|
180
|
+
const deadline = Date.now() + timeout;
|
|
181
|
+
while (Date.now() < deadline) {
|
|
182
|
+
await page.waitForTimeout(pollIntervalMs);
|
|
183
|
+
const result = await page.evaluate(
|
|
184
|
+
([filterType, filterName, knownUuids]) => {
|
|
185
|
+
const api = window.__R3F_DOM__;
|
|
186
|
+
if (!api) return null;
|
|
187
|
+
const snap = api.snapshot();
|
|
188
|
+
const known = new Set(knownUuids);
|
|
189
|
+
const newObjects = [];
|
|
190
|
+
function scan(node) {
|
|
191
|
+
if (!known.has(node.uuid)) {
|
|
192
|
+
const typeMatch = !filterType || node.type === filterType;
|
|
193
|
+
const nameMatch = !filterName || node.name.includes(filterName);
|
|
194
|
+
if (typeMatch && nameMatch) {
|
|
195
|
+
newObjects.push({
|
|
196
|
+
uuid: node.uuid,
|
|
197
|
+
name: node.name,
|
|
198
|
+
type: node.type,
|
|
199
|
+
visible: node.visible,
|
|
200
|
+
testId: node.testId,
|
|
201
|
+
position: node.position,
|
|
202
|
+
rotation: node.rotation,
|
|
203
|
+
scale: node.scale
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
for (const child of node.children) {
|
|
208
|
+
scan(child);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
scan(snap.tree);
|
|
212
|
+
if (newObjects.length === 0) return null;
|
|
213
|
+
return {
|
|
214
|
+
newObjects,
|
|
215
|
+
newUuids: newObjects.map((o) => o.uuid),
|
|
216
|
+
count: newObjects.length
|
|
217
|
+
};
|
|
218
|
+
},
|
|
219
|
+
[type ?? null, nameContains ?? null, baselineUuids]
|
|
220
|
+
);
|
|
221
|
+
if (result) {
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const filterDesc = [
|
|
226
|
+
type ? `type="${type}"` : null,
|
|
227
|
+
nameContains ? `nameContains="${nameContains}"` : null
|
|
228
|
+
].filter(Boolean).join(", ");
|
|
229
|
+
throw new Error(
|
|
230
|
+
`waitForNewObject timed out after ${timeout}ms. No new objects appeared${filterDesc ? ` matching ${filterDesc}` : ""}. Baseline had ${baselineUuids.length} objects.`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/interactions.ts
|
|
235
|
+
var DEFAULT_AUTO_WAIT_TIMEOUT = 5e3;
|
|
236
|
+
var AUTO_WAIT_POLL_MS = 100;
|
|
237
|
+
async function autoWaitForObject(page, idOrUuid, timeout = DEFAULT_AUTO_WAIT_TIMEOUT) {
|
|
238
|
+
const deadline = Date.now() + timeout;
|
|
239
|
+
while (Date.now() < deadline) {
|
|
240
|
+
const state = await page.evaluate(
|
|
241
|
+
(id) => {
|
|
242
|
+
const api = window.__R3F_DOM__;
|
|
243
|
+
if (!api) return { bridge: "missing" };
|
|
244
|
+
if (!api._ready) {
|
|
245
|
+
return {
|
|
246
|
+
bridge: "not-ready",
|
|
247
|
+
error: api._error ?? null
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const found = (api.getByTestId(id) ?? api.getByUuid(id)) !== null;
|
|
251
|
+
return { bridge: "ready", found };
|
|
252
|
+
},
|
|
253
|
+
idOrUuid
|
|
254
|
+
);
|
|
255
|
+
if (state.bridge === "ready" && state.found) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (state.bridge === "not-ready" && state.error) {
|
|
259
|
+
throw new Error(
|
|
260
|
+
`[react-three-dom] Bridge initialization failed: ${state.error}
|
|
261
|
+
Cannot perform interaction on "${idOrUuid}".`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
await page.waitForTimeout(AUTO_WAIT_POLL_MS);
|
|
265
|
+
}
|
|
266
|
+
const finalState = await page.evaluate(
|
|
267
|
+
(id) => {
|
|
268
|
+
const api = window.__R3F_DOM__;
|
|
269
|
+
if (!api) return { bridge: false, ready: false, count: 0, error: null, found: false };
|
|
270
|
+
return {
|
|
271
|
+
bridge: true,
|
|
272
|
+
ready: api._ready,
|
|
273
|
+
count: api.getCount(),
|
|
274
|
+
error: api._error ?? null,
|
|
275
|
+
found: (api.getByTestId(id) ?? api.getByUuid(id)) !== null
|
|
276
|
+
};
|
|
277
|
+
},
|
|
278
|
+
idOrUuid
|
|
279
|
+
);
|
|
280
|
+
if (!finalState.bridge) {
|
|
281
|
+
throw new Error(
|
|
282
|
+
`[react-three-dom] Auto-wait timed out after ${timeout}ms: bridge not found.
|
|
283
|
+
Ensure <ThreeDom> is mounted inside your <Canvas> component.`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
throw new Error(
|
|
287
|
+
`[react-three-dom] Auto-wait timed out after ${timeout}ms: object "${idOrUuid}" not found.
|
|
288
|
+
Bridge: ready=${finalState.ready}, objectCount=${finalState.count}` + (finalState.error ? `, error=${finalState.error}` : "") + `.
|
|
289
|
+
Ensure the object has userData.testId="${idOrUuid}" or uuid="${idOrUuid}".`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
async function autoWaitForBridge(page, timeout = DEFAULT_AUTO_WAIT_TIMEOUT) {
|
|
293
|
+
const deadline = Date.now() + timeout;
|
|
294
|
+
while (Date.now() < deadline) {
|
|
295
|
+
const state = await page.evaluate(() => {
|
|
296
|
+
const api = window.__R3F_DOM__;
|
|
297
|
+
if (!api) return { exists: false };
|
|
298
|
+
return {
|
|
299
|
+
exists: true,
|
|
300
|
+
ready: api._ready,
|
|
301
|
+
error: api._error ?? null
|
|
302
|
+
};
|
|
303
|
+
});
|
|
304
|
+
if (state.exists && state.ready) return;
|
|
305
|
+
if (state.exists && !state.ready && state.error) {
|
|
306
|
+
throw new Error(
|
|
307
|
+
`[react-three-dom] Bridge initialization failed: ${state.error}`
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
await page.waitForTimeout(AUTO_WAIT_POLL_MS);
|
|
311
|
+
}
|
|
312
|
+
throw new Error(
|
|
313
|
+
`[react-three-dom] Auto-wait timed out after ${timeout}ms: bridge not ready.
|
|
314
|
+
Ensure <ThreeDom> is mounted inside your <Canvas> component.`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
async function click(page, idOrUuid, timeout) {
|
|
318
|
+
await autoWaitForObject(page, idOrUuid, timeout);
|
|
319
|
+
await page.evaluate((id) => {
|
|
320
|
+
window.__R3F_DOM__.click(id);
|
|
103
321
|
}, idOrUuid);
|
|
104
322
|
}
|
|
105
|
-
async function doubleClick(page, idOrUuid) {
|
|
323
|
+
async function doubleClick(page, idOrUuid, timeout) {
|
|
324
|
+
await autoWaitForObject(page, idOrUuid, timeout);
|
|
106
325
|
await page.evaluate((id) => {
|
|
107
|
-
|
|
108
|
-
if (!api) throw new Error("react-three-dom bridge not found. Is <ThreeDom> mounted?");
|
|
109
|
-
api.doubleClick(id);
|
|
326
|
+
window.__R3F_DOM__.doubleClick(id);
|
|
110
327
|
}, idOrUuid);
|
|
111
328
|
}
|
|
112
|
-
async function contextMenu(page, idOrUuid) {
|
|
329
|
+
async function contextMenu(page, idOrUuid, timeout) {
|
|
330
|
+
await autoWaitForObject(page, idOrUuid, timeout);
|
|
113
331
|
await page.evaluate((id) => {
|
|
114
|
-
|
|
115
|
-
if (!api) throw new Error("react-three-dom bridge not found. Is <ThreeDom> mounted?");
|
|
116
|
-
api.contextMenu(id);
|
|
332
|
+
window.__R3F_DOM__.contextMenu(id);
|
|
117
333
|
}, idOrUuid);
|
|
118
334
|
}
|
|
119
|
-
async function hover(page, idOrUuid) {
|
|
335
|
+
async function hover(page, idOrUuid, timeout) {
|
|
336
|
+
await autoWaitForObject(page, idOrUuid, timeout);
|
|
120
337
|
await page.evaluate((id) => {
|
|
121
|
-
|
|
122
|
-
if (!api) throw new Error("react-three-dom bridge not found. Is <ThreeDom> mounted?");
|
|
123
|
-
api.hover(id);
|
|
338
|
+
window.__R3F_DOM__.hover(id);
|
|
124
339
|
}, idOrUuid);
|
|
125
340
|
}
|
|
126
|
-
async function drag(page, idOrUuid, delta) {
|
|
341
|
+
async function drag(page, idOrUuid, delta, timeout) {
|
|
342
|
+
await autoWaitForObject(page, idOrUuid, timeout);
|
|
127
343
|
await page.evaluate(
|
|
128
|
-
([id, d]) => {
|
|
129
|
-
|
|
130
|
-
if (!api) throw new Error("react-three-dom bridge not found. Is <ThreeDom> mounted?");
|
|
131
|
-
api.drag(id, d);
|
|
344
|
+
async ([id, d]) => {
|
|
345
|
+
await window.__R3F_DOM__.drag(id, d);
|
|
132
346
|
},
|
|
133
347
|
[idOrUuid, delta]
|
|
134
348
|
);
|
|
135
349
|
}
|
|
136
|
-
async function wheel(page, idOrUuid, options) {
|
|
350
|
+
async function wheel(page, idOrUuid, options, timeout) {
|
|
351
|
+
await autoWaitForObject(page, idOrUuid, timeout);
|
|
137
352
|
await page.evaluate(
|
|
138
353
|
([id, opts]) => {
|
|
139
|
-
|
|
140
|
-
if (!api) throw new Error("react-three-dom bridge not found. Is <ThreeDom> mounted?");
|
|
141
|
-
api.wheel(id, opts);
|
|
354
|
+
window.__R3F_DOM__.wheel(id, opts);
|
|
142
355
|
},
|
|
143
356
|
[idOrUuid, options]
|
|
144
357
|
);
|
|
145
358
|
}
|
|
146
|
-
async function pointerMiss(page) {
|
|
359
|
+
async function pointerMiss(page, timeout) {
|
|
360
|
+
await autoWaitForBridge(page, timeout);
|
|
147
361
|
await page.evaluate(() => {
|
|
148
|
-
|
|
149
|
-
if (!api) throw new Error("react-three-dom bridge not found. Is <ThreeDom> mounted?");
|
|
150
|
-
api.pointerMiss();
|
|
362
|
+
window.__R3F_DOM__.pointerMiss();
|
|
151
363
|
});
|
|
152
364
|
}
|
|
365
|
+
async function drawPathOnCanvas(page, points, options, timeout) {
|
|
366
|
+
await autoWaitForBridge(page, timeout);
|
|
367
|
+
return page.evaluate(
|
|
368
|
+
async ([pts, opts]) => {
|
|
369
|
+
return window.__R3F_DOM__.drawPath(pts, opts ?? void 0);
|
|
370
|
+
},
|
|
371
|
+
[points, options ?? null]
|
|
372
|
+
);
|
|
373
|
+
}
|
|
153
374
|
|
|
154
375
|
// src/fixtures.ts
|
|
155
376
|
var R3FFixture = class {
|
|
156
|
-
constructor(_page) {
|
|
377
|
+
constructor(_page, opts) {
|
|
157
378
|
this._page = _page;
|
|
379
|
+
this._debugListenerAttached = false;
|
|
380
|
+
if (opts?.debug) {
|
|
381
|
+
this._attachDebugListener();
|
|
382
|
+
}
|
|
158
383
|
}
|
|
159
384
|
/** The underlying Playwright Page. */
|
|
160
385
|
get page() {
|
|
161
386
|
return this._page;
|
|
162
387
|
}
|
|
163
388
|
// -----------------------------------------------------------------------
|
|
389
|
+
// Debug logging
|
|
390
|
+
// -----------------------------------------------------------------------
|
|
391
|
+
/**
|
|
392
|
+
* Enable debug logging. Turns on `window.__R3F_DOM_DEBUG__` in the browser
|
|
393
|
+
* and forwards all `[r3f-dom:*]` console messages to the Node.js test terminal.
|
|
394
|
+
*
|
|
395
|
+
* Call before `page.goto()` to capture setup logs, or after to capture
|
|
396
|
+
* interaction logs.
|
|
397
|
+
*/
|
|
398
|
+
async enableDebug() {
|
|
399
|
+
this._attachDebugListener();
|
|
400
|
+
await this._page.evaluate(() => {
|
|
401
|
+
window.__R3F_DOM_DEBUG__ = true;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
_attachDebugListener() {
|
|
405
|
+
if (this._debugListenerAttached) return;
|
|
406
|
+
this._debugListenerAttached = true;
|
|
407
|
+
this._page.on("console", (msg) => {
|
|
408
|
+
const text = msg.text();
|
|
409
|
+
if (text.startsWith("[r3f-dom:")) {
|
|
410
|
+
console.log(text);
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
// -----------------------------------------------------------------------
|
|
164
415
|
// Queries
|
|
165
416
|
// -----------------------------------------------------------------------
|
|
166
417
|
/** Get object metadata by testId or uuid. Returns null if not found. */
|
|
@@ -193,36 +444,153 @@ var R3FFixture = class {
|
|
|
193
444
|
return api ? api.getCount() : 0;
|
|
194
445
|
});
|
|
195
446
|
}
|
|
447
|
+
/**
|
|
448
|
+
* Get all objects of a given Three.js type (e.g. "Mesh", "Group", "Line").
|
|
449
|
+
* Useful for BIM/CAD apps to find all walls, doors, etc. by object type.
|
|
450
|
+
*/
|
|
451
|
+
async getByType(type) {
|
|
452
|
+
return this._page.evaluate((t) => {
|
|
453
|
+
const api = window.__R3F_DOM__;
|
|
454
|
+
return api ? api.getByType(t) : [];
|
|
455
|
+
}, type);
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Get objects that have a specific userData key (and optionally matching value).
|
|
459
|
+
* Useful for BIM/CAD apps where objects are tagged with metadata like
|
|
460
|
+
* `userData.category = "wall"` or `userData.floorId = 2`.
|
|
461
|
+
*/
|
|
462
|
+
async getByUserData(key, value) {
|
|
463
|
+
return this._page.evaluate(({ k, v }) => {
|
|
464
|
+
const api = window.__R3F_DOM__;
|
|
465
|
+
return api ? api.getByUserData(k, v) : [];
|
|
466
|
+
}, { k: key, v: value });
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Count objects of a given Three.js type.
|
|
470
|
+
* More efficient than `getByType(type).then(arr => arr.length)`.
|
|
471
|
+
*/
|
|
472
|
+
async getCountByType(type) {
|
|
473
|
+
return this._page.evaluate((t) => {
|
|
474
|
+
const api = window.__R3F_DOM__;
|
|
475
|
+
return api ? api.getCountByType(t) : 0;
|
|
476
|
+
}, type);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Batch lookup: get metadata for multiple objects by testId or uuid in a
|
|
480
|
+
* single browser round-trip. Returns a record from id to metadata (or null).
|
|
481
|
+
*
|
|
482
|
+
* Much more efficient than calling `getObject()` in a loop for BIM/CAD
|
|
483
|
+
* scenes with many objects.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```typescript
|
|
487
|
+
* const results = await r3f.getObjects(['wall-1', 'door-2', 'window-3']);
|
|
488
|
+
* expect(results['wall-1']).not.toBeNull();
|
|
489
|
+
* expect(results['door-2']?.type).toBe('Mesh');
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
async getObjects(ids) {
|
|
493
|
+
return this._page.evaluate((idList) => {
|
|
494
|
+
const api = window.__R3F_DOM__;
|
|
495
|
+
if (!api) {
|
|
496
|
+
const result = {};
|
|
497
|
+
for (const id of idList) result[id] = null;
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
return api.getObjects(idList);
|
|
501
|
+
}, ids);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Log the scene tree to the test terminal for debugging.
|
|
505
|
+
*
|
|
506
|
+
* Prints a human-readable tree like:
|
|
507
|
+
* ```
|
|
508
|
+
* Scene "root"
|
|
509
|
+
* ├─ Mesh "chair-primary" [testId: chair-primary] visible
|
|
510
|
+
* │ └─ BoxGeometry
|
|
511
|
+
* ├─ DirectionalLight "sun-light" [testId: sun-light] visible
|
|
512
|
+
* └─ Group "furniture"
|
|
513
|
+
* ├─ Mesh "table-top" [testId: table-top] visible
|
|
514
|
+
* └─ Mesh "vase" [testId: vase] visible
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
async logScene() {
|
|
518
|
+
const snap = await this.snapshot();
|
|
519
|
+
if (!snap) {
|
|
520
|
+
console.log("[r3f-dom] logScene: no scene snapshot available (bridge not ready?)");
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const lines = formatSceneTree(snap.tree);
|
|
524
|
+
console.log(`
|
|
525
|
+
[r3f-dom] Scene tree (${snap.objectCount} objects):
|
|
526
|
+
${lines}
|
|
527
|
+
`);
|
|
528
|
+
}
|
|
196
529
|
// -----------------------------------------------------------------------
|
|
197
530
|
// Interactions
|
|
198
531
|
// -----------------------------------------------------------------------
|
|
199
|
-
/**
|
|
200
|
-
|
|
201
|
-
|
|
532
|
+
/**
|
|
533
|
+
* Click a 3D object by testId or uuid.
|
|
534
|
+
* Auto-waits for the bridge and the object to exist before clicking.
|
|
535
|
+
* @param timeout Optional auto-wait timeout in ms. Default: 5000
|
|
536
|
+
*/
|
|
537
|
+
async click(idOrUuid, timeout) {
|
|
538
|
+
return click(this._page, idOrUuid, timeout);
|
|
202
539
|
}
|
|
203
|
-
/**
|
|
204
|
-
|
|
205
|
-
|
|
540
|
+
/**
|
|
541
|
+
* Double-click a 3D object by testId or uuid.
|
|
542
|
+
* Auto-waits for the object to exist.
|
|
543
|
+
*/
|
|
544
|
+
async doubleClick(idOrUuid, timeout) {
|
|
545
|
+
return doubleClick(this._page, idOrUuid, timeout);
|
|
206
546
|
}
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
|
|
547
|
+
/**
|
|
548
|
+
* Right-click / context-menu a 3D object by testId or uuid.
|
|
549
|
+
* Auto-waits for the object to exist.
|
|
550
|
+
*/
|
|
551
|
+
async contextMenu(idOrUuid, timeout) {
|
|
552
|
+
return contextMenu(this._page, idOrUuid, timeout);
|
|
210
553
|
}
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
554
|
+
/**
|
|
555
|
+
* Hover over a 3D object by testId or uuid.
|
|
556
|
+
* Auto-waits for the object to exist.
|
|
557
|
+
*/
|
|
558
|
+
async hover(idOrUuid, timeout) {
|
|
559
|
+
return hover(this._page, idOrUuid, timeout);
|
|
214
560
|
}
|
|
215
|
-
/**
|
|
216
|
-
|
|
217
|
-
|
|
561
|
+
/**
|
|
562
|
+
* Drag a 3D object with a world-space delta vector.
|
|
563
|
+
* Auto-waits for the object to exist.
|
|
564
|
+
*/
|
|
565
|
+
async drag(idOrUuid, delta, timeout) {
|
|
566
|
+
return drag(this._page, idOrUuid, delta, timeout);
|
|
218
567
|
}
|
|
219
|
-
/**
|
|
220
|
-
|
|
221
|
-
|
|
568
|
+
/**
|
|
569
|
+
* Dispatch a wheel/scroll event on a 3D object.
|
|
570
|
+
* Auto-waits for the object to exist.
|
|
571
|
+
*/
|
|
572
|
+
async wheel(idOrUuid, options, timeout) {
|
|
573
|
+
return wheel(this._page, idOrUuid, options, timeout);
|
|
222
574
|
}
|
|
223
|
-
/**
|
|
224
|
-
|
|
225
|
-
|
|
575
|
+
/**
|
|
576
|
+
* Click empty space to trigger onPointerMissed handlers.
|
|
577
|
+
* Auto-waits for the bridge to be ready.
|
|
578
|
+
*/
|
|
579
|
+
async pointerMiss(timeout) {
|
|
580
|
+
return pointerMiss(this._page, timeout);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Draw a freeform path on the canvas. Dispatches pointerdown → N × pointermove → pointerup.
|
|
584
|
+
* Designed for canvas drawing/annotation/whiteboard apps.
|
|
585
|
+
* Auto-waits for the bridge to be ready.
|
|
586
|
+
*
|
|
587
|
+
* @param points Array of screen-space points (min 2). { x, y } in CSS pixels relative to canvas.
|
|
588
|
+
* @param options Drawing options (stepDelayMs, pointerType, clickAtEnd)
|
|
589
|
+
* @param timeout Optional auto-wait timeout in ms. Default: 5000
|
|
590
|
+
* @returns { eventCount, pointCount }
|
|
591
|
+
*/
|
|
592
|
+
async drawPath(points, options, timeout) {
|
|
593
|
+
return drawPathOnCanvas(this._page, points, options, timeout);
|
|
226
594
|
}
|
|
227
595
|
// -----------------------------------------------------------------------
|
|
228
596
|
// Waiters
|
|
@@ -249,6 +617,17 @@ var R3FFixture = class {
|
|
|
249
617
|
async waitForIdle(options) {
|
|
250
618
|
return waitForIdle(this._page, options);
|
|
251
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* Wait until one or more new objects appear in the scene that were not
|
|
622
|
+
* present when this call was made. Perfect for drawing apps where
|
|
623
|
+
* `drawPath()` creates new geometry asynchronously.
|
|
624
|
+
*
|
|
625
|
+
* @param options Filter by type, nameContains, timeout, pollInterval
|
|
626
|
+
* @returns Metadata of the newly added object(s)
|
|
627
|
+
*/
|
|
628
|
+
async waitForNewObject(options) {
|
|
629
|
+
return waitForNewObject(this._page, options);
|
|
630
|
+
}
|
|
252
631
|
// -----------------------------------------------------------------------
|
|
253
632
|
// Selection (for inspector integration)
|
|
254
633
|
// -----------------------------------------------------------------------
|
|
@@ -268,145 +647,879 @@ var R3FFixture = class {
|
|
|
268
647
|
});
|
|
269
648
|
}
|
|
270
649
|
};
|
|
650
|
+
function formatSceneTree(node, prefix = "", isLast = true) {
|
|
651
|
+
const connector = prefix === "" ? "" : isLast ? "\u2514\u2500 " : "\u251C\u2500 ";
|
|
652
|
+
const childPrefix = prefix === "" ? "" : prefix + (isLast ? " " : "\u2502 ");
|
|
653
|
+
let label = node.type;
|
|
654
|
+
if (node.name) label += ` "${node.name}"`;
|
|
655
|
+
if (node.testId) label += ` [testId: ${node.testId}]`;
|
|
656
|
+
label += node.visible ? " visible" : " HIDDEN";
|
|
657
|
+
let result = prefix + connector + label + "\n";
|
|
658
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
659
|
+
const child = node.children[i];
|
|
660
|
+
const last = i === node.children.length - 1;
|
|
661
|
+
result += formatSceneTree(child, childPrefix, last);
|
|
662
|
+
}
|
|
663
|
+
return result;
|
|
664
|
+
}
|
|
271
665
|
var test = test$1.extend({
|
|
272
666
|
r3f: async ({ page }, use) => {
|
|
273
667
|
const fixture = new R3FFixture(page);
|
|
274
668
|
await use(fixture);
|
|
275
669
|
}
|
|
276
670
|
});
|
|
671
|
+
function createR3FTest(options) {
|
|
672
|
+
return test$1.extend({
|
|
673
|
+
r3f: async ({ page }, use) => {
|
|
674
|
+
const fixture = new R3FFixture(page, options);
|
|
675
|
+
await use(fixture);
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
var DEFAULT_TIMEOUT = 5e3;
|
|
680
|
+
var DEFAULT_INTERVAL = 100;
|
|
681
|
+
async function fetchSceneCount(page) {
|
|
682
|
+
return page.evaluate(() => {
|
|
683
|
+
const api = window.__R3F_DOM__;
|
|
684
|
+
return api ? api.getCount() : 0;
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
async function fetchCountByType(page, type) {
|
|
688
|
+
return page.evaluate((t) => {
|
|
689
|
+
const api = window.__R3F_DOM__;
|
|
690
|
+
return api ? api.getCountByType(t) : 0;
|
|
691
|
+
}, type);
|
|
692
|
+
}
|
|
693
|
+
async function fetchTotalTriangles(page) {
|
|
694
|
+
return page.evaluate(() => {
|
|
695
|
+
const api = window.__R3F_DOM__;
|
|
696
|
+
if (!api) return 0;
|
|
697
|
+
const bridge = api;
|
|
698
|
+
const snap = bridge.snapshot();
|
|
699
|
+
let total = 0;
|
|
700
|
+
function walk(node) {
|
|
701
|
+
const meta = bridge.getByUuid(node.uuid);
|
|
702
|
+
if (meta && meta.triangleCount) total += meta.triangleCount;
|
|
703
|
+
for (const child of node.children) {
|
|
704
|
+
walk(child);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
walk(snap.tree);
|
|
708
|
+
return total;
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
async function fetchMeta(page, id) {
|
|
712
|
+
return page.evaluate((i) => {
|
|
713
|
+
const api = window.__R3F_DOM__;
|
|
714
|
+
if (!api) return null;
|
|
715
|
+
return api.getByTestId(i) ?? api.getByUuid(i) ?? null;
|
|
716
|
+
}, id);
|
|
717
|
+
}
|
|
718
|
+
async function fetchInsp(page, id) {
|
|
719
|
+
return page.evaluate((i) => {
|
|
720
|
+
const api = window.__R3F_DOM__;
|
|
721
|
+
if (!api) return null;
|
|
722
|
+
return api.inspect(i);
|
|
723
|
+
}, id);
|
|
724
|
+
}
|
|
725
|
+
function parseTol(v, def) {
|
|
726
|
+
const o = typeof v === "number" ? { tolerance: v } : v ?? {};
|
|
727
|
+
return {
|
|
728
|
+
timeout: o.timeout ?? DEFAULT_TIMEOUT,
|
|
729
|
+
interval: o.interval ?? DEFAULT_INTERVAL,
|
|
730
|
+
tolerance: o.tolerance ?? def
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function notFound(name, id, detail, timeout) {
|
|
734
|
+
return {
|
|
735
|
+
pass: false,
|
|
736
|
+
message: () => `Expected object "${id}" ${detail}, but it was not found (waited ${timeout}ms)`,
|
|
737
|
+
name
|
|
738
|
+
};
|
|
739
|
+
}
|
|
277
740
|
var expect = expect$1.extend({
|
|
278
|
-
//
|
|
279
|
-
// toExist
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
741
|
+
// ========================= TIER 1 — Metadata ============================
|
|
742
|
+
// --- toExist ---
|
|
743
|
+
async toExist(r3f, id, opts) {
|
|
744
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
745
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
746
|
+
const isNot = this.isNot;
|
|
747
|
+
let meta = null;
|
|
748
|
+
try {
|
|
749
|
+
await expect$1.poll(async () => {
|
|
750
|
+
meta = await fetchMeta(r3f.page, id);
|
|
751
|
+
return meta !== null;
|
|
752
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
753
|
+
} catch {
|
|
754
|
+
}
|
|
283
755
|
const pass = meta !== null;
|
|
284
756
|
return {
|
|
285
757
|
pass,
|
|
286
|
-
message: () => pass ? `Expected object "${
|
|
758
|
+
message: () => pass ? `Expected object "${id}" to NOT exist, but it does` : `Expected object "${id}" to exist, but it was not found (waited ${timeout}ms)`,
|
|
287
759
|
name: "toExist",
|
|
288
|
-
expected:
|
|
760
|
+
expected: id,
|
|
289
761
|
actual: meta
|
|
290
762
|
};
|
|
291
763
|
},
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
};
|
|
764
|
+
// --- toBeVisible ---
|
|
765
|
+
async toBeVisible(r3f, id, opts) {
|
|
766
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
767
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
768
|
+
const isNot = this.isNot;
|
|
769
|
+
let meta = null;
|
|
770
|
+
try {
|
|
771
|
+
await expect$1.poll(async () => {
|
|
772
|
+
meta = await fetchMeta(r3f.page, id);
|
|
773
|
+
return meta?.visible ?? false;
|
|
774
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
775
|
+
} catch {
|
|
303
776
|
}
|
|
304
|
-
|
|
777
|
+
if (!meta) return notFound("toBeVisible", id, "to be visible", timeout);
|
|
778
|
+
const m = meta;
|
|
305
779
|
return {
|
|
306
|
-
pass,
|
|
307
|
-
message: () =>
|
|
780
|
+
pass: m.visible,
|
|
781
|
+
message: () => m.visible ? `Expected "${id}" to NOT be visible, but it is` : `Expected "${id}" to be visible, but visible=${m.visible} (waited ${timeout}ms)`,
|
|
308
782
|
name: "toBeVisible",
|
|
309
783
|
expected: true,
|
|
310
|
-
actual:
|
|
784
|
+
actual: m.visible
|
|
311
785
|
};
|
|
312
786
|
},
|
|
313
|
-
//
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
787
|
+
// --- toHavePosition ---
|
|
788
|
+
async toHavePosition(r3f, id, expected, tolOpts) {
|
|
789
|
+
const { timeout, interval, tolerance } = parseTol(tolOpts, 0.01);
|
|
790
|
+
const isNot = this.isNot;
|
|
791
|
+
let meta = null;
|
|
792
|
+
let pass = false;
|
|
793
|
+
let delta = [0, 0, 0];
|
|
794
|
+
try {
|
|
795
|
+
await expect$1.poll(async () => {
|
|
796
|
+
meta = await fetchMeta(r3f.page, id);
|
|
797
|
+
if (!meta) return false;
|
|
798
|
+
delta = [Math.abs(meta.position[0] - expected[0]), Math.abs(meta.position[1] - expected[1]), Math.abs(meta.position[2] - expected[2])];
|
|
799
|
+
pass = delta.every((d) => d <= tolerance);
|
|
800
|
+
return pass;
|
|
801
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
802
|
+
} catch {
|
|
325
803
|
}
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
const pass = isFinite(bounds.min) && isFinite(bounds.max);
|
|
804
|
+
if (!meta) return notFound("toHavePosition", id, `to have position [${expected}]`, timeout);
|
|
805
|
+
const m = meta;
|
|
329
806
|
return {
|
|
330
807
|
pass,
|
|
331
|
-
message: () => pass ? `Expected
|
|
332
|
-
name: "
|
|
333
|
-
expected
|
|
334
|
-
actual:
|
|
808
|
+
message: () => pass ? `Expected "${id}" to NOT be at [${expected}] (\xB1${tolerance})` : `Expected "${id}" at [${expected}] (\xB1${tolerance}), got [${m.position}] (\u0394 [${delta.map((d) => d.toFixed(4))}]) (waited ${timeout}ms)`,
|
|
809
|
+
name: "toHavePosition",
|
|
810
|
+
expected,
|
|
811
|
+
actual: m.position
|
|
335
812
|
};
|
|
336
813
|
},
|
|
337
|
-
//
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
814
|
+
// --- toHaveRotation ---
|
|
815
|
+
async toHaveRotation(r3f, id, expected, tolOpts) {
|
|
816
|
+
const { timeout, interval, tolerance } = parseTol(tolOpts, 0.01);
|
|
817
|
+
const isNot = this.isNot;
|
|
818
|
+
let meta = null;
|
|
819
|
+
let pass = false;
|
|
820
|
+
let delta = [0, 0, 0];
|
|
821
|
+
try {
|
|
822
|
+
await expect$1.poll(async () => {
|
|
823
|
+
meta = await fetchMeta(r3f.page, id);
|
|
824
|
+
if (!meta) return false;
|
|
825
|
+
delta = [Math.abs(meta.rotation[0] - expected[0]), Math.abs(meta.rotation[1] - expected[1]), Math.abs(meta.rotation[2] - expected[2])];
|
|
826
|
+
pass = delta.every((d) => d <= tolerance);
|
|
827
|
+
return pass;
|
|
828
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
829
|
+
} catch {
|
|
348
830
|
}
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
const dx = Math.abs(ax - ex);
|
|
352
|
-
const dy = Math.abs(ay - ey);
|
|
353
|
-
const dz = Math.abs(az - ez);
|
|
354
|
-
const pass = dx <= tolerance && dy <= tolerance && dz <= tolerance;
|
|
831
|
+
if (!meta) return notFound("toHaveRotation", id, `to have rotation [${expected}]`, timeout);
|
|
832
|
+
const m = meta;
|
|
355
833
|
return {
|
|
356
834
|
pass,
|
|
357
|
-
message: () => pass ? `Expected
|
|
358
|
-
name: "
|
|
835
|
+
message: () => pass ? `Expected "${id}" to NOT have rotation [${expected}] (\xB1${tolerance})` : `Expected "${id}" rotation [${expected}] (\xB1${tolerance}), got [${m.rotation}] (\u0394 [${delta.map((d) => d.toFixed(4))}]) (waited ${timeout}ms)`,
|
|
836
|
+
name: "toHaveRotation",
|
|
359
837
|
expected,
|
|
360
|
-
actual:
|
|
838
|
+
actual: m.rotation
|
|
361
839
|
};
|
|
362
840
|
},
|
|
363
|
-
//
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
841
|
+
// --- toHaveScale ---
|
|
842
|
+
async toHaveScale(r3f, id, expected, tolOpts) {
|
|
843
|
+
const { timeout, interval, tolerance } = parseTol(tolOpts, 0.01);
|
|
844
|
+
const isNot = this.isNot;
|
|
845
|
+
let meta = null;
|
|
846
|
+
let pass = false;
|
|
847
|
+
let delta = [0, 0, 0];
|
|
848
|
+
try {
|
|
849
|
+
await expect$1.poll(async () => {
|
|
850
|
+
meta = await fetchMeta(r3f.page, id);
|
|
851
|
+
if (!meta) return false;
|
|
852
|
+
delta = [Math.abs(meta.scale[0] - expected[0]), Math.abs(meta.scale[1] - expected[1]), Math.abs(meta.scale[2] - expected[2])];
|
|
853
|
+
pass = delta.every((d) => d <= tolerance);
|
|
854
|
+
return pass;
|
|
855
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
856
|
+
} catch {
|
|
374
857
|
}
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
const pass = withinTolerance(bounds.min, expected.min) && withinTolerance(bounds.max, expected.max);
|
|
858
|
+
if (!meta) return notFound("toHaveScale", id, `to have scale [${expected}]`, timeout);
|
|
859
|
+
const m = meta;
|
|
378
860
|
return {
|
|
379
861
|
pass,
|
|
380
|
-
message: () => pass ? `Expected
|
|
381
|
-
name: "
|
|
862
|
+
message: () => pass ? `Expected "${id}" to NOT have scale [${expected}] (\xB1${tolerance})` : `Expected "${id}" scale [${expected}] (\xB1${tolerance}), got [${m.scale}] (\u0394 [${delta.map((d) => d.toFixed(4))}]) (waited ${timeout}ms)`,
|
|
863
|
+
name: "toHaveScale",
|
|
382
864
|
expected,
|
|
383
|
-
actual:
|
|
865
|
+
actual: m.scale
|
|
384
866
|
};
|
|
385
867
|
},
|
|
386
|
-
//
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
868
|
+
// --- toHaveType ---
|
|
869
|
+
async toHaveType(r3f, id, expectedType, opts) {
|
|
870
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
871
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
872
|
+
const isNot = this.isNot;
|
|
873
|
+
let meta = null;
|
|
874
|
+
let pass = false;
|
|
875
|
+
try {
|
|
876
|
+
await expect$1.poll(async () => {
|
|
877
|
+
meta = await fetchMeta(r3f.page, id);
|
|
878
|
+
if (!meta) return false;
|
|
879
|
+
pass = meta.type === expectedType;
|
|
880
|
+
return pass;
|
|
881
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
882
|
+
} catch {
|
|
883
|
+
}
|
|
884
|
+
if (!meta) return notFound("toHaveType", id, `to have type "${expectedType}"`, timeout);
|
|
885
|
+
const m = meta;
|
|
886
|
+
return {
|
|
887
|
+
pass,
|
|
888
|
+
message: () => pass ? `Expected "${id}" to NOT have type "${expectedType}"` : `Expected "${id}" type "${expectedType}", got "${m.type}" (waited ${timeout}ms)`,
|
|
889
|
+
name: "toHaveType",
|
|
890
|
+
expected: expectedType,
|
|
891
|
+
actual: m.type
|
|
892
|
+
};
|
|
893
|
+
},
|
|
894
|
+
// --- toHaveName ---
|
|
895
|
+
async toHaveName(r3f, id, expectedName, opts) {
|
|
896
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
897
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
898
|
+
const isNot = this.isNot;
|
|
899
|
+
let meta = null;
|
|
900
|
+
let pass = false;
|
|
901
|
+
try {
|
|
902
|
+
await expect$1.poll(async () => {
|
|
903
|
+
meta = await fetchMeta(r3f.page, id);
|
|
904
|
+
if (!meta) return false;
|
|
905
|
+
pass = meta.name === expectedName;
|
|
906
|
+
return pass;
|
|
907
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
908
|
+
} catch {
|
|
909
|
+
}
|
|
910
|
+
if (!meta) return notFound("toHaveName", id, `to have name "${expectedName}"`, timeout);
|
|
911
|
+
const m = meta;
|
|
912
|
+
return {
|
|
913
|
+
pass,
|
|
914
|
+
message: () => pass ? `Expected "${id}" to NOT have name "${expectedName}"` : `Expected "${id}" name "${expectedName}", got "${m.name}" (waited ${timeout}ms)`,
|
|
915
|
+
name: "toHaveName",
|
|
916
|
+
expected: expectedName,
|
|
917
|
+
actual: m.name
|
|
918
|
+
};
|
|
919
|
+
},
|
|
920
|
+
// --- toHaveGeometryType ---
|
|
921
|
+
async toHaveGeometryType(r3f, id, expectedGeo, opts) {
|
|
922
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
923
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
924
|
+
const isNot = this.isNot;
|
|
925
|
+
let meta = null;
|
|
926
|
+
let pass = false;
|
|
927
|
+
try {
|
|
928
|
+
await expect$1.poll(async () => {
|
|
929
|
+
meta = await fetchMeta(r3f.page, id);
|
|
930
|
+
if (!meta) return false;
|
|
931
|
+
pass = meta.geometryType === expectedGeo;
|
|
932
|
+
return pass;
|
|
933
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
934
|
+
} catch {
|
|
935
|
+
}
|
|
936
|
+
if (!meta) return notFound("toHaveGeometryType", id, `to have geometry "${expectedGeo}"`, timeout);
|
|
937
|
+
const m = meta;
|
|
938
|
+
return {
|
|
939
|
+
pass,
|
|
940
|
+
message: () => pass ? `Expected "${id}" to NOT have geometry "${expectedGeo}"` : `Expected "${id}" geometry "${expectedGeo}", got "${m.geometryType ?? "none"}" (waited ${timeout}ms)`,
|
|
941
|
+
name: "toHaveGeometryType",
|
|
942
|
+
expected: expectedGeo,
|
|
943
|
+
actual: m.geometryType
|
|
944
|
+
};
|
|
945
|
+
},
|
|
946
|
+
// --- toHaveMaterialType ---
|
|
947
|
+
async toHaveMaterialType(r3f, id, expectedMat, opts) {
|
|
948
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
949
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
950
|
+
const isNot = this.isNot;
|
|
951
|
+
let meta = null;
|
|
952
|
+
let pass = false;
|
|
953
|
+
try {
|
|
954
|
+
await expect$1.poll(async () => {
|
|
955
|
+
meta = await fetchMeta(r3f.page, id);
|
|
956
|
+
if (!meta) return false;
|
|
957
|
+
pass = meta.materialType === expectedMat;
|
|
958
|
+
return pass;
|
|
959
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
960
|
+
} catch {
|
|
397
961
|
}
|
|
398
|
-
|
|
962
|
+
if (!meta) return notFound("toHaveMaterialType", id, `to have material "${expectedMat}"`, timeout);
|
|
963
|
+
const m = meta;
|
|
964
|
+
return {
|
|
965
|
+
pass,
|
|
966
|
+
message: () => pass ? `Expected "${id}" to NOT have material "${expectedMat}"` : `Expected "${id}" material "${expectedMat}", got "${m.materialType ?? "none"}" (waited ${timeout}ms)`,
|
|
967
|
+
name: "toHaveMaterialType",
|
|
968
|
+
expected: expectedMat,
|
|
969
|
+
actual: m.materialType
|
|
970
|
+
};
|
|
971
|
+
},
|
|
972
|
+
// --- toHaveChildCount ---
|
|
973
|
+
async toHaveChildCount(r3f, id, expectedCount, opts) {
|
|
974
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
975
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
976
|
+
const isNot = this.isNot;
|
|
977
|
+
let meta = null;
|
|
978
|
+
let actual = 0;
|
|
979
|
+
try {
|
|
980
|
+
await expect$1.poll(async () => {
|
|
981
|
+
meta = await fetchMeta(r3f.page, id);
|
|
982
|
+
if (!meta) return false;
|
|
983
|
+
actual = meta.childrenUuids.length;
|
|
984
|
+
return actual === expectedCount;
|
|
985
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
986
|
+
} catch {
|
|
987
|
+
}
|
|
988
|
+
if (!meta) return notFound("toHaveChildCount", id, `to have ${expectedCount} children`, timeout);
|
|
399
989
|
const pass = actual === expectedCount;
|
|
400
990
|
return {
|
|
401
991
|
pass,
|
|
402
|
-
message: () => pass ? `Expected
|
|
992
|
+
message: () => pass ? `Expected "${id}" to NOT have ${expectedCount} children` : `Expected "${id}" ${expectedCount} children, got ${actual} (waited ${timeout}ms)`,
|
|
993
|
+
name: "toHaveChildCount",
|
|
994
|
+
expected: expectedCount,
|
|
995
|
+
actual
|
|
996
|
+
};
|
|
997
|
+
},
|
|
998
|
+
// --- toHaveParent ---
|
|
999
|
+
async toHaveParent(r3f, id, expectedParent, opts) {
|
|
1000
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1001
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1002
|
+
const isNot = this.isNot;
|
|
1003
|
+
let meta = null;
|
|
1004
|
+
let parentMeta = null;
|
|
1005
|
+
let pass = false;
|
|
1006
|
+
try {
|
|
1007
|
+
await expect$1.poll(async () => {
|
|
1008
|
+
meta = await fetchMeta(r3f.page, id);
|
|
1009
|
+
if (!meta?.parentUuid) return false;
|
|
1010
|
+
parentMeta = await fetchMeta(r3f.page, meta.parentUuid);
|
|
1011
|
+
if (!parentMeta) return false;
|
|
1012
|
+
pass = parentMeta.uuid === expectedParent || parentMeta.testId === expectedParent || parentMeta.name === expectedParent;
|
|
1013
|
+
return pass;
|
|
1014
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1015
|
+
} catch {
|
|
1016
|
+
}
|
|
1017
|
+
if (!meta) return notFound("toHaveParent", id, `to have parent "${expectedParent}"`, timeout);
|
|
1018
|
+
const m = meta;
|
|
1019
|
+
const pm = parentMeta;
|
|
1020
|
+
const parentLabel = pm?.testId ?? pm?.name ?? m.parentUuid;
|
|
1021
|
+
return {
|
|
1022
|
+
pass,
|
|
1023
|
+
message: () => pass ? `Expected "${id}" to NOT have parent "${expectedParent}"` : `Expected "${id}" parent "${expectedParent}", got "${parentLabel}" (waited ${timeout}ms)`,
|
|
1024
|
+
name: "toHaveParent",
|
|
1025
|
+
expected: expectedParent,
|
|
1026
|
+
actual: parentLabel
|
|
1027
|
+
};
|
|
1028
|
+
},
|
|
1029
|
+
// --- toHaveInstanceCount ---
|
|
1030
|
+
async toHaveInstanceCount(r3f, id, expectedCount, opts) {
|
|
1031
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1032
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1033
|
+
const isNot = this.isNot;
|
|
1034
|
+
let meta = null;
|
|
1035
|
+
let actual = 0;
|
|
1036
|
+
try {
|
|
1037
|
+
await expect$1.poll(async () => {
|
|
1038
|
+
meta = await fetchMeta(r3f.page, id);
|
|
1039
|
+
actual = meta?.instanceCount ?? 0;
|
|
1040
|
+
return actual === expectedCount;
|
|
1041
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1042
|
+
} catch {
|
|
1043
|
+
}
|
|
1044
|
+
if (!meta) return notFound("toHaveInstanceCount", id, `to have instance count ${expectedCount}`, timeout);
|
|
1045
|
+
const pass = actual === expectedCount;
|
|
1046
|
+
return {
|
|
1047
|
+
pass,
|
|
1048
|
+
message: () => pass ? `Expected "${id}" to NOT have instance count ${expectedCount}` : `Expected "${id}" instance count ${expectedCount}, got ${actual} (waited ${timeout}ms)`,
|
|
403
1049
|
name: "toHaveInstanceCount",
|
|
404
1050
|
expected: expectedCount,
|
|
405
1051
|
actual
|
|
406
1052
|
};
|
|
1053
|
+
},
|
|
1054
|
+
// ========================= TIER 2 — Inspection ==========================
|
|
1055
|
+
// --- toBeInFrustum ---
|
|
1056
|
+
async toBeInFrustum(r3f, id, opts) {
|
|
1057
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1058
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1059
|
+
const isNot = this.isNot;
|
|
1060
|
+
let insp = null;
|
|
1061
|
+
let pass = false;
|
|
1062
|
+
try {
|
|
1063
|
+
await expect$1.poll(async () => {
|
|
1064
|
+
insp = await fetchInsp(r3f.page, id);
|
|
1065
|
+
if (!insp) return false;
|
|
1066
|
+
const fin = (v) => v.every(Number.isFinite);
|
|
1067
|
+
pass = fin(insp.bounds.min) && fin(insp.bounds.max);
|
|
1068
|
+
return pass;
|
|
1069
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1070
|
+
} catch {
|
|
1071
|
+
}
|
|
1072
|
+
if (!insp) return notFound("toBeInFrustum", id, "to be in frustum", timeout);
|
|
1073
|
+
const i = insp;
|
|
1074
|
+
return {
|
|
1075
|
+
pass,
|
|
1076
|
+
message: () => pass ? `Expected "${id}" to NOT be in the camera frustum` : `Expected "${id}" in frustum, but bounds are invalid (waited ${timeout}ms)`,
|
|
1077
|
+
name: "toBeInFrustum",
|
|
1078
|
+
expected: "finite bounds",
|
|
1079
|
+
actual: i.bounds
|
|
1080
|
+
};
|
|
1081
|
+
},
|
|
1082
|
+
// --- toHaveBounds ---
|
|
1083
|
+
async toHaveBounds(r3f, id, expected, tolOpts) {
|
|
1084
|
+
const { timeout, interval, tolerance } = parseTol(tolOpts, 0.1);
|
|
1085
|
+
const isNot = this.isNot;
|
|
1086
|
+
let insp = null;
|
|
1087
|
+
let pass = false;
|
|
1088
|
+
try {
|
|
1089
|
+
await expect$1.poll(async () => {
|
|
1090
|
+
insp = await fetchInsp(r3f.page, id);
|
|
1091
|
+
if (!insp) return false;
|
|
1092
|
+
const w = (a, b) => a.every((v, j) => Math.abs(v - b[j]) <= tolerance);
|
|
1093
|
+
pass = w(insp.bounds.min, expected.min) && w(insp.bounds.max, expected.max);
|
|
1094
|
+
return pass;
|
|
1095
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1096
|
+
} catch {
|
|
1097
|
+
}
|
|
1098
|
+
if (!insp) return notFound("toHaveBounds", id, "to have specific bounds", timeout);
|
|
1099
|
+
const i = insp;
|
|
1100
|
+
return {
|
|
1101
|
+
pass,
|
|
1102
|
+
message: () => pass ? `Expected "${id}" to NOT have bounds min:${JSON.stringify(expected.min)} max:${JSON.stringify(expected.max)}` : `Expected "${id}" bounds min:${JSON.stringify(expected.min)} max:${JSON.stringify(expected.max)}, got min:${JSON.stringify(i.bounds.min)} max:${JSON.stringify(i.bounds.max)} (waited ${timeout}ms)`,
|
|
1103
|
+
name: "toHaveBounds",
|
|
1104
|
+
expected,
|
|
1105
|
+
actual: i.bounds
|
|
1106
|
+
};
|
|
1107
|
+
},
|
|
1108
|
+
// --- toHaveColor ---
|
|
1109
|
+
async toHaveColor(r3f, id, expectedColor, opts) {
|
|
1110
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1111
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1112
|
+
const isNot = this.isNot;
|
|
1113
|
+
const norm = expectedColor.startsWith("#") ? expectedColor.toLowerCase() : `#${expectedColor.toLowerCase()}`;
|
|
1114
|
+
let insp = null;
|
|
1115
|
+
let actual;
|
|
1116
|
+
let pass = false;
|
|
1117
|
+
try {
|
|
1118
|
+
await expect$1.poll(async () => {
|
|
1119
|
+
insp = await fetchInsp(r3f.page, id);
|
|
1120
|
+
if (!insp?.material?.color) return false;
|
|
1121
|
+
actual = insp.material.color.toLowerCase();
|
|
1122
|
+
pass = actual === norm;
|
|
1123
|
+
return pass;
|
|
1124
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1125
|
+
} catch {
|
|
1126
|
+
}
|
|
1127
|
+
if (!insp) return notFound("toHaveColor", id, `to have color "${norm}"`, timeout);
|
|
1128
|
+
return {
|
|
1129
|
+
pass,
|
|
1130
|
+
message: () => pass ? `Expected "${id}" to NOT have color "${norm}"` : `Expected "${id}" color "${norm}", got "${actual ?? "no color"}" (waited ${timeout}ms)`,
|
|
1131
|
+
name: "toHaveColor",
|
|
1132
|
+
expected: norm,
|
|
1133
|
+
actual
|
|
1134
|
+
};
|
|
1135
|
+
},
|
|
1136
|
+
// --- toHaveOpacity ---
|
|
1137
|
+
async toHaveOpacity(r3f, id, expectedOpacity, tolOpts) {
|
|
1138
|
+
const { timeout, interval, tolerance } = parseTol(tolOpts, 0.01);
|
|
1139
|
+
const isNot = this.isNot;
|
|
1140
|
+
let insp = null;
|
|
1141
|
+
let actual;
|
|
1142
|
+
let pass = false;
|
|
1143
|
+
try {
|
|
1144
|
+
await expect$1.poll(async () => {
|
|
1145
|
+
insp = await fetchInsp(r3f.page, id);
|
|
1146
|
+
if (!insp?.material) return false;
|
|
1147
|
+
actual = insp.material.opacity;
|
|
1148
|
+
pass = actual !== void 0 && Math.abs(actual - expectedOpacity) <= tolerance;
|
|
1149
|
+
return pass;
|
|
1150
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1151
|
+
} catch {
|
|
1152
|
+
}
|
|
1153
|
+
if (!insp) return notFound("toHaveOpacity", id, `to have opacity ${expectedOpacity}`, timeout);
|
|
1154
|
+
return {
|
|
1155
|
+
pass,
|
|
1156
|
+
message: () => pass ? `Expected "${id}" to NOT have opacity ${expectedOpacity} (\xB1${tolerance})` : `Expected "${id}" opacity ${expectedOpacity} (\xB1${tolerance}), got ${actual ?? "no material"} (waited ${timeout}ms)`,
|
|
1157
|
+
name: "toHaveOpacity",
|
|
1158
|
+
expected: expectedOpacity,
|
|
1159
|
+
actual
|
|
1160
|
+
};
|
|
1161
|
+
},
|
|
1162
|
+
// --- toBeTransparent ---
|
|
1163
|
+
async toBeTransparent(r3f, id, opts) {
|
|
1164
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1165
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1166
|
+
const isNot = this.isNot;
|
|
1167
|
+
let insp = null;
|
|
1168
|
+
let pass = false;
|
|
1169
|
+
try {
|
|
1170
|
+
await expect$1.poll(async () => {
|
|
1171
|
+
insp = await fetchInsp(r3f.page, id);
|
|
1172
|
+
if (!insp?.material) return false;
|
|
1173
|
+
pass = insp.material.transparent === true;
|
|
1174
|
+
return pass;
|
|
1175
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1176
|
+
} catch {
|
|
1177
|
+
}
|
|
1178
|
+
if (!insp) return notFound("toBeTransparent", id, "to be transparent", timeout);
|
|
1179
|
+
const i = insp;
|
|
1180
|
+
return {
|
|
1181
|
+
pass,
|
|
1182
|
+
message: () => pass ? `Expected "${id}" to NOT be transparent` : `Expected "${id}" transparent=true, got ${i.material?.transparent ?? "no material"} (waited ${timeout}ms)`,
|
|
1183
|
+
name: "toBeTransparent",
|
|
1184
|
+
expected: true,
|
|
1185
|
+
actual: i.material?.transparent
|
|
1186
|
+
};
|
|
1187
|
+
},
|
|
1188
|
+
// --- toHaveVertexCount ---
|
|
1189
|
+
async toHaveVertexCount(r3f, id, expectedCount, opts) {
|
|
1190
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1191
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1192
|
+
const isNot = this.isNot;
|
|
1193
|
+
let meta = null;
|
|
1194
|
+
let actual = 0;
|
|
1195
|
+
try {
|
|
1196
|
+
await expect$1.poll(async () => {
|
|
1197
|
+
meta = await fetchMeta(r3f.page, id);
|
|
1198
|
+
actual = meta?.vertexCount ?? 0;
|
|
1199
|
+
return actual === expectedCount;
|
|
1200
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1201
|
+
} catch {
|
|
1202
|
+
}
|
|
1203
|
+
if (!meta) return notFound("toHaveVertexCount", id, `to have ${expectedCount} vertices`, timeout);
|
|
1204
|
+
const pass = actual === expectedCount;
|
|
1205
|
+
return {
|
|
1206
|
+
pass,
|
|
1207
|
+
message: () => pass ? `Expected "${id}" to NOT have ${expectedCount} vertices` : `Expected "${id}" ${expectedCount} vertices, got ${actual} (waited ${timeout}ms)`,
|
|
1208
|
+
name: "toHaveVertexCount",
|
|
1209
|
+
expected: expectedCount,
|
|
1210
|
+
actual
|
|
1211
|
+
};
|
|
1212
|
+
},
|
|
1213
|
+
// --- toHaveTriangleCount ---
|
|
1214
|
+
async toHaveTriangleCount(r3f, id, expectedCount, opts) {
|
|
1215
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1216
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1217
|
+
const isNot = this.isNot;
|
|
1218
|
+
let meta = null;
|
|
1219
|
+
let actual = 0;
|
|
1220
|
+
try {
|
|
1221
|
+
await expect$1.poll(async () => {
|
|
1222
|
+
meta = await fetchMeta(r3f.page, id);
|
|
1223
|
+
actual = meta?.triangleCount ?? 0;
|
|
1224
|
+
return actual === expectedCount;
|
|
1225
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1226
|
+
} catch {
|
|
1227
|
+
}
|
|
1228
|
+
if (!meta) return notFound("toHaveTriangleCount", id, `to have ${expectedCount} triangles`, timeout);
|
|
1229
|
+
const pass = actual === expectedCount;
|
|
1230
|
+
return {
|
|
1231
|
+
pass,
|
|
1232
|
+
message: () => pass ? `Expected "${id}" to NOT have ${expectedCount} triangles` : `Expected "${id}" ${expectedCount} triangles, got ${actual} (waited ${timeout}ms)`,
|
|
1233
|
+
name: "toHaveTriangleCount",
|
|
1234
|
+
expected: expectedCount,
|
|
1235
|
+
actual
|
|
1236
|
+
};
|
|
1237
|
+
},
|
|
1238
|
+
// --- toHaveUserData ---
|
|
1239
|
+
async toHaveUserData(r3f, id, key, expectedValue, opts) {
|
|
1240
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1241
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1242
|
+
const isNot = this.isNot;
|
|
1243
|
+
let insp = null;
|
|
1244
|
+
let actual;
|
|
1245
|
+
let pass = false;
|
|
1246
|
+
try {
|
|
1247
|
+
await expect$1.poll(async () => {
|
|
1248
|
+
insp = await fetchInsp(r3f.page, id);
|
|
1249
|
+
if (!insp) return false;
|
|
1250
|
+
if (!(key in insp.userData)) return false;
|
|
1251
|
+
if (expectedValue === void 0) {
|
|
1252
|
+
pass = true;
|
|
1253
|
+
return true;
|
|
1254
|
+
}
|
|
1255
|
+
actual = insp.userData[key];
|
|
1256
|
+
pass = JSON.stringify(actual) === JSON.stringify(expectedValue);
|
|
1257
|
+
return pass;
|
|
1258
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1259
|
+
} catch {
|
|
1260
|
+
}
|
|
1261
|
+
if (!insp) return notFound("toHaveUserData", id, `to have userData.${key}`, timeout);
|
|
1262
|
+
return {
|
|
1263
|
+
pass,
|
|
1264
|
+
message: () => {
|
|
1265
|
+
if (expectedValue === void 0) {
|
|
1266
|
+
return pass ? `Expected "${id}" to NOT have userData key "${key}"` : `Expected "${id}" to have userData key "${key}", but missing (waited ${timeout}ms)`;
|
|
1267
|
+
}
|
|
1268
|
+
return pass ? `Expected "${id}" to NOT have userData.${key} = ${JSON.stringify(expectedValue)}` : `Expected "${id}" userData.${key} = ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actual)} (waited ${timeout}ms)`;
|
|
1269
|
+
},
|
|
1270
|
+
name: "toHaveUserData",
|
|
1271
|
+
expected: expectedValue ?? `key "${key}"`,
|
|
1272
|
+
actual
|
|
1273
|
+
};
|
|
1274
|
+
},
|
|
1275
|
+
// --- toHaveMapTexture ---
|
|
1276
|
+
async toHaveMapTexture(r3f, id, expectedName, opts) {
|
|
1277
|
+
const timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1278
|
+
const interval = opts?.interval ?? DEFAULT_INTERVAL;
|
|
1279
|
+
const isNot = this.isNot;
|
|
1280
|
+
let insp = null;
|
|
1281
|
+
let actual;
|
|
1282
|
+
let pass = false;
|
|
1283
|
+
try {
|
|
1284
|
+
await expect$1.poll(async () => {
|
|
1285
|
+
insp = await fetchInsp(r3f.page, id);
|
|
1286
|
+
if (!insp?.material?.map) return false;
|
|
1287
|
+
actual = insp.material.map;
|
|
1288
|
+
if (!expectedName) {
|
|
1289
|
+
pass = true;
|
|
1290
|
+
return true;
|
|
1291
|
+
}
|
|
1292
|
+
pass = actual === expectedName;
|
|
1293
|
+
return pass;
|
|
1294
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1295
|
+
} catch {
|
|
1296
|
+
}
|
|
1297
|
+
if (!insp) return notFound("toHaveMapTexture", id, "to have a map texture", timeout);
|
|
1298
|
+
return {
|
|
1299
|
+
pass,
|
|
1300
|
+
message: () => {
|
|
1301
|
+
if (!expectedName) {
|
|
1302
|
+
return pass ? `Expected "${id}" to NOT have a map texture` : `Expected "${id}" to have a map texture, but none found (waited ${timeout}ms)`;
|
|
1303
|
+
}
|
|
1304
|
+
return pass ? `Expected "${id}" to NOT have map "${expectedName}"` : `Expected "${id}" map "${expectedName}", got "${actual ?? "none"}" (waited ${timeout}ms)`;
|
|
1305
|
+
},
|
|
1306
|
+
name: "toHaveMapTexture",
|
|
1307
|
+
expected: expectedName ?? "any map",
|
|
1308
|
+
actual
|
|
1309
|
+
};
|
|
1310
|
+
},
|
|
1311
|
+
// =========================================================================
|
|
1312
|
+
// Scene-level matchers (no object ID — operate on the whole scene)
|
|
1313
|
+
// =========================================================================
|
|
1314
|
+
/**
|
|
1315
|
+
* Assert the total number of objects in the scene.
|
|
1316
|
+
* Auto-retries until the count matches or timeout.
|
|
1317
|
+
*
|
|
1318
|
+
* @example expect(r3f).toHaveObjectCount(42);
|
|
1319
|
+
* @example expect(r3f).toHaveObjectCount(42, { timeout: 10_000 });
|
|
1320
|
+
*/
|
|
1321
|
+
async toHaveObjectCount(r3f, expected, options) {
|
|
1322
|
+
const isNot = this.isNot;
|
|
1323
|
+
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
1324
|
+
const interval = options?.interval ?? DEFAULT_INTERVAL;
|
|
1325
|
+
let actual = -1;
|
|
1326
|
+
let pass = false;
|
|
1327
|
+
try {
|
|
1328
|
+
await expect$1.poll(async () => {
|
|
1329
|
+
actual = await fetchSceneCount(r3f.page);
|
|
1330
|
+
pass = actual === expected;
|
|
1331
|
+
return pass;
|
|
1332
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1333
|
+
} catch {
|
|
1334
|
+
}
|
|
1335
|
+
return {
|
|
1336
|
+
pass,
|
|
1337
|
+
message: () => pass ? `Expected scene to NOT have ${expected} objects, but it does` : `Expected scene to have ${expected} objects, got ${actual} (waited ${timeout}ms)`,
|
|
1338
|
+
name: "toHaveObjectCount",
|
|
1339
|
+
expected,
|
|
1340
|
+
actual
|
|
1341
|
+
};
|
|
1342
|
+
},
|
|
1343
|
+
/**
|
|
1344
|
+
* Assert the total number of objects is at least `min`.
|
|
1345
|
+
* Useful for BIM scenes where the exact count may vary slightly.
|
|
1346
|
+
*
|
|
1347
|
+
* @example expect(r3f).toHaveObjectCountGreaterThan(10);
|
|
1348
|
+
*/
|
|
1349
|
+
async toHaveObjectCountGreaterThan(r3f, min, options) {
|
|
1350
|
+
const isNot = this.isNot;
|
|
1351
|
+
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
1352
|
+
const interval = options?.interval ?? DEFAULT_INTERVAL;
|
|
1353
|
+
let actual = -1;
|
|
1354
|
+
let pass = false;
|
|
1355
|
+
try {
|
|
1356
|
+
await expect$1.poll(async () => {
|
|
1357
|
+
actual = await fetchSceneCount(r3f.page);
|
|
1358
|
+
pass = actual > min;
|
|
1359
|
+
return pass;
|
|
1360
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1361
|
+
} catch {
|
|
1362
|
+
}
|
|
1363
|
+
return {
|
|
1364
|
+
pass,
|
|
1365
|
+
message: () => pass ? `Expected scene to have at most ${min} objects, but has ${actual}` : `Expected scene to have more than ${min} objects, got ${actual} (waited ${timeout}ms)`,
|
|
1366
|
+
name: "toHaveObjectCountGreaterThan",
|
|
1367
|
+
expected: `> ${min}`,
|
|
1368
|
+
actual
|
|
1369
|
+
};
|
|
1370
|
+
},
|
|
1371
|
+
/**
|
|
1372
|
+
* Assert the count of objects of a specific Three.js type.
|
|
1373
|
+
* Auto-retries until the count matches or timeout.
|
|
1374
|
+
*
|
|
1375
|
+
* @example expect(r3f).toHaveCountByType('Mesh', 5);
|
|
1376
|
+
* @example expect(r3f).toHaveCountByType('Line', 10, { timeout: 10_000 });
|
|
1377
|
+
*/
|
|
1378
|
+
async toHaveCountByType(r3f, type, expected, options) {
|
|
1379
|
+
const isNot = this.isNot;
|
|
1380
|
+
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
1381
|
+
const interval = options?.interval ?? DEFAULT_INTERVAL;
|
|
1382
|
+
let actual = -1;
|
|
1383
|
+
let pass = false;
|
|
1384
|
+
try {
|
|
1385
|
+
await expect$1.poll(async () => {
|
|
1386
|
+
actual = await fetchCountByType(r3f.page, type);
|
|
1387
|
+
pass = actual === expected;
|
|
1388
|
+
return pass;
|
|
1389
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1390
|
+
} catch {
|
|
1391
|
+
}
|
|
1392
|
+
return {
|
|
1393
|
+
pass,
|
|
1394
|
+
message: () => pass ? `Expected scene to NOT have ${expected} "${type}" objects, but it does` : `Expected ${expected} "${type}" objects, got ${actual} (waited ${timeout}ms)`,
|
|
1395
|
+
name: "toHaveCountByType",
|
|
1396
|
+
expected,
|
|
1397
|
+
actual
|
|
1398
|
+
};
|
|
1399
|
+
},
|
|
1400
|
+
/**
|
|
1401
|
+
* Assert the total triangle count across all meshes in the scene.
|
|
1402
|
+
* Use as a performance budget guard — fail if the scene exceeds a threshold.
|
|
1403
|
+
*
|
|
1404
|
+
* @example expect(r3f).toHaveTotalTriangleCount(50000);
|
|
1405
|
+
* @example expect(r3f).not.toHaveTotalTriangleCountGreaterThan(100000); // budget guard
|
|
1406
|
+
*/
|
|
1407
|
+
async toHaveTotalTriangleCount(r3f, expected, options) {
|
|
1408
|
+
const isNot = this.isNot;
|
|
1409
|
+
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
1410
|
+
const interval = options?.interval ?? DEFAULT_INTERVAL;
|
|
1411
|
+
let actual = -1;
|
|
1412
|
+
let pass = false;
|
|
1413
|
+
try {
|
|
1414
|
+
await expect$1.poll(async () => {
|
|
1415
|
+
actual = await fetchTotalTriangles(r3f.page);
|
|
1416
|
+
pass = actual === expected;
|
|
1417
|
+
return pass;
|
|
1418
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1419
|
+
} catch {
|
|
1420
|
+
}
|
|
1421
|
+
return {
|
|
1422
|
+
pass,
|
|
1423
|
+
message: () => pass ? `Expected scene to NOT have ${expected} total triangles, but it does` : `Expected ${expected} total triangles, got ${actual} (waited ${timeout}ms)`,
|
|
1424
|
+
name: "toHaveTotalTriangleCount",
|
|
1425
|
+
expected,
|
|
1426
|
+
actual
|
|
1427
|
+
};
|
|
1428
|
+
},
|
|
1429
|
+
/**
|
|
1430
|
+
* Assert the total triangle count is at most `max`.
|
|
1431
|
+
* Perfect as a performance budget guard to prevent scene bloat.
|
|
1432
|
+
*
|
|
1433
|
+
* @example expect(r3f).toHaveTotalTriangleCountLessThan(100_000);
|
|
1434
|
+
*/
|
|
1435
|
+
async toHaveTotalTriangleCountLessThan(r3f, max, options) {
|
|
1436
|
+
const isNot = this.isNot;
|
|
1437
|
+
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
1438
|
+
const interval = options?.interval ?? DEFAULT_INTERVAL;
|
|
1439
|
+
let actual = -1;
|
|
1440
|
+
let pass = false;
|
|
1441
|
+
try {
|
|
1442
|
+
await expect$1.poll(async () => {
|
|
1443
|
+
actual = await fetchTotalTriangles(r3f.page);
|
|
1444
|
+
pass = actual < max;
|
|
1445
|
+
return pass;
|
|
1446
|
+
}, { timeout, intervals: [interval] }).toBe(!isNot);
|
|
1447
|
+
} catch {
|
|
1448
|
+
}
|
|
1449
|
+
return {
|
|
1450
|
+
pass,
|
|
1451
|
+
message: () => pass ? `Expected scene to have at least ${max} triangles, but has ${actual}` : `Expected scene to have fewer than ${max} triangles, got ${actual} (waited ${timeout}ms)`,
|
|
1452
|
+
name: "toHaveTotalTriangleCountLessThan",
|
|
1453
|
+
expected: `< ${max}`,
|
|
1454
|
+
actual
|
|
1455
|
+
};
|
|
407
1456
|
}
|
|
408
1457
|
});
|
|
409
1458
|
|
|
410
|
-
|
|
1459
|
+
// src/pathGenerators.ts
|
|
1460
|
+
function linePath(start, end, steps = 10, pressure = 0.5) {
|
|
1461
|
+
const points = [];
|
|
1462
|
+
const totalSteps = steps + 1;
|
|
1463
|
+
for (let i = 0; i <= totalSteps; i++) {
|
|
1464
|
+
const t = i / totalSteps;
|
|
1465
|
+
points.push({
|
|
1466
|
+
x: start.x + (end.x - start.x) * t,
|
|
1467
|
+
y: start.y + (end.y - start.y) * t,
|
|
1468
|
+
pressure
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
return points;
|
|
1472
|
+
}
|
|
1473
|
+
function curvePath(start, control, end, steps = 20, pressure = 0.5) {
|
|
1474
|
+
const points = [];
|
|
1475
|
+
for (let i = 0; i <= steps; i++) {
|
|
1476
|
+
const t = i / steps;
|
|
1477
|
+
const invT = 1 - t;
|
|
1478
|
+
points.push({
|
|
1479
|
+
x: invT * invT * start.x + 2 * invT * t * control.x + t * t * end.x,
|
|
1480
|
+
y: invT * invT * start.y + 2 * invT * t * control.y + t * t * end.y,
|
|
1481
|
+
pressure
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
return points;
|
|
1485
|
+
}
|
|
1486
|
+
function rectPath(topLeft, bottomRight, pointsPerSide = 5, pressure = 0.5) {
|
|
1487
|
+
const topRight = { x: bottomRight.x, y: topLeft.y };
|
|
1488
|
+
const bottomLeft = { x: topLeft.x, y: bottomRight.y };
|
|
1489
|
+
const sides = [
|
|
1490
|
+
[topLeft, topRight],
|
|
1491
|
+
[topRight, bottomRight],
|
|
1492
|
+
[bottomRight, bottomLeft],
|
|
1493
|
+
[bottomLeft, topLeft]
|
|
1494
|
+
];
|
|
1495
|
+
const points = [];
|
|
1496
|
+
for (const [from, to] of sides) {
|
|
1497
|
+
for (let i = 0; i < pointsPerSide; i++) {
|
|
1498
|
+
const t = i / pointsPerSide;
|
|
1499
|
+
points.push({
|
|
1500
|
+
x: from.x + (to.x - from.x) * t,
|
|
1501
|
+
y: from.y + (to.y - from.y) * t,
|
|
1502
|
+
pressure
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
points.push({ x: topLeft.x, y: topLeft.y, pressure });
|
|
1507
|
+
return points;
|
|
1508
|
+
}
|
|
1509
|
+
function circlePath(center, radiusX, radiusY, steps = 36, pressure = 0.5) {
|
|
1510
|
+
const ry = radiusY ?? radiusX;
|
|
1511
|
+
const points = [];
|
|
1512
|
+
for (let i = 0; i <= steps; i++) {
|
|
1513
|
+
const angle = i / steps * Math.PI * 2;
|
|
1514
|
+
points.push({
|
|
1515
|
+
x: center.x + Math.cos(angle) * radiusX,
|
|
1516
|
+
y: center.y + Math.sin(angle) * ry,
|
|
1517
|
+
pressure
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
return points;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
export { R3FFixture, circlePath, click, contextMenu, createR3FTest, curvePath, doubleClick, drag, drawPathOnCanvas, expect, hover, linePath, pointerMiss, rectPath, test, waitForIdle, waitForNewObject, waitForObject, waitForSceneReady, wheel };
|
|
411
1524
|
//# sourceMappingURL=index.js.map
|
|
412
1525
|
//# sourceMappingURL=index.js.map
|