@react-three-dom/cypress 0.2.0 → 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,47 +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 {
14
- // ---- Debug ----
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 ----
15
26
  /** Enable debug logging. Mirrors [r3f-dom:*] browser logs to Cypress command log. */
16
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>;
17
33
  /** Log the full scene tree to the Cypress command log and browser console. */
18
34
  r3fLogScene(): Chainable<void>;
19
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
+
20
44
  // ---- Interactions ----
21
- /** Click a 3D object by testId or uuid. */
45
+ /** Click a 3D object by testId or uuid. Auto-waits for bridge + object. */
22
46
  r3fClick(idOrUuid: string): Chainable<void>;
23
- /** Double-click a 3D object by testId or uuid. */
47
+ /** Double-click a 3D object by testId or uuid. Auto-waits for bridge + object. */
24
48
  r3fDoubleClick(idOrUuid: string): Chainable<void>;
25
- /** 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. */
26
50
  r3fContextMenu(idOrUuid: string): Chainable<void>;
27
- /** Hover over a 3D object by testId or uuid. */
51
+ /** Hover over a 3D object by testId or uuid. Auto-waits for bridge + object. */
28
52
  r3fHover(idOrUuid: string): Chainable<void>;
29
- /** 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. */
30
56
  r3fDrag(idOrUuid: string, delta: { x: number; y: number; z: number }): Chainable<void>;
31
- /** Dispatch a wheel/scroll event on a 3D object. */
57
+ /** Dispatch a wheel/scroll event on a 3D object. Auto-waits for bridge + object. */
32
58
  r3fWheel(idOrUuid: string, options?: { deltaY?: number; deltaX?: number }): Chainable<void>;
33
- /** Click empty space to trigger onPointerMissed handlers. */
59
+ /** Click empty space to trigger onPointerMissed handlers. Auto-waits for bridge. */
34
60
  r3fPointerMiss(): Chainable<void>;
35
- /** Draw a freeform path on the canvas (for drawing/annotation apps). */
61
+ /** Draw a freeform path on the canvas (for drawing/annotation apps). Auto-waits for bridge. */
36
62
  r3fDrawPath(
37
63
  points: Array<{ x: number; y: number; pressure?: number }>,
38
64
  options?: { stepDelayMs?: number; pointerType?: 'mouse' | 'pen' | 'touch'; clickAtEnd?: boolean },
39
65
  ): Chainable<{ eventCount: number; pointCount: number }>;
40
66
 
41
67
  // ---- Selection ----
42
- /** Select a 3D object (highlights in scene). */
68
+ /** Select a 3D object (highlights in scene). Auto-waits for bridge + object. */
43
69
  r3fSelect(idOrUuid: string): Chainable<void>;
44
- /** Clear the current selection. */
70
+ /** Clear the current selection. Auto-waits for bridge. */
45
71
  r3fClearSelection(): Chainable<void>;
46
72
 
47
73
  // ---- Queries ----
48
74
  /** Get object metadata by testId or uuid. */
49
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 }>;
50
94
  /** Get heavy inspection data (Tier 2) by testId or uuid. */
51
95
  r3fInspect(idOrUuid: string): Chainable<ObjectInspection | null>;
52
96
  /** Take a full scene snapshot. */
@@ -57,6 +101,10 @@ declare global {
57
101
  // ---- BIM/CAD queries ----
58
102
  /** Get all objects of a given Three.js type (e.g. "Mesh", "Group", "Line"). */
59
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[]>;
60
108
  /** Get objects that have a specific userData key (and optionally matching value). */
61
109
  r3fGetByUserData(key: string, value?: unknown): Chainable<ObjectMetadata[]>;
62
110
  /** Count objects of a given Three.js type. */
@@ -64,6 +112,10 @@ declare global {
64
112
  /** Batch lookup: get metadata for multiple objects by testId or uuid. */
65
113
  r3fGetObjects(ids: string[]): Chainable<Record<string, ObjectMetadata | null>>;
66
114
 
115
+ // ---- Camera ----
116
+ /** Get current camera state (position, rotation, fov, near, far, zoom, target). */
117
+ r3fGetCameraState(): Chainable<CameraState>;
118
+
67
119
  // ---- Waiters ----
68
120
  /** Wait until the scene is ready (bridge available, object count stable). */
69
121
  r3fWaitForSceneReady(options?: {
@@ -93,6 +145,11 @@ declare global {
93
145
  pollIntervalMs?: number;
94
146
  timeout?: number;
95
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>;
96
153
  }
97
154
 
98
155
  interface Assertion {
@@ -101,8 +158,10 @@ declare global {
101
158
  r3fExist(idOrUuid: string): Assertion;
102
159
  /** Assert that a 3D object is visible. */
103
160
  r3fVisible(idOrUuid: string): Assertion;
104
- /** Assert object position within tolerance. */
161
+ /** Assert object local position within tolerance. */
105
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;
106
165
  /** Assert object rotation (Euler radians) within tolerance. */
107
166
  r3fRotation(idOrUuid: string, expected: [number, number, number], tolerance?: number): Assertion;
108
167
  /** Assert object scale within tolerance. */
@@ -157,6 +216,26 @@ declare global {
157
216
  r3fTotalTriangleCount(expected: number): Assertion;
158
217
  /** Assert total triangle count is less than a maximum (performance budget). */
159
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;
160
239
  }
161
240
  }
162
241
  }