@react-three-dom/cypress 0.1.1 → 0.3.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/src/index.d.ts CHANGED
@@ -6,36 +6,91 @@
6
6
  // import '@react-three-dom/cypress';
7
7
  // ---------------------------------------------------------------------------
8
8
 
9
- import type { ObjectMetadata, ObjectInspection, SceneSnapshot } from './types';
9
+ import type { ObjectMetadata, ObjectInspection, SceneSnapshot, BridgeDiagnostics, CameraState } from './types';
10
+ import type { SceneDiff } from './diffSnapshots';
10
11
 
11
12
  declare global {
12
13
  namespace Cypress {
13
14
  interface Chainable {
15
+ // ---- Multi-canvas ----
16
+ /**
17
+ * Switch all subsequent r3f commands to target a specific canvas instance.
18
+ * Pass `null` to switch back to the default canvas.
19
+ * @example cy.r3fUseCanvas('minimap'); cy.r3fClick('marker');
20
+ */
21
+ r3fUseCanvas(canvasId: string | null): Chainable<void>;
22
+ /** List all active canvas IDs registered on the page. */
23
+ r3fGetCanvasIds(): Chainable<string[]>;
24
+
25
+ // ---- Debug / Reporter ----
26
+ /** Enable debug logging. Mirrors [r3f-dom:*] browser logs to Cypress command log. */
27
+ r3fEnableDebug(): Chainable<void>;
28
+ /**
29
+ * Enable the R3F reporter for rich terminal output (bridge status, object lookup,
30
+ * interaction timing, diagnostics). Requires `registerR3FTasks(on)` in cypress.config.ts.
31
+ */
32
+ r3fEnableReporter(enabled?: boolean): Chainable<void>;
33
+ /** Log the full scene tree to the Cypress command log and browser console. */
34
+ r3fLogScene(): Chainable<void>;
35
+
36
+ // ---- Diagnostics ----
37
+ /** Get bridge diagnostics (object counts, DOM state, GPU info). */
38
+ r3fGetDiagnostics(): Chainable<BridgeDiagnostics | null>;
39
+ /** Log bridge diagnostics to the Cypress command log and browser console. */
40
+ r3fLogDiagnostics(): Chainable<void>;
41
+ /** Fuzzy search for objects by partial testId, name, or uuid. */
42
+ r3fFuzzyFind(query: string, limit?: number): Chainable<ObjectMetadata[]>;
43
+
14
44
  // ---- Interactions ----
15
- /** Click a 3D object by testId or uuid. */
45
+ /** Click a 3D object by testId or uuid. Auto-waits for bridge + object. */
16
46
  r3fClick(idOrUuid: string): Chainable<void>;
17
- /** Double-click a 3D object by testId or uuid. */
47
+ /** Double-click a 3D object by testId or uuid. Auto-waits for bridge + object. */
18
48
  r3fDoubleClick(idOrUuid: string): Chainable<void>;
19
- /** Right-click / context-menu a 3D object by testId or uuid. */
49
+ /** Right-click / context-menu a 3D object by testId or uuid. Auto-waits for bridge + object. */
20
50
  r3fContextMenu(idOrUuid: string): Chainable<void>;
21
- /** Hover over a 3D object by testId or uuid. */
51
+ /** Hover over a 3D object by testId or uuid. Auto-waits for bridge + object. */
22
52
  r3fHover(idOrUuid: string): Chainable<void>;
23
- /** Drag a 3D object with a world-space delta vector. */
53
+ /** Unhover / pointer-leave resets hover state. Auto-waits for bridge. */
54
+ r3fUnhover(): Chainable<void>;
55
+ /** Drag a 3D object with a world-space delta vector. Auto-waits for bridge + object. */
24
56
  r3fDrag(idOrUuid: string, delta: { x: number; y: number; z: number }): Chainable<void>;
25
- /** Dispatch a wheel/scroll event on a 3D object. */
57
+ /** Dispatch a wheel/scroll event on a 3D object. Auto-waits for bridge + object. */
26
58
  r3fWheel(idOrUuid: string, options?: { deltaY?: number; deltaX?: number }): Chainable<void>;
27
- /** Click empty space to trigger onPointerMissed handlers. */
59
+ /** Click empty space to trigger onPointerMissed handlers. Auto-waits for bridge. */
28
60
  r3fPointerMiss(): Chainable<void>;
61
+ /** Draw a freeform path on the canvas (for drawing/annotation apps). Auto-waits for bridge. */
62
+ r3fDrawPath(
63
+ points: Array<{ x: number; y: number; pressure?: number }>,
64
+ options?: { stepDelayMs?: number; pointerType?: 'mouse' | 'pen' | 'touch'; clickAtEnd?: boolean },
65
+ ): Chainable<{ eventCount: number; pointCount: number }>;
29
66
 
30
67
  // ---- Selection ----
31
- /** Select a 3D object (highlights in scene). */
68
+ /** Select a 3D object (highlights in scene). Auto-waits for bridge + object. */
32
69
  r3fSelect(idOrUuid: string): Chainable<void>;
33
- /** Clear the current selection. */
70
+ /** Clear the current selection. Auto-waits for bridge. */
34
71
  r3fClearSelection(): Chainable<void>;
35
72
 
36
73
  // ---- Queries ----
37
74
  /** Get object metadata by testId or uuid. */
38
75
  r3fGetObject(idOrUuid: string): Chainable<ObjectMetadata | null>;
76
+ /** Get object metadata by testId. */
77
+ r3fGetByTestId(testId: string): Chainable<ObjectMetadata | null>;
78
+ /** Get all objects with the given name (object.name). */
79
+ r3fGetByName(name: string): Chainable<ObjectMetadata[]>;
80
+ /** Get object metadata by uuid only. */
81
+ r3fGetByUuid(uuid: string): Chainable<ObjectMetadata | null>;
82
+ /** Get direct children of an object by testId or uuid. */
83
+ r3fGetChildren(idOrUuid: string): Chainable<ObjectMetadata[]>;
84
+ /** Get parent of an object by testId or uuid. */
85
+ r3fGetParent(idOrUuid: string): Chainable<ObjectMetadata | null>;
86
+ /** Get the R3F canvas element (data-r3f-canvas). */
87
+ r3fGetCanvas(): Chainable<JQuery<HTMLCanvasElement>>;
88
+ /** Get world-space position [x, y, z] of an object. */
89
+ r3fGetWorldPosition(idOrUuid: string): Chainable<[number, number, number] | null>;
90
+ /** Compare two scene snapshots (added, removed, changed). */
91
+ r3fDiffSnapshots(before: SceneSnapshot, after: SceneSnapshot): Chainable<SceneDiff>;
92
+ /** Run an action and return { added, removed } object count change. */
93
+ r3fTrackObjectCount(action: () => Cypress.Chainable<unknown>): Chainable<{ added: number; removed: number }>;
39
94
  /** Get heavy inspection data (Tier 2) by testId or uuid. */
40
95
  r3fInspect(idOrUuid: string): Chainable<ObjectInspection | null>;
41
96
  /** Take a full scene snapshot. */
@@ -43,6 +98,24 @@ declare global {
43
98
  /** Get the total number of tracked objects. */
44
99
  r3fGetCount(): Chainable<number>;
45
100
 
101
+ // ---- BIM/CAD queries ----
102
+ /** Get all objects of a given Three.js type (e.g. "Mesh", "Group", "Line"). */
103
+ r3fGetByType(type: string): Chainable<ObjectMetadata[]>;
104
+ /** Get all objects with a given geometry type (e.g. "BoxGeometry"). */
105
+ r3fGetByGeometryType(type: string): Chainable<ObjectMetadata[]>;
106
+ /** Get all objects with a given material type (e.g. "MeshStandardMaterial"). */
107
+ r3fGetByMaterialType(type: string): Chainable<ObjectMetadata[]>;
108
+ /** Get objects that have a specific userData key (and optionally matching value). */
109
+ r3fGetByUserData(key: string, value?: unknown): Chainable<ObjectMetadata[]>;
110
+ /** Count objects of a given Three.js type. */
111
+ r3fGetCountByType(type: string): Chainable<number>;
112
+ /** Batch lookup: get metadata for multiple objects by testId or uuid. */
113
+ r3fGetObjects(ids: string[]): Chainable<Record<string, ObjectMetadata | null>>;
114
+
115
+ // ---- Camera ----
116
+ /** Get current camera state (position, rotation, fov, near, far, zoom, target). */
117
+ r3fGetCameraState(): Chainable<CameraState>;
118
+
46
119
  // ---- Waiters ----
47
120
  /** Wait until the scene is ready (bridge available, object count stable). */
48
121
  r3fWaitForSceneReady(options?: {
@@ -56,29 +129,113 @@ declare global {
56
129
  pollIntervalMs?: number;
57
130
  timeout?: number;
58
131
  }): Chainable<void>;
132
+ /** Wait until a specific object (by testId or uuid) exists in the scene. */
133
+ r3fWaitForObject(
134
+ idOrUuid: string,
135
+ options?: {
136
+ bridgeTimeout?: number;
137
+ objectTimeout?: number;
138
+ pollIntervalMs?: number;
139
+ },
140
+ ): Chainable<void>;
141
+ /** Wait until new object(s) appear in the scene (for drawing/annotation apps). */
142
+ r3fWaitForNewObject(options?: {
143
+ type?: string;
144
+ nameContains?: string;
145
+ pollIntervalMs?: number;
146
+ timeout?: number;
147
+ }): Chainable<{ newObjects: ObjectMetadata[]; newUuids: string[]; count: number }>;
148
+ /** Wait until an object (by testId or uuid) is no longer in the scene. */
149
+ r3fWaitForObjectRemoved(
150
+ idOrUuid: string,
151
+ options?: { bridgeTimeout?: number; pollIntervalMs?: number; timeout?: number },
152
+ ): Chainable<void>;
59
153
  }
60
154
 
61
155
  interface Assertion {
156
+ // ---- Tier 1: Metadata-based assertions (cheap) ----
62
157
  /** Assert that a 3D object with the given testId/uuid exists. */
63
158
  r3fExist(idOrUuid: string): Assertion;
64
159
  /** Assert that a 3D object is visible. */
65
160
  r3fVisible(idOrUuid: string): Assertion;
66
- /** Assert that a 3D object is in the camera frustum. */
67
- r3fInFrustum(idOrUuid: string): Assertion;
68
- /** Assert object position within tolerance. */
69
- r3fPosition(
70
- idOrUuid: string,
71
- expected: [number, number, number],
72
- tolerance?: number,
73
- ): Assertion;
161
+ /** Assert object local position within tolerance. */
162
+ r3fPosition(idOrUuid: string, expected: [number, number, number], tolerance?: number): Assertion;
163
+ /** Assert object world position within tolerance. */
164
+ r3fWorldPosition(idOrUuid: string, expected: [number, number, number], tolerance?: number): Assertion;
165
+ /** Assert object rotation (Euler radians) within tolerance. */
166
+ r3fRotation(idOrUuid: string, expected: [number, number, number], tolerance?: number): Assertion;
167
+ /** Assert object scale within tolerance. */
168
+ r3fScale(idOrUuid: string, expected: [number, number, number], tolerance?: number): Assertion;
169
+ /** Assert object type (Mesh, Group, Line, Points, etc.). */
170
+ r3fType(idOrUuid: string, expectedType: string): Assertion;
171
+ /** Assert object name. */
172
+ r3fName(idOrUuid: string, expectedName: string): Assertion;
173
+ /** Assert geometry type (BoxGeometry, PlaneGeometry, BufferGeometry, etc.). */
174
+ r3fGeometryType(idOrUuid: string, expectedGeoType: string): Assertion;
175
+ /** Assert material type (MeshStandardMaterial, ShaderMaterial, etc.). */
176
+ r3fMaterialType(idOrUuid: string, expectedMatType: string): Assertion;
177
+ /** Assert number of direct children. */
178
+ r3fChildCount(idOrUuid: string, expectedCount: number): Assertion;
179
+ /** Assert object's parent by testId, uuid, or name. */
180
+ r3fParent(idOrUuid: string, expectedParent: string): Assertion;
74
181
  /** Assert InstancedMesh instance count. */
75
182
  r3fInstanceCount(idOrUuid: string, expectedCount: number): Assertion;
183
+
184
+ // ---- Tier 2: Inspection-based assertions (heavier) ----
185
+ /** Assert that a 3D object is in the camera frustum. */
186
+ r3fInFrustum(idOrUuid: string): Assertion;
76
187
  /** Assert world-space bounding box within tolerance. */
77
188
  r3fBounds(
78
189
  idOrUuid: string,
79
190
  expected: { min: [number, number, number]; max: [number, number, number] },
80
191
  tolerance?: number,
81
192
  ): Assertion;
193
+ /** Assert material color (hex string, e.g. '#ff0000'). */
194
+ r3fColor(idOrUuid: string, expectedColor: string): Assertion;
195
+ /** Assert material opacity (0–1) within tolerance. */
196
+ r3fOpacity(idOrUuid: string, expectedOpacity: number, tolerance?: number): Assertion;
197
+ /** Assert material.transparent === true. */
198
+ r3fTransparent(idOrUuid: string): Assertion;
199
+ /** Assert geometry vertex count. */
200
+ r3fVertexCount(idOrUuid: string, expectedCount: number): Assertion;
201
+ /** Assert geometry triangle count. */
202
+ r3fTriangleCount(idOrUuid: string, expectedCount: number): Assertion;
203
+ /** Assert a specific key (and optionally value) in userData. */
204
+ r3fUserData(idOrUuid: string, key: string, expectedValue?: unknown): Assertion;
205
+ /** Assert material has a map texture (optionally by name). */
206
+ r3fMapTexture(idOrUuid: string, expectedMapName?: string): Assertion;
207
+
208
+ // ---- Scene-level assertions ----
209
+ /** Assert total object count in the scene. */
210
+ r3fObjectCount(expected: number): Assertion;
211
+ /** Assert total object count is greater than a minimum. */
212
+ r3fObjectCountGreaterThan(min: number): Assertion;
213
+ /** Assert count of objects of a specific type. */
214
+ r3fCountByType(type: string, expected: number): Assertion;
215
+ /** Assert total triangle count across all meshes. */
216
+ r3fTotalTriangleCount(expected: number): Assertion;
217
+ /** Assert total triangle count is less than a maximum (performance budget). */
218
+ r3fTotalTriangleCountLessThan(max: number): Assertion;
219
+
220
+ // ---- Camera assertions ----
221
+ /** Assert camera position within tolerance. */
222
+ r3fCameraPosition(expected: [number, number, number], tolerance?: number): Assertion;
223
+ /** Assert camera field of view (PerspectiveCamera). */
224
+ r3fCameraFov(expected: number, tolerance?: number): Assertion;
225
+ /** Assert camera near clipping plane. */
226
+ r3fCameraNear(expected: number, tolerance?: number): Assertion;
227
+ /** Assert camera far clipping plane. */
228
+ r3fCameraFar(expected: number, tolerance?: number): Assertion;
229
+ /** Assert camera zoom level. */
230
+ r3fCameraZoom(expected: number, tolerance?: number): Assertion;
231
+
232
+ // ---- Batch assertions ----
233
+ /** Assert ALL given objects exist. Accepts array of ids or glob pattern (e.g. "wall-*"). */
234
+ r3fAllExist(idsOrPattern: string[] | string): Assertion;
235
+ /** Assert ALL given objects are visible. Accepts array of ids or glob pattern. */
236
+ r3fAllVisible(idsOrPattern: string[] | string): Assertion;
237
+ /** Assert NONE of the given objects exist. Accepts array of ids or glob pattern. */
238
+ r3fNoneExist(idsOrPattern: string[] | string): Assertion;
82
239
  }
83
240
  }
84
241
  }