@react-three/test-renderer 10.0.0-alpha.2 → 10.0.0-alpha.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-2025 Poimandres
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,228 +1,228 @@
1
- # React Three Test Renderer ⚛️🔼🧪
2
-
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
- [![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
- [![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
- [![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/ZZjjNvJ)
7
-
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.
9
-
10
- ```bash
11
- yarn add @react-three/fiber three
12
- yarn add -D @react-three/test-renderer
13
- ```
14
-
15
- ---
16
-
17
- ## The problem
18
-
19
- You've written a complex and amazing webgl experience using [`@react-three/fiber`](https://github.com/pmndrs/react-three-fiber) and you want to test it to make sure it works even after you add even more features.
20
-
21
- You go to use `react-dom` but hang on, `THREE` elements aren't in the DOM! You decide to use `@react-three/test-renderer` you can see the container & the canvas but you can't see the tree for the scene!? That's because `@react-three/fiber` renders to a different react root with it's own reconciler.
22
-
23
- ## The solution
24
-
25
- You use `@react-three/test-renderer` ⚛️-🔼-🧪, an experimental React renderer using `@react-three/fiber` under the hood to expose the scene graph wrapped in a test instance providing helpful utilities to test with.
26
-
27
- Essentially, this package makes it easy to grab a snapshot of the Scene Graph rendered by `three` without the need for webgl & browser.
28
-
29
- ---
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
-
109
- ## Usage
110
-
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.
112
-
113
- ```tsx
114
- import ReactThreeTestRenderer from '@react-three/test-renderer'
115
-
116
- const renderer = await ReactThreeTestRenderer.create(
117
- <mesh>
118
- <boxGeometry args={[2, 2]} />
119
- <meshStandardMaterial
120
- args={[
121
- {
122
- color: 0x0000ff,
123
- },
124
- ]}
125
- />
126
- </mesh>,
127
- )
128
-
129
- // assertions using the TestInstance & Scene Graph
130
- console.log(renderer.toGraph())
131
- ```
132
-
133
- ---
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
-
224
- ## API
225
-
226
- - [React Three Test Renderer API](/packages/test-renderer/markdown/rttr.md)
227
- - [React Three Test Instance API](/packages/test-renderer/markdown/rttr-instance.md)
228
- - [WebGPU Testing Guide](/packages/test-renderer/markdown/webgpu-testing.md)
1
+ # React Three Test Renderer ⚛️🔼🧪
2
+
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
+ [![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
+ [![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
+ [![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/ZZjjNvJ)
7
+
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.
9
+
10
+ ```bash
11
+ yarn add @react-three/fiber three
12
+ yarn add -D @react-three/test-renderer
13
+ ```
14
+
15
+ ---
16
+
17
+ ## The problem
18
+
19
+ You've written a complex and amazing webgl experience using [`@react-three/fiber`](https://github.com/pmndrs/react-three-fiber) and you want to test it to make sure it works even after you add even more features.
20
+
21
+ You go to use `react-dom` but hang on, `THREE` elements aren't in the DOM! You decide to use `@react-three/test-renderer` you can see the container & the canvas but you can't see the tree for the scene!? That's because `@react-three/fiber` renders to a different react root with it's own reconciler.
22
+
23
+ ## The solution
24
+
25
+ You use `@react-three/test-renderer` ⚛️-🔼-🧪, an experimental React renderer using `@react-three/fiber` under the hood to expose the scene graph wrapped in a test instance providing helpful utilities to test with.
26
+
27
+ Essentially, this package makes it easy to grab a snapshot of the Scene Graph rendered by `three` without the need for webgl & browser.
28
+
29
+ ---
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
+
109
+ ## Usage
110
+
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.
112
+
113
+ ```tsx
114
+ import ReactThreeTestRenderer from '@react-three/test-renderer'
115
+
116
+ const renderer = await ReactThreeTestRenderer.create(
117
+ <mesh>
118
+ <boxGeometry args={[2, 2]} />
119
+ <meshStandardMaterial
120
+ args={[
121
+ {
122
+ color: 0x0000ff,
123
+ },
124
+ ]}
125
+ />
126
+ </mesh>,
127
+ )
128
+
129
+ // assertions using the TestInstance & Scene Graph
130
+ console.log(renderer.toGraph())
131
+ ```
132
+
133
+ ---
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
+
224
+ ## API
225
+
226
+ - [React Three Test Renderer API](./markdown/rttr.md)
227
+ - [React Three Test Instance API](./markdown/rttr-instance.md)
228
+ - [WebGPU Testing Guide](./markdown/webgpu-testing.md)