@react-three/test-renderer 9.0.1 → 10.0.0-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # @react-three/test-renderer
2
2
 
3
+ ## 10.0.0-alpha.0
4
+
5
+ ### Major Changes
6
+
7
+ - ## R3F v10 - WebGPU Support & React 19
8
+
9
+ ### Breaking Changes
10
+
11
+ - **React 19 required** - Minimum React version is now 19.0
12
+ - **Three.js 0.181+ required** - Minimum Three.js version is now 0.181.2
13
+ - **New entry points** - Bundle structure reorganized with dedicated WebGPU support
14
+
15
+ ### New Features
16
+
17
+ - **WebGPU Renderer Support** - New `@react-three/fiber/webgpu` entry point with full WebGPU and TSL (Three.js Shading Language) support
18
+ - **Legacy Entry Point** - `@react-three/fiber/legacy` for WebGL-only environments
19
+ - **Improved Frame Loop** - Enhanced `useFrame` with better priority scheduling and `runOnce` support
20
+ - **Build System Migration** - Moved from Preconstruct to Unbuild for better per-entry-point optimization
21
+
22
+ ### Entry Points
23
+
24
+ ```js
25
+ // Default - WebGL + WebGPU support
26
+ import { Canvas } from '@react-three/fiber'
27
+
28
+ // WebGPU only - smaller bundle, TSL support
29
+ import { Canvas } from '@react-three/fiber/webgpu'
30
+
31
+ // Legacy WebGL only - maximum compatibility
32
+ import { Canvas } from '@react-three/fiber/legacy'
33
+ ```
34
+
35
+ See the full migration guide in the documentation.
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies
40
+ - @react-three/fiber@10.0.0-alpha.0
41
+
42
+ ## 9.1.0
43
+
44
+ ### Minor Changes
45
+
46
+ - 31781e5a1fdc464cb67617cc3d7bc5d8690cd4cd: feat(RTTR): handle primitives in test-renderer and fix queries in TestInstances
47
+
3
48
  ## 9.0.1
4
49
 
5
50
  ### Patch Changes
@@ -298,7 +343,7 @@
298
343
 
299
344
  ### Patch Changes
300
345
 
301
- - 7aa2eab: fix: remove zustand subcribe selector
346
+ - 7aa2eab: fix: remove zustand subscribe selector
302
347
  - Updated dependencies [7aa2eab]
303
348
  - @react-three/fiber@7.0.19
304
349
 
@@ -330,7 +375,7 @@
330
375
 
331
376
  ### Patch Changes
332
377
 
333
- - c5645e8: fix primitve leftovers on switch
378
+ - c5645e8: fix primitive leftovers on switch
334
379
  - Updated dependencies [c5645e8]
335
380
  - @react-three/fiber@7.0.15
336
381
 
package/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Version](https://img.shields.io/npm/v/@react-three/test-renderer?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/@react-three/test-renderer)
4
4
  [![Downloads](https://img.shields.io/npm/dt/@react-three/test-renderer.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/@react-three/test-renderer)
5
5
  [![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/pmndrs)
6
- [![Twitter](https://img.shields.io/twitter/follow/_josh_ellis_?label=%40_josh_ellis_&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/_josh_ellis_)
7
6
  [![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/ZZjjNvJ)
8
7
 
9
8
  `@react-three/test-renderer` is a React testing <a href="https://reactjs.org/docs/codebase-overview.html#renderers">renderer</a> for threejs in node.
@@ -29,6 +28,84 @@ Essentially, this package makes it easy to grab a snapshot of the Scene Graph re
29
28
 
30
29
  ---
31
30
 
31
+ ## Entry Points
32
+
33
+ Choose the entry point that matches your `@react-three/fiber` import:
34
+
35
+ | Your Fiber Import | Test Renderer Import | Use Case |
36
+ | --------------------------- | ----------------------------------- | ------------------------------------ |
37
+ | `@react-three/fiber` | `@react-three/test-renderer` | Default (WebGL with WebGPU fallback) |
38
+ | `@react-three/fiber/legacy` | `@react-three/test-renderer/legacy` | WebGL only |
39
+ | `@react-three/fiber/webgpu` | `@react-three/test-renderer/webgpu` | WebGPU with TSL hooks |
40
+
41
+ ### Default Entry
42
+
43
+ For applications using the standard fiber import:
44
+
45
+ ```tsx
46
+ import ReactThreeTestRenderer from '@react-three/test-renderer'
47
+ import { Canvas } from '@react-three/fiber'
48
+
49
+ // Your component
50
+ function MyScene() {
51
+ return (
52
+ <mesh>
53
+ <boxGeometry />
54
+ <meshStandardMaterial color="blue" />
55
+ </mesh>
56
+ )
57
+ }
58
+
59
+ // Test
60
+ const renderer = await ReactThreeTestRenderer.create(<MyScene />)
61
+ expect(renderer.scene.children[0].type).toBe('Mesh')
62
+ ```
63
+
64
+ ### Legacy Entry (WebGL Only)
65
+
66
+ For applications using legacy WebGL-only rendering:
67
+
68
+ ```tsx
69
+ import ReactThreeTestRenderer from '@react-three/test-renderer/legacy'
70
+ import { Canvas } from '@react-three/fiber/legacy'
71
+
72
+ const renderer = await ReactThreeTestRenderer.create(<MyScene />)
73
+ ```
74
+
75
+ ### WebGPU Entry
76
+
77
+ For applications using WebGPU with TSL (Three Shading Language):
78
+
79
+ ```tsx
80
+ import ReactThreeTestRenderer, {
81
+ useUniform,
82
+ useUniforms,
83
+ useNodes,
84
+ useLocalNodes,
85
+ } from '@react-three/test-renderer/webgpu'
86
+ import { Canvas, useUniforms } from '@react-three/fiber/webgpu'
87
+
88
+ // Component using WebGPU hooks
89
+ function MyWebGPUScene() {
90
+ const { uTime } = useUniforms({ uTime: 0 })
91
+ const { colorNode } = useNodes(() => ({
92
+ colorNode: color('#ff0000'),
93
+ }))
94
+
95
+ return (
96
+ <mesh>
97
+ <boxGeometry />
98
+ <meshBasicNodeMaterial colorNode={colorNode} />
99
+ </mesh>
100
+ )
101
+ }
102
+
103
+ // Test with hook access
104
+ const renderer = await ReactThreeTestRenderer.create(<MyWebGPUScene />)
105
+ ```
106
+
107
+ ---
108
+
32
109
  ## Usage
33
110
 
34
111
  RTTR is testing library agnostic, so we hope that it works with libraries such as [`jest`](https://jestjs.io/), [`jasmine`](https://jasmine.github.io/) etc.
@@ -55,7 +132,97 @@ console.log(renderer.toGraph())
55
132
 
56
133
  ---
57
134
 
135
+ ## Testing WebGPU Hooks
136
+
137
+ The `/webgpu` entry exports all WebGPU-specific hooks for testing TSL uniforms and nodes:
138
+
139
+ ```tsx
140
+ import ReactThreeTestRenderer, {
141
+ useUniform,
142
+ useUniforms,
143
+ useNodes,
144
+ useLocalNodes,
145
+ // Cleanup utilities
146
+ removeUniforms,
147
+ clearScope,
148
+ clearRootUniforms,
149
+ removeNodes,
150
+ clearNodeScope,
151
+ clearRootNodes,
152
+ } from '@react-three/test-renderer/webgpu'
153
+ import { useThree } from '@react-three/fiber/webgpu'
154
+
155
+ describe('My WebGPU Scene', () => {
156
+ it('should create and use uniforms', async () => {
157
+ let uniforms: any = null
158
+
159
+ function TestComponent() {
160
+ uniforms = useUniforms({
161
+ uTime: 0,
162
+ uColor: '#ff0000',
163
+ })
164
+ return null
165
+ }
166
+
167
+ const renderer = await ReactThreeTestRenderer.create(<TestComponent />)
168
+
169
+ // Assert uniform values
170
+ expect(uniforms.uTime.value).toBe(0)
171
+
172
+ // Modify uniform imperatively
173
+ uniforms.uTime.value = 1.5
174
+ expect(uniforms.uTime.value).toBe(1.5)
175
+
176
+ await renderer.unmount()
177
+ })
178
+
179
+ it('should test nodes with materials', async () => {
180
+ function TestMesh() {
181
+ const { colorNode } = useNodes(() => ({
182
+ colorNode: color('#00ff00'),
183
+ }))
184
+
185
+ return (
186
+ <mesh>
187
+ <boxGeometry />
188
+ <meshBasicNodeMaterial colorNode={colorNode} />
189
+ </mesh>
190
+ )
191
+ }
192
+
193
+ const renderer = await ReactThreeTestRenderer.create(<TestMesh />)
194
+
195
+ expect(renderer.scene.children[0].type).toBe('Mesh')
196
+ await renderer.unmount()
197
+ })
198
+ })
199
+ ```
200
+
201
+ ---
202
+
203
+ ## Migration from v8
204
+
205
+ If you're upgrading from v8 and using WebGPU features:
206
+
207
+ ```diff
208
+ // Before (v8) - single entry point
209
+ -import ReactThreeTestRenderer from '@react-three/test-renderer'
210
+
211
+ // After (v9+) - choose matching entry
212
+ // For WebGPU apps:
213
+ +import ReactThreeTestRenderer from '@react-three/test-renderer/webgpu'
214
+
215
+ // For legacy WebGL apps:
216
+ +import ReactThreeTestRenderer from '@react-three/test-renderer/legacy'
217
+
218
+ // For default (auto-detection):
219
+ +import ReactThreeTestRenderer from '@react-three/test-renderer'
220
+ ```
221
+
222
+ ---
223
+
58
224
  ## API
59
225
 
60
226
  - [React Three Test Renderer API](/packages/test-renderer/markdown/rttr.md)
61
227
  - [React Three Test Instance API](/packages/test-renderer/markdown/rttr-instance.md)
228
+ - [WebGPU Testing Guide](/packages/test-renderer/markdown/webgpu-testing.md)
@@ -43,10 +43,25 @@ const graphObjectFactory = (type, name, children) => ({
43
43
  name,
44
44
  children
45
45
  });
46
- const toGraph = object => object.children.map(child => {
47
- var _child$object$name;
48
- return graphObjectFactory(child.object.type, (_child$object$name = child.object.name) != null ? _child$object$name : '', toGraph(child));
49
- });
46
+
47
+ // Helper function to process raw THREE.js children objects
48
+ function processThreeChildren(children) {
49
+ return children.map(object => graphObjectFactory(object.type, object.name || '', object.children && object.children.length > 0 ? processThreeChildren(object.children) : []));
50
+ }
51
+ const toGraph = object => {
52
+ return object.children.map(child => {
53
+ var _child$object$childre, _child$object$name;
54
+ // Process standard R3F children
55
+ const children = toGraph(child);
56
+
57
+ // For primitives, also include THREE.js object children
58
+ if (child.type === 'primitive' && (_child$object$childre = child.object.children) != null && _child$object$childre.length) {
59
+ const threeChildren = processThreeChildren(child.object.children);
60
+ children.push(...threeChildren);
61
+ }
62
+ return graphObjectFactory(child.object.type, (_child$object$name = child.object.name) != null ? _child$object$name : '', children);
63
+ });
64
+ };
50
65
 
51
66
  const functions = ['activeTexture', 'attachShader', 'beginQuery', 'beginTransformFeedback', 'bindAttribLocation', 'bindBufferBase', 'bindBufferRange', 'bindRenderbuffer', 'bindSampler', 'bindTransformFeedback', 'bindVertexArray', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'blitFramebuffer', 'bufferData', 'bufferSubData', 'checkFramebufferStatus', 'clientWaitSync', 'compileShader', 'compressedTexImage2D', 'compressedTexImage3D', 'compressedTexSubImage2D', 'compressedTexSubImage3D', 'copyBufferSubData', 'copyTexImage2D', 'copyTexSubImage2D', 'copyTexSubImage3D', 'createBuffer', 'createFramebuffer', 'createProgram', 'createQuery', 'createRenderbuffer', 'createSampler', 'createShader', 'createTexture', 'createTransformFeedback', 'createVertexArray', 'cullFace', 'deleteBuffer', 'deleteFramebuffer', 'deleteProgram', 'deleteQuery', 'deleteRenderbuffer', 'deleteSampler', 'deleteShader', 'deleteSync', 'deleteTexture', 'deleteTransformFeedback', 'deleteVertexArray', 'depthFunc', 'depthMask', 'depthRange', 'detachShader', 'disable', 'drawArraysInstanced', 'drawElementsInstanced', 'drawRangeElements', 'enable', 'endQuery', 'endTransformFeedback', 'fenceSync', 'finish', 'flush', 'framebufferRenderbuffer', 'framebufferTexture2D', 'framebufferTextureLayer', 'frontFace', 'generateMipmap', 'getActiveAttrib', 'getActiveUniform', 'getActiveUniformBlockName', 'getActiveUniformBlockParameter', 'getActiveUniforms', 'getAttachedShaders', 'getAttribLocation', 'getBufferParameter', 'getBufferSubData', 'getContextAttributes', 'getError', 'getExtension', 'getFragDataLocation', 'getFramebufferAttachmentParameter', 'getIndexedParameter', 'getInternalformatParameter', 'getParameter', 'getProgramInfoLog', 'getProgramParameter', 'getQuery', 'getQueryParameter', 'getRenderbufferParameter', 'getSamplerParameter', 'getShaderInfoLog', 'getShaderParameter', 'getShaderPrecisionFormat', 'getShaderSource', 'getSupportedExtensions', 'getSyncParameter', 'getTexParameter', 'getTransformFeedbackVarying', 'getUniform', 'getUniformBlockIndex', 'getUniformIndices', 'getUniformLocation', 'getVertexAttrib', 'getVertexAttribOffset', 'hint', 'invalidateFramebuffer', 'invalidateSubFramebuffer', 'isBuffer', 'isContextLost', 'isEnabled', 'isFramebuffer', 'isProgram', 'isQuery', 'isRenderbuffer', 'isSampler', 'isShader', 'isSync', 'isTexture', 'isTransformFeedback', 'isVertexArray', 'lineWidth', 'linkProgram', 'pauseTransformFeedback', 'pixelStorei', 'polygonOffset', 'readBuffer', 'readPixels', 'renderbufferStorage', 'renderbufferStorageMultisample', 'resumeTransformFeedback', 'sampleCoverage', 'samplerParameterf', 'samplerParameteri', 'shaderSource', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texImage2D', 'texImage3D', 'texParameterf', 'texParameteri', 'texStorage2D', 'texStorage3D', 'texSubImage2D', 'texSubImage3D', 'transformFeedbackVaryings', 'uniform1ui', 'uniform2ui', 'uniform3ui', 'uniform4ui', 'uniformBlockBinding', 'useProgram', 'validateProgram', 'vertexAttribDivisor', 'vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribIPointer', 'waitSync', 'bindBuffer', 'bindFramebuffer', 'bindTexture', 'clear', 'clearBufferfi', 'clearBufferfv', 'clearBufferiv', 'clearBufferuiv', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'disableVertexAttribArray', 'drawArrays', 'drawBuffers', 'drawElements', 'enableVertexAttribArray', 'scissor', 'uniform1f', 'uniform1fv', 'uniform1i', 'uniform1iv', 'uniform1uiv', 'uniform2f', 'uniform2fv', 'uniform2i', 'uniform2iv', 'uniform2uiv', 'uniform3f', 'uniform3fv', 'uniform3i', 'uniform3iv', 'uniform3uiv', 'uniform4f', 'uniform4fv', 'uniform4i', 'uniform4iv', 'uniform4uiv', 'uniformMatrix2fv', 'uniformMatrix2x3fv', 'uniformMatrix2x4fv', 'uniformMatrix3fv', 'uniformMatrix3x2fv', 'uniformMatrix3x4fv', 'uniformMatrix4fv', 'uniformMatrix4x2fv', 'uniformMatrix4x3fv', 'vertexAttrib1f', 'vertexAttrib1fv', 'vertexAttrib2f', 'vertexAttrib2fv', 'vertexAttrib3f', 'vertexAttrib3fv', 'vertexAttrib4f', 'vertexAttrib4fv', 'vertexAttribI4iv', 'vertexAttribI4uiv', 'vertexAttribPointer', 'viewport', 'makeXRCompatible'];
52
67
  const enums = {
@@ -671,23 +686,76 @@ const matchProps = (props, filter) => {
671
686
  }
672
687
  return true;
673
688
  };
674
- const findAll = (root, decider) => {
689
+ const findAll = (root, decider, options = {
690
+ includeRoot: true
691
+ }) => {
675
692
  const results = [];
676
- if (decider(root)) {
693
+
694
+ // Only include the root node if the option is enabled
695
+ if (options.includeRoot !== false && decider(root)) {
677
696
  results.push(root);
678
697
  }
698
+
699
+ // Always search through children
679
700
  root.allChildren.forEach(child => {
680
- results.push(...findAll(child, decider));
701
+ // When recursively searching children, we always want to include their roots
702
+ results.push(...findAll(child, decider, {
703
+ includeRoot: true
704
+ }));
681
705
  });
682
706
  return results;
683
707
  };
684
708
 
709
+ // Helper to create a minimal wrapper for THREE.Object3D children of primitives
710
+ const createVirtualInstance = (object, parent) => {
711
+ // Create the virtual instance for this object
712
+ // we can't import the prepare method from packages/fiber/src/core/utils.tsx so we do what we can
713
+ const instance = {
714
+ root: parent.root,
715
+ type: object.type.toLowerCase(),
716
+ // Convert to lowercase to match R3F convention
717
+ parent,
718
+ children: [],
719
+ props: {
720
+ object
721
+ },
722
+ object,
723
+ eventCount: 0,
724
+ handlers: {},
725
+ isHidden: false
726
+ };
727
+
728
+ // Recursively process children if they exist
729
+ if (object.children && object.children.length > 0) {
730
+ const objectChildren = object.children;
731
+ instance.children = Array.from(objectChildren).map(child => createVirtualInstance(child, instance));
732
+ }
733
+ return instance;
734
+ };
685
735
  class ReactThreeTestInstance {
686
736
  constructor(_fiber) {
687
737
  this.getChildren = (fiber, opts = {
688
738
  exhaustive: false
689
- }) => fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
690
- this.findAll = decider => findAll(this, decider);
739
+ }) => {
740
+ var _fiber$object$childre;
741
+ // Get standard R3F children
742
+ const r3fChildren = fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
743
+
744
+ // For primitives, also add THREE.js object children
745
+ if (fiber.type === 'primitive' && (_fiber$object$childre = fiber.object.children) != null && _fiber$object$childre.length) {
746
+ const threeChildren = fiber.object.children.map(child => {
747
+ // Create a virtual instance that wraps the THREE.js child
748
+ const virtualInstance = createVirtualInstance(child, fiber);
749
+ return wrapFiber(virtualInstance);
750
+ });
751
+ r3fChildren.push(...threeChildren);
752
+ return r3fChildren;
753
+ }
754
+ return r3fChildren;
755
+ };
756
+ this.findAll = decider => findAll(this, decider, {
757
+ includeRoot: false
758
+ });
691
759
  this.find = decider => expectOne(this.findAll(decider), `matching custom checker: ${decider.toString()}`);
692
760
  this.findByType = type => expectOne(this.findAll(node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
693
761
  this.findAllByType = type => this.findAll(node => Boolean(node.type && node.type === type));
@@ -43,10 +43,25 @@ const graphObjectFactory = (type, name, children) => ({
43
43
  name,
44
44
  children
45
45
  });
46
- const toGraph = object => object.children.map(child => {
47
- var _child$object$name;
48
- return graphObjectFactory(child.object.type, (_child$object$name = child.object.name) != null ? _child$object$name : '', toGraph(child));
49
- });
46
+
47
+ // Helper function to process raw THREE.js children objects
48
+ function processThreeChildren(children) {
49
+ return children.map(object => graphObjectFactory(object.type, object.name || '', object.children && object.children.length > 0 ? processThreeChildren(object.children) : []));
50
+ }
51
+ const toGraph = object => {
52
+ return object.children.map(child => {
53
+ var _child$object$childre, _child$object$name;
54
+ // Process standard R3F children
55
+ const children = toGraph(child);
56
+
57
+ // For primitives, also include THREE.js object children
58
+ if (child.type === 'primitive' && (_child$object$childre = child.object.children) != null && _child$object$childre.length) {
59
+ const threeChildren = processThreeChildren(child.object.children);
60
+ children.push(...threeChildren);
61
+ }
62
+ return graphObjectFactory(child.object.type, (_child$object$name = child.object.name) != null ? _child$object$name : '', children);
63
+ });
64
+ };
50
65
 
51
66
  const functions = ['activeTexture', 'attachShader', 'beginQuery', 'beginTransformFeedback', 'bindAttribLocation', 'bindBufferBase', 'bindBufferRange', 'bindRenderbuffer', 'bindSampler', 'bindTransformFeedback', 'bindVertexArray', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'blitFramebuffer', 'bufferData', 'bufferSubData', 'checkFramebufferStatus', 'clientWaitSync', 'compileShader', 'compressedTexImage2D', 'compressedTexImage3D', 'compressedTexSubImage2D', 'compressedTexSubImage3D', 'copyBufferSubData', 'copyTexImage2D', 'copyTexSubImage2D', 'copyTexSubImage3D', 'createBuffer', 'createFramebuffer', 'createProgram', 'createQuery', 'createRenderbuffer', 'createSampler', 'createShader', 'createTexture', 'createTransformFeedback', 'createVertexArray', 'cullFace', 'deleteBuffer', 'deleteFramebuffer', 'deleteProgram', 'deleteQuery', 'deleteRenderbuffer', 'deleteSampler', 'deleteShader', 'deleteSync', 'deleteTexture', 'deleteTransformFeedback', 'deleteVertexArray', 'depthFunc', 'depthMask', 'depthRange', 'detachShader', 'disable', 'drawArraysInstanced', 'drawElementsInstanced', 'drawRangeElements', 'enable', 'endQuery', 'endTransformFeedback', 'fenceSync', 'finish', 'flush', 'framebufferRenderbuffer', 'framebufferTexture2D', 'framebufferTextureLayer', 'frontFace', 'generateMipmap', 'getActiveAttrib', 'getActiveUniform', 'getActiveUniformBlockName', 'getActiveUniformBlockParameter', 'getActiveUniforms', 'getAttachedShaders', 'getAttribLocation', 'getBufferParameter', 'getBufferSubData', 'getContextAttributes', 'getError', 'getExtension', 'getFragDataLocation', 'getFramebufferAttachmentParameter', 'getIndexedParameter', 'getInternalformatParameter', 'getParameter', 'getProgramInfoLog', 'getProgramParameter', 'getQuery', 'getQueryParameter', 'getRenderbufferParameter', 'getSamplerParameter', 'getShaderInfoLog', 'getShaderParameter', 'getShaderPrecisionFormat', 'getShaderSource', 'getSupportedExtensions', 'getSyncParameter', 'getTexParameter', 'getTransformFeedbackVarying', 'getUniform', 'getUniformBlockIndex', 'getUniformIndices', 'getUniformLocation', 'getVertexAttrib', 'getVertexAttribOffset', 'hint', 'invalidateFramebuffer', 'invalidateSubFramebuffer', 'isBuffer', 'isContextLost', 'isEnabled', 'isFramebuffer', 'isProgram', 'isQuery', 'isRenderbuffer', 'isSampler', 'isShader', 'isSync', 'isTexture', 'isTransformFeedback', 'isVertexArray', 'lineWidth', 'linkProgram', 'pauseTransformFeedback', 'pixelStorei', 'polygonOffset', 'readBuffer', 'readPixels', 'renderbufferStorage', 'renderbufferStorageMultisample', 'resumeTransformFeedback', 'sampleCoverage', 'samplerParameterf', 'samplerParameteri', 'shaderSource', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texImage2D', 'texImage3D', 'texParameterf', 'texParameteri', 'texStorage2D', 'texStorage3D', 'texSubImage2D', 'texSubImage3D', 'transformFeedbackVaryings', 'uniform1ui', 'uniform2ui', 'uniform3ui', 'uniform4ui', 'uniformBlockBinding', 'useProgram', 'validateProgram', 'vertexAttribDivisor', 'vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribIPointer', 'waitSync', 'bindBuffer', 'bindFramebuffer', 'bindTexture', 'clear', 'clearBufferfi', 'clearBufferfv', 'clearBufferiv', 'clearBufferuiv', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'disableVertexAttribArray', 'drawArrays', 'drawBuffers', 'drawElements', 'enableVertexAttribArray', 'scissor', 'uniform1f', 'uniform1fv', 'uniform1i', 'uniform1iv', 'uniform1uiv', 'uniform2f', 'uniform2fv', 'uniform2i', 'uniform2iv', 'uniform2uiv', 'uniform3f', 'uniform3fv', 'uniform3i', 'uniform3iv', 'uniform3uiv', 'uniform4f', 'uniform4fv', 'uniform4i', 'uniform4iv', 'uniform4uiv', 'uniformMatrix2fv', 'uniformMatrix2x3fv', 'uniformMatrix2x4fv', 'uniformMatrix3fv', 'uniformMatrix3x2fv', 'uniformMatrix3x4fv', 'uniformMatrix4fv', 'uniformMatrix4x2fv', 'uniformMatrix4x3fv', 'vertexAttrib1f', 'vertexAttrib1fv', 'vertexAttrib2f', 'vertexAttrib2fv', 'vertexAttrib3f', 'vertexAttrib3fv', 'vertexAttrib4f', 'vertexAttrib4fv', 'vertexAttribI4iv', 'vertexAttribI4uiv', 'vertexAttribPointer', 'viewport', 'makeXRCompatible'];
52
67
  const enums = {
@@ -671,23 +686,76 @@ const matchProps = (props, filter) => {
671
686
  }
672
687
  return true;
673
688
  };
674
- const findAll = (root, decider) => {
689
+ const findAll = (root, decider, options = {
690
+ includeRoot: true
691
+ }) => {
675
692
  const results = [];
676
- if (decider(root)) {
693
+
694
+ // Only include the root node if the option is enabled
695
+ if (options.includeRoot !== false && decider(root)) {
677
696
  results.push(root);
678
697
  }
698
+
699
+ // Always search through children
679
700
  root.allChildren.forEach(child => {
680
- results.push(...findAll(child, decider));
701
+ // When recursively searching children, we always want to include their roots
702
+ results.push(...findAll(child, decider, {
703
+ includeRoot: true
704
+ }));
681
705
  });
682
706
  return results;
683
707
  };
684
708
 
709
+ // Helper to create a minimal wrapper for THREE.Object3D children of primitives
710
+ const createVirtualInstance = (object, parent) => {
711
+ // Create the virtual instance for this object
712
+ // we can't import the prepare method from packages/fiber/src/core/utils.tsx so we do what we can
713
+ const instance = {
714
+ root: parent.root,
715
+ type: object.type.toLowerCase(),
716
+ // Convert to lowercase to match R3F convention
717
+ parent,
718
+ children: [],
719
+ props: {
720
+ object
721
+ },
722
+ object,
723
+ eventCount: 0,
724
+ handlers: {},
725
+ isHidden: false
726
+ };
727
+
728
+ // Recursively process children if they exist
729
+ if (object.children && object.children.length > 0) {
730
+ const objectChildren = object.children;
731
+ instance.children = Array.from(objectChildren).map(child => createVirtualInstance(child, instance));
732
+ }
733
+ return instance;
734
+ };
685
735
  class ReactThreeTestInstance {
686
736
  constructor(_fiber) {
687
737
  this.getChildren = (fiber, opts = {
688
738
  exhaustive: false
689
- }) => fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
690
- this.findAll = decider => findAll(this, decider);
739
+ }) => {
740
+ var _fiber$object$childre;
741
+ // Get standard R3F children
742
+ const r3fChildren = fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
743
+
744
+ // For primitives, also add THREE.js object children
745
+ if (fiber.type === 'primitive' && (_fiber$object$childre = fiber.object.children) != null && _fiber$object$childre.length) {
746
+ const threeChildren = fiber.object.children.map(child => {
747
+ // Create a virtual instance that wraps the THREE.js child
748
+ const virtualInstance = createVirtualInstance(child, fiber);
749
+ return wrapFiber(virtualInstance);
750
+ });
751
+ r3fChildren.push(...threeChildren);
752
+ return r3fChildren;
753
+ }
754
+ return r3fChildren;
755
+ };
756
+ this.findAll = decider => findAll(this, decider, {
757
+ includeRoot: false
758
+ });
691
759
  this.find = decider => expectOne(this.findAll(decider), `matching custom checker: ${decider.toString()}`);
692
760
  this.findByType = type => expectOne(this.findAll(node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
693
761
  this.findAllByType = type => this.findAll(node => Boolean(node.type && node.type === type));
@@ -20,10 +20,25 @@ const graphObjectFactory = (type, name, children) => ({
20
20
  name,
21
21
  children
22
22
  });
23
- const toGraph = object => object.children.map(child => {
24
- var _child$object$name;
25
- return graphObjectFactory(child.object.type, (_child$object$name = child.object.name) != null ? _child$object$name : '', toGraph(child));
26
- });
23
+
24
+ // Helper function to process raw THREE.js children objects
25
+ function processThreeChildren(children) {
26
+ return children.map(object => graphObjectFactory(object.type, object.name || '', object.children && object.children.length > 0 ? processThreeChildren(object.children) : []));
27
+ }
28
+ const toGraph = object => {
29
+ return object.children.map(child => {
30
+ var _child$object$childre, _child$object$name;
31
+ // Process standard R3F children
32
+ const children = toGraph(child);
33
+
34
+ // For primitives, also include THREE.js object children
35
+ if (child.type === 'primitive' && (_child$object$childre = child.object.children) != null && _child$object$childre.length) {
36
+ const threeChildren = processThreeChildren(child.object.children);
37
+ children.push(...threeChildren);
38
+ }
39
+ return graphObjectFactory(child.object.type, (_child$object$name = child.object.name) != null ? _child$object$name : '', children);
40
+ });
41
+ };
27
42
 
28
43
  const functions = ['activeTexture', 'attachShader', 'beginQuery', 'beginTransformFeedback', 'bindAttribLocation', 'bindBufferBase', 'bindBufferRange', 'bindRenderbuffer', 'bindSampler', 'bindTransformFeedback', 'bindVertexArray', 'blendColor', 'blendEquation', 'blendEquationSeparate', 'blendFunc', 'blendFuncSeparate', 'blitFramebuffer', 'bufferData', 'bufferSubData', 'checkFramebufferStatus', 'clientWaitSync', 'compileShader', 'compressedTexImage2D', 'compressedTexImage3D', 'compressedTexSubImage2D', 'compressedTexSubImage3D', 'copyBufferSubData', 'copyTexImage2D', 'copyTexSubImage2D', 'copyTexSubImage3D', 'createBuffer', 'createFramebuffer', 'createProgram', 'createQuery', 'createRenderbuffer', 'createSampler', 'createShader', 'createTexture', 'createTransformFeedback', 'createVertexArray', 'cullFace', 'deleteBuffer', 'deleteFramebuffer', 'deleteProgram', 'deleteQuery', 'deleteRenderbuffer', 'deleteSampler', 'deleteShader', 'deleteSync', 'deleteTexture', 'deleteTransformFeedback', 'deleteVertexArray', 'depthFunc', 'depthMask', 'depthRange', 'detachShader', 'disable', 'drawArraysInstanced', 'drawElementsInstanced', 'drawRangeElements', 'enable', 'endQuery', 'endTransformFeedback', 'fenceSync', 'finish', 'flush', 'framebufferRenderbuffer', 'framebufferTexture2D', 'framebufferTextureLayer', 'frontFace', 'generateMipmap', 'getActiveAttrib', 'getActiveUniform', 'getActiveUniformBlockName', 'getActiveUniformBlockParameter', 'getActiveUniforms', 'getAttachedShaders', 'getAttribLocation', 'getBufferParameter', 'getBufferSubData', 'getContextAttributes', 'getError', 'getExtension', 'getFragDataLocation', 'getFramebufferAttachmentParameter', 'getIndexedParameter', 'getInternalformatParameter', 'getParameter', 'getProgramInfoLog', 'getProgramParameter', 'getQuery', 'getQueryParameter', 'getRenderbufferParameter', 'getSamplerParameter', 'getShaderInfoLog', 'getShaderParameter', 'getShaderPrecisionFormat', 'getShaderSource', 'getSupportedExtensions', 'getSyncParameter', 'getTexParameter', 'getTransformFeedbackVarying', 'getUniform', 'getUniformBlockIndex', 'getUniformIndices', 'getUniformLocation', 'getVertexAttrib', 'getVertexAttribOffset', 'hint', 'invalidateFramebuffer', 'invalidateSubFramebuffer', 'isBuffer', 'isContextLost', 'isEnabled', 'isFramebuffer', 'isProgram', 'isQuery', 'isRenderbuffer', 'isSampler', 'isShader', 'isSync', 'isTexture', 'isTransformFeedback', 'isVertexArray', 'lineWidth', 'linkProgram', 'pauseTransformFeedback', 'pixelStorei', 'polygonOffset', 'readBuffer', 'readPixels', 'renderbufferStorage', 'renderbufferStorageMultisample', 'resumeTransformFeedback', 'sampleCoverage', 'samplerParameterf', 'samplerParameteri', 'shaderSource', 'stencilFunc', 'stencilFuncSeparate', 'stencilMask', 'stencilMaskSeparate', 'stencilOp', 'stencilOpSeparate', 'texImage2D', 'texImage3D', 'texParameterf', 'texParameteri', 'texStorage2D', 'texStorage3D', 'texSubImage2D', 'texSubImage3D', 'transformFeedbackVaryings', 'uniform1ui', 'uniform2ui', 'uniform3ui', 'uniform4ui', 'uniformBlockBinding', 'useProgram', 'validateProgram', 'vertexAttribDivisor', 'vertexAttribI4i', 'vertexAttribI4ui', 'vertexAttribIPointer', 'waitSync', 'bindBuffer', 'bindFramebuffer', 'bindTexture', 'clear', 'clearBufferfi', 'clearBufferfv', 'clearBufferiv', 'clearBufferuiv', 'clearColor', 'clearDepth', 'clearStencil', 'colorMask', 'disableVertexAttribArray', 'drawArrays', 'drawBuffers', 'drawElements', 'enableVertexAttribArray', 'scissor', 'uniform1f', 'uniform1fv', 'uniform1i', 'uniform1iv', 'uniform1uiv', 'uniform2f', 'uniform2fv', 'uniform2i', 'uniform2iv', 'uniform2uiv', 'uniform3f', 'uniform3fv', 'uniform3i', 'uniform3iv', 'uniform3uiv', 'uniform4f', 'uniform4fv', 'uniform4i', 'uniform4iv', 'uniform4uiv', 'uniformMatrix2fv', 'uniformMatrix2x3fv', 'uniformMatrix2x4fv', 'uniformMatrix3fv', 'uniformMatrix3x2fv', 'uniformMatrix3x4fv', 'uniformMatrix4fv', 'uniformMatrix4x2fv', 'uniformMatrix4x3fv', 'vertexAttrib1f', 'vertexAttrib1fv', 'vertexAttrib2f', 'vertexAttrib2fv', 'vertexAttrib3f', 'vertexAttrib3fv', 'vertexAttrib4f', 'vertexAttrib4fv', 'vertexAttribI4iv', 'vertexAttribI4uiv', 'vertexAttribPointer', 'viewport', 'makeXRCompatible'];
29
44
  const enums = {
@@ -648,23 +663,76 @@ const matchProps = (props, filter) => {
648
663
  }
649
664
  return true;
650
665
  };
651
- const findAll = (root, decider) => {
666
+ const findAll = (root, decider, options = {
667
+ includeRoot: true
668
+ }) => {
652
669
  const results = [];
653
- if (decider(root)) {
670
+
671
+ // Only include the root node if the option is enabled
672
+ if (options.includeRoot !== false && decider(root)) {
654
673
  results.push(root);
655
674
  }
675
+
676
+ // Always search through children
656
677
  root.allChildren.forEach(child => {
657
- results.push(...findAll(child, decider));
678
+ // When recursively searching children, we always want to include their roots
679
+ results.push(...findAll(child, decider, {
680
+ includeRoot: true
681
+ }));
658
682
  });
659
683
  return results;
660
684
  };
661
685
 
686
+ // Helper to create a minimal wrapper for THREE.Object3D children of primitives
687
+ const createVirtualInstance = (object, parent) => {
688
+ // Create the virtual instance for this object
689
+ // we can't import the prepare method from packages/fiber/src/core/utils.tsx so we do what we can
690
+ const instance = {
691
+ root: parent.root,
692
+ type: object.type.toLowerCase(),
693
+ // Convert to lowercase to match R3F convention
694
+ parent,
695
+ children: [],
696
+ props: {
697
+ object
698
+ },
699
+ object,
700
+ eventCount: 0,
701
+ handlers: {},
702
+ isHidden: false
703
+ };
704
+
705
+ // Recursively process children if they exist
706
+ if (object.children && object.children.length > 0) {
707
+ const objectChildren = object.children;
708
+ instance.children = Array.from(objectChildren).map(child => createVirtualInstance(child, instance));
709
+ }
710
+ return instance;
711
+ };
662
712
  class ReactThreeTestInstance {
663
713
  constructor(_fiber) {
664
714
  this.getChildren = (fiber, opts = {
665
715
  exhaustive: false
666
- }) => fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
667
- this.findAll = decider => findAll(this, decider);
716
+ }) => {
717
+ var _fiber$object$childre;
718
+ // Get standard R3F children
719
+ const r3fChildren = fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
720
+
721
+ // For primitives, also add THREE.js object children
722
+ if (fiber.type === 'primitive' && (_fiber$object$childre = fiber.object.children) != null && _fiber$object$childre.length) {
723
+ const threeChildren = fiber.object.children.map(child => {
724
+ // Create a virtual instance that wraps the THREE.js child
725
+ const virtualInstance = createVirtualInstance(child, fiber);
726
+ return wrapFiber(virtualInstance);
727
+ });
728
+ r3fChildren.push(...threeChildren);
729
+ return r3fChildren;
730
+ }
731
+ return r3fChildren;
732
+ };
733
+ this.findAll = decider => findAll(this, decider, {
734
+ includeRoot: false
735
+ });
668
736
  this.find = decider => expectOne(this.findAll(decider), `matching custom checker: ${decider.toString()}`);
669
737
  this.findByType = type => expectOne(this.findAll(node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
670
738
  this.findAllByType = type => this.findAll(node => Boolean(node.type && node.type === type));
package/package.json CHANGED
@@ -1,29 +1,57 @@
1
- {
2
- "name": "@react-three/test-renderer",
3
- "version": "9.0.1",
4
- "description": "Test Renderer for react-three-fiber",
5
- "author": "Josh Ellis",
6
- "license": "MIT",
7
- "private": false,
8
- "main": "dist/react-three-test-renderer.cjs.js",
9
- "module": "dist/react-three-test-renderer.esm.js",
10
- "types": "dist/react-three-test-renderer.cjs.d.ts",
11
- "bugs": {
12
- "url": "https://github.com/pmndrs/react-three-fiber/issues"
13
- },
14
- "homepage": "https://github.com/pmndrs/react-three-fiber/packages/react-three-test-renderer",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/pmndrs/react-three-fiber.git"
18
- },
19
- "preconstruct": {
20
- "entrypoints": [
21
- "index.tsx"
22
- ]
23
- },
24
- "peerDependencies": {
25
- "react": "^19.0.0",
26
- "@react-three/fiber": ">=9.0.0",
27
- "three": ">=0.156"
28
- }
29
- }
1
+ {
2
+ "name": "@react-three/test-renderer",
3
+ "version": "10.0.0-alpha.0",
4
+ "description": "Test Renderer for react-three-fiber",
5
+ "author": "Josh Ellis",
6
+ "license": "MIT",
7
+ "main": "dist/react-three-test-renderer.cjs.js",
8
+ "module": "dist/react-three-test-renderer.esm.js",
9
+ "types": "dist/react-three-test-renderer.cjs.d.ts",
10
+ "sideEffects": false,
11
+ "exports": {
12
+ ".": {
13
+ "types": "./src/index.tsx",
14
+ "import": "./dist/react-three-test-renderer.esm.js",
15
+ "require": "./dist/react-three-test-renderer.cjs.js"
16
+ },
17
+ "./legacy": {
18
+ "types": "./src/legacy.tsx",
19
+ "import": "./dist/legacy.esm.js",
20
+ "require": "./dist/legacy.cjs.js"
21
+ },
22
+ "./webgpu": {
23
+ "types": "./src/webgpu/index.tsx",
24
+ "import": "./dist/webgpu.esm.js",
25
+ "require": "./dist/webgpu.cjs.js"
26
+ }
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/pmndrs/react-three-fiber/issues"
30
+ },
31
+ "homepage": "https://github.com/pmndrs/react-three-fiber/packages/react-three-test-renderer",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/pmndrs/react-three-fiber.git"
35
+ },
36
+ "preconstruct": {
37
+ "entrypoints": [
38
+ "index.tsx",
39
+ "legacy.tsx",
40
+ "webgpu/index.tsx"
41
+ ]
42
+ },
43
+ "peerDependencies": {
44
+ "@react-three/fiber": ">=10.0.0-alpha.0",
45
+ "react": "^19.0.0",
46
+ "three": ">=0.181"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "three": {
50
+ "optional": false
51
+ }
52
+ },
53
+ "devDependencies": {
54
+ "@react-three/fiber": "workspace:*",
55
+ "three": ">=0.181"
56
+ }
57
+ }