@react-three/test-renderer 10.0.0-canary.07c4f9d → 10.0.0-canary.0aed646

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/README.md CHANGED
@@ -34,9 +34,10 @@ Choose the entry point that matches your `@react-three/fiber` import:
34
34
 
35
35
  | Your Fiber Import | Test Renderer Import | Use Case |
36
36
  | --------------------------- | ----------------------------------- | ------------------------------------ |
37
- | `@react-three/fiber` | `@react-three/test-renderer` | Default (WebGL with WebGPU fallback) |
37
+ | `@react-three/fiber` | `@react-three/test-renderer` | Default (WebGPU, mocked GPU context) |
38
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 |
39
+
40
+ Whichever entry you pick, the root resolves JSX elements from the three namespace of the renderer it loads, exactly as in the app: node materials exist under WebGPU and not under WebGL.
40
41
 
41
42
  ### Default Entry
42
43
 
@@ -72,18 +73,16 @@ import { Canvas } from '@react-three/fiber/legacy'
72
73
  const renderer = await ReactThreeTestRenderer.create(<MyScene />)
73
74
  ```
74
75
 
75
- ### WebGPU Entry
76
+ ### TSL (Three Shading Language)
76
77
 
77
- For applications using WebGPU with TSL (Three Shading Language):
78
+ The default entry renders with `WebGPURenderer`, so node materials and the TSL hooks work without
79
+ any setup. It replaces `@react-three/test-renderer/webgpu`, which is removed.
78
80
 
79
81
  ```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'
82
+ import ReactThreeTestRenderer from '@react-three/test-renderer'
83
+ import { color } from 'three/tsl'
84
+ // The TSL hooks come from @react-three/tsl, in tests as in app code
85
+ import { useUniforms, useNodes } from '@react-three/tsl'
87
86
 
88
87
  // Component using WebGPU hooks
89
88
  function MyWebGPUScene() {
@@ -134,23 +133,12 @@ console.log(renderer.toGraph())
134
133
 
135
134
  ## Testing WebGPU Hooks
136
135
 
137
- The `/webgpu` entry exports all WebGPU-specific hooks for testing TSL uniforms and nodes:
136
+ Test TSL uniforms and nodes with the default entry and the hooks from `@react-three/tsl`:
138
137
 
139
138
  ```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'
139
+ import ReactThreeTestRenderer from '@react-three/test-renderer'
140
+ import { color } from 'three/tsl'
141
+ import { useUniforms, useNodes } from '@react-three/tsl'
154
142
 
155
143
  describe('My WebGPU Scene', () => {
156
144
  it('should create and use uniforms', async () => {
@@ -200,23 +188,15 @@ describe('My WebGPU Scene', () => {
200
188
 
201
189
  ---
202
190
 
203
- ## Migration from v8
191
+ ## Upgrading from v9
204
192
 
205
- If you're upgrading from v8 and using WebGPU features:
193
+ v9 had one entry, which rendered with WebGL. In v10 the default entry renders with WebGPU, to match
194
+ `@react-three/fiber`. If your app imports `Canvas` from `@react-three/fiber/legacy`, test with the
195
+ `/legacy` entry:
206
196
 
207
197
  ```diff
208
- // Before (v8) - single entry point
209
198
  -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
199
  +import ReactThreeTestRenderer from '@react-three/test-renderer/legacy'
217
-
218
- // For default (auto-detection):
219
- +import ReactThreeTestRenderer from '@react-three/test-renderer'
220
200
  ```
221
201
 
222
202
  ---
@@ -225,4 +205,4 @@ If you're upgrading from v8 and using WebGPU features:
225
205
 
226
206
  - [React Three Test Renderer API](./markdown/rttr.md)
227
207
  - [React Three Test Instance API](./markdown/rttr-instance.md)
228
- - [WebGPU Testing Guide](./markdown/webgpu-testing.md)
208
+ - [Testing WebGPU and TSL](https://r3f.docs.pmnd.rs/next/api/testing#testing-webgpu-and-tsl)
package/dist/index.cjs CHANGED
@@ -3,22 +3,400 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const react = require('react');
6
- const THREE = require('three');
7
6
  const fiber = require('@react-three/fiber');
8
7
 
9
- function _interopNamespaceCompat(e) {
10
- if (e && typeof e === 'object' && 'default' in e) return e;
11
- const n = Object.create(null);
12
- if (e) {
13
- for (const k in e) {
14
- n[k] = e[k];
15
- }
8
+ var __defProp$2 = Object.defineProperty;
9
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ class MockGPUBuffer {
12
+ constructor(descriptor) {
13
+ __publicField$2(this, "size");
14
+ __publicField$2(this, "usage");
15
+ __publicField$2(this, "mapState", "unmapped");
16
+ this.size = descriptor.size;
17
+ this.usage = descriptor.usage;
18
+ }
19
+ getMappedRange(_offset, _size) {
20
+ return new ArrayBuffer(this.size);
21
+ }
22
+ unmap() {
23
+ }
24
+ destroy() {
25
+ }
26
+ async mapAsync(_mode, _offset, _size) {
16
27
  }
17
- n.default = e;
18
- return n;
19
28
  }
20
-
21
- const THREE__namespace = /*#__PURE__*/_interopNamespaceCompat(THREE);
29
+ class MockGPUTexture {
30
+ constructor(descriptor) {
31
+ __publicField$2(this, "width");
32
+ __publicField$2(this, "height");
33
+ __publicField$2(this, "depthOrArrayLayers");
34
+ __publicField$2(this, "mipLevelCount");
35
+ __publicField$2(this, "sampleCount");
36
+ __publicField$2(this, "dimension");
37
+ __publicField$2(this, "format");
38
+ __publicField$2(this, "usage");
39
+ this.width = typeof descriptor.size === "number" ? descriptor.size : descriptor.size.width ?? 1;
40
+ this.height = typeof descriptor.size === "number" ? 1 : descriptor.size.height ?? 1;
41
+ this.depthOrArrayLayers = typeof descriptor.size === "number" ? 1 : descriptor.size.depthOrArrayLayers ?? 1;
42
+ this.mipLevelCount = descriptor.mipLevelCount ?? 1;
43
+ this.sampleCount = descriptor.sampleCount ?? 1;
44
+ this.dimension = descriptor.dimension ?? "2d";
45
+ this.format = descriptor.format;
46
+ this.usage = descriptor.usage;
47
+ }
48
+ createView(_descriptor) {
49
+ return new MockGPUTextureView();
50
+ }
51
+ destroy() {
52
+ }
53
+ }
54
+ class MockGPUTextureView {
55
+ constructor() {
56
+ __publicField$2(this, "label");
57
+ }
58
+ }
59
+ class MockGPUSampler {
60
+ constructor(_descriptor) {
61
+ __publicField$2(this, "label");
62
+ }
63
+ }
64
+ class MockGPUShaderModule {
65
+ constructor(_descriptor) {
66
+ __publicField$2(this, "label");
67
+ }
68
+ getCompilationInfo() {
69
+ return Promise.resolve({ messages: [] });
70
+ }
71
+ }
72
+ class MockGPUBindGroupLayout {
73
+ constructor(_descriptor) {
74
+ __publicField$2(this, "label");
75
+ }
76
+ }
77
+ class MockGPUBindGroup {
78
+ constructor(_descriptor) {
79
+ __publicField$2(this, "label");
80
+ }
81
+ }
82
+ class MockGPUPipelineLayout {
83
+ constructor(_descriptor) {
84
+ __publicField$2(this, "label");
85
+ }
86
+ }
87
+ class MockGPURenderPipeline {
88
+ constructor(_descriptor) {
89
+ __publicField$2(this, "label");
90
+ }
91
+ getBindGroupLayout(_index) {
92
+ return new MockGPUBindGroupLayout({ entries: [] });
93
+ }
94
+ }
95
+ class MockGPUComputePipeline {
96
+ constructor(_descriptor) {
97
+ __publicField$2(this, "label");
98
+ }
99
+ getBindGroupLayout(_index) {
100
+ return new MockGPUBindGroupLayout({ entries: [] });
101
+ }
102
+ }
103
+ class MockGPUCommandEncoder {
104
+ constructor() {
105
+ __publicField$2(this, "label");
106
+ }
107
+ beginRenderPass(_descriptor) {
108
+ return new MockGPURenderPassEncoder();
109
+ }
110
+ beginComputePass(_descriptor) {
111
+ return new MockGPUComputePassEncoder();
112
+ }
113
+ copyBufferToBuffer(_source, _sourceOffset, _destination, _destinationOffset, _size) {
114
+ }
115
+ copyBufferToTexture(_source, _destination, _copySize) {
116
+ }
117
+ copyTextureToBuffer(_source, _destination, _copySize) {
118
+ }
119
+ copyTextureToTexture(_source, _destination, _copySize) {
120
+ }
121
+ finish(_descriptor) {
122
+ return new MockGPUCommandBuffer();
123
+ }
124
+ }
125
+ class MockGPURenderPassEncoder {
126
+ setPipeline(_pipeline) {
127
+ }
128
+ setBindGroup(_index, _bindGroup, _dynamicOffsets) {
129
+ }
130
+ setVertexBuffer(_slot, _buffer, _offset, _size) {
131
+ }
132
+ setIndexBuffer(_buffer, _indexFormat, _offset, _size) {
133
+ }
134
+ setViewport(_x, _y, _width, _height, _minDepth, _maxDepth) {
135
+ }
136
+ setScissorRect(_x, _y, _width, _height) {
137
+ }
138
+ setBlendConstant(_color) {
139
+ }
140
+ setStencilReference(_reference) {
141
+ }
142
+ draw(_vertexCount, _instanceCount, _firstVertex, _firstInstance) {
143
+ }
144
+ drawIndexed(_indexCount, _instanceCount, _firstIndex, _baseVertex, _firstInstance) {
145
+ }
146
+ drawIndirect(_indirectBuffer, _indirectOffset) {
147
+ }
148
+ drawIndexedIndirect(_indirectBuffer, _indirectOffset) {
149
+ }
150
+ end() {
151
+ }
152
+ }
153
+ class MockGPUComputePassEncoder {
154
+ setPipeline(_pipeline) {
155
+ }
156
+ setBindGroup(_index, _bindGroup, _dynamicOffsets) {
157
+ }
158
+ dispatchWorkgroups(_workgroupCountX, _workgroupCountY, _workgroupCountZ) {
159
+ }
160
+ dispatchWorkgroupsIndirect(_indirectBuffer, _indirectOffset) {
161
+ }
162
+ end() {
163
+ }
164
+ }
165
+ class MockGPUCommandBuffer {
166
+ constructor() {
167
+ __publicField$2(this, "label");
168
+ }
169
+ }
170
+ class MockGPUQueue {
171
+ constructor() {
172
+ __publicField$2(this, "label");
173
+ }
174
+ submit(_commandBuffers) {
175
+ }
176
+ writeBuffer(_buffer, _bufferOffset, _data, _dataOffset, _size) {
177
+ }
178
+ writeTexture(_destination, _data, _dataLayout, _size) {
179
+ }
180
+ copyExternalImageToTexture(_source, _destination, _copySize) {
181
+ }
182
+ onSubmittedWorkDone() {
183
+ return Promise.resolve();
184
+ }
185
+ }
186
+ class MockGPUQuerySet {
187
+ constructor(descriptor) {
188
+ __publicField$2(this, "type");
189
+ __publicField$2(this, "count");
190
+ this.type = descriptor.type;
191
+ this.count = descriptor.count;
192
+ }
193
+ destroy() {
194
+ }
195
+ }
196
+ class MockGPUDevice extends EventTarget {
197
+ constructor() {
198
+ super();
199
+ __publicField$2(this, "features", /* @__PURE__ */ new Set());
200
+ __publicField$2(this, "limits", createMockLimits());
201
+ __publicField$2(this, "queue", new MockGPUQueue());
202
+ __publicField$2(this, "lost");
203
+ __publicField$2(this, "label");
204
+ __publicField$2(this, "_destroyed", false);
205
+ this.lost = new Promise(() => {
206
+ });
207
+ }
208
+ destroy() {
209
+ this._destroyed = true;
210
+ }
211
+ // Buffer Creation --
212
+ createBuffer(descriptor) {
213
+ return new MockGPUBuffer(descriptor);
214
+ }
215
+ // Texture Creation --
216
+ createTexture(descriptor) {
217
+ return new MockGPUTexture(descriptor);
218
+ }
219
+ createSampler(descriptor) {
220
+ return new MockGPUSampler(descriptor);
221
+ }
222
+ // Shader/Pipeline Creation --
223
+ createShaderModule(descriptor) {
224
+ return new MockGPUShaderModule(descriptor);
225
+ }
226
+ createBindGroupLayout(descriptor) {
227
+ return new MockGPUBindGroupLayout(descriptor);
228
+ }
229
+ createBindGroup(descriptor) {
230
+ return new MockGPUBindGroup(descriptor);
231
+ }
232
+ createPipelineLayout(descriptor) {
233
+ return new MockGPUPipelineLayout(descriptor);
234
+ }
235
+ createRenderPipeline(descriptor) {
236
+ return new MockGPURenderPipeline(descriptor);
237
+ }
238
+ async createRenderPipelineAsync(descriptor) {
239
+ return new MockGPURenderPipeline(descriptor);
240
+ }
241
+ createComputePipeline(descriptor) {
242
+ return new MockGPUComputePipeline(descriptor);
243
+ }
244
+ async createComputePipelineAsync(descriptor) {
245
+ return new MockGPUComputePipeline(descriptor);
246
+ }
247
+ // Command Encoding --
248
+ createCommandEncoder(_descriptor) {
249
+ return new MockGPUCommandEncoder();
250
+ }
251
+ // Query Sets --
252
+ createQuerySet(descriptor) {
253
+ return new MockGPUQuerySet(descriptor);
254
+ }
255
+ // Error Handling --
256
+ pushErrorScope(_filter) {
257
+ }
258
+ popErrorScope() {
259
+ return Promise.resolve(null);
260
+ }
261
+ }
262
+ class MockGPUAdapter {
263
+ constructor() {
264
+ __publicField$2(this, "features", /* @__PURE__ */ new Set());
265
+ __publicField$2(this, "limits", createMockLimits());
266
+ __publicField$2(this, "isFallbackAdapter", false);
267
+ }
268
+ async requestDevice(_descriptor) {
269
+ return new MockGPUDevice();
270
+ }
271
+ async requestAdapterInfo() {
272
+ return {
273
+ vendor: "Mock",
274
+ architecture: "Mock",
275
+ device: "Mock Test Renderer",
276
+ description: "Mock WebGPU Adapter for Testing"
277
+ };
278
+ }
279
+ }
280
+ class MockGPU {
281
+ constructor() {
282
+ __publicField$2(this, "wgslLanguageFeatures", /* @__PURE__ */ new Set());
283
+ }
284
+ async requestAdapter(_options) {
285
+ return new MockGPUAdapter();
286
+ }
287
+ getPreferredCanvasFormat() {
288
+ return "bgra8unorm";
289
+ }
290
+ }
291
+ class MockGPUCanvasContext {
292
+ constructor(canvas) {
293
+ __publicField$2(this, "canvas");
294
+ __publicField$2(this, "_configuration", null);
295
+ this.canvas = canvas;
296
+ }
297
+ configure(configuration) {
298
+ this._configuration = configuration;
299
+ }
300
+ unconfigure() {
301
+ this._configuration = null;
302
+ }
303
+ getCurrentTexture() {
304
+ const width = this.canvas instanceof HTMLCanvasElement ? this.canvas.width : this.canvas.width;
305
+ const height = this.canvas instanceof HTMLCanvasElement ? this.canvas.height : this.canvas.height;
306
+ return new MockGPUTexture({
307
+ size: { width, height },
308
+ format: this._configuration?.format ?? "bgra8unorm",
309
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
310
+ });
311
+ }
312
+ }
313
+ function createMockLimits() {
314
+ return {
315
+ maxTextureDimension1D: 8192,
316
+ maxTextureDimension2D: 8192,
317
+ maxTextureDimension3D: 2048,
318
+ maxTextureArrayLayers: 256,
319
+ maxBindGroups: 4,
320
+ maxBindGroupsPlusVertexBuffers: 24,
321
+ maxBindingsPerBindGroup: 1e3,
322
+ maxDynamicUniformBuffersPerPipelineLayout: 8,
323
+ maxDynamicStorageBuffersPerPipelineLayout: 4,
324
+ maxSampledTexturesPerShaderStage: 16,
325
+ maxSamplersPerShaderStage: 16,
326
+ maxStorageBuffersPerShaderStage: 8,
327
+ maxStorageTexturesPerShaderStage: 4,
328
+ maxUniformBuffersPerShaderStage: 12,
329
+ maxUniformBufferBindingSize: 65536,
330
+ maxStorageBufferBindingSize: 134217728,
331
+ minUniformBufferOffsetAlignment: 256,
332
+ minStorageBufferOffsetAlignment: 256,
333
+ maxVertexBuffers: 8,
334
+ maxBufferSize: 268435456,
335
+ maxVertexAttributes: 16,
336
+ maxVertexBufferArrayStride: 2048,
337
+ maxInterStageShaderVariables: 16,
338
+ maxColorAttachments: 8,
339
+ maxColorAttachmentBytesPerSample: 32,
340
+ maxComputeWorkgroupStorageSize: 16384,
341
+ maxComputeInvocationsPerWorkgroup: 256,
342
+ maxComputeWorkgroupSizeX: 256,
343
+ maxComputeWorkgroupSizeY: 256,
344
+ maxComputeWorkgroupSizeZ: 64,
345
+ maxComputeWorkgroupsPerDimension: 65535
346
+ };
347
+ }
348
+ function mockWebGPU() {
349
+ const mockGPU = new MockGPU();
350
+ if (typeof globalThis.navigator === "undefined") {
351
+ globalThis.navigator = {};
352
+ }
353
+ globalThis.navigator.gpu = mockGPU;
354
+ globalThis.GPUTextureUsage = {
355
+ COPY_SRC: 1,
356
+ COPY_DST: 2,
357
+ TEXTURE_BINDING: 4,
358
+ STORAGE_BINDING: 8,
359
+ RENDER_ATTACHMENT: 16
360
+ };
361
+ globalThis.GPUBufferUsage = {
362
+ MAP_READ: 1,
363
+ MAP_WRITE: 2,
364
+ COPY_SRC: 4,
365
+ COPY_DST: 8,
366
+ INDEX: 16,
367
+ VERTEX: 32,
368
+ UNIFORM: 64,
369
+ STORAGE: 128,
370
+ INDIRECT: 256,
371
+ QUERY_RESOLVE: 512
372
+ };
373
+ globalThis.GPUMapMode = {
374
+ READ: 1,
375
+ WRITE: 2
376
+ };
377
+ globalThis.GPUShaderStage = {
378
+ VERTEX: 1,
379
+ FRAGMENT: 2,
380
+ COMPUTE: 4
381
+ };
382
+ globalThis.GPUColorWrite = {
383
+ RED: 1,
384
+ GREEN: 2,
385
+ BLUE: 4,
386
+ ALPHA: 8,
387
+ ALL: 15
388
+ };
389
+ }
390
+ function unmockWebGPU() {
391
+ if (typeof globalThis.navigator !== "undefined") {
392
+ delete globalThis.navigator.gpu;
393
+ }
394
+ delete globalThis.GPUTextureUsage;
395
+ delete globalThis.GPUBufferUsage;
396
+ delete globalThis.GPUMapMode;
397
+ delete globalThis.GPUShaderStage;
398
+ delete globalThis.GPUColorWrite;
399
+ }
22
400
 
23
401
  const lowerCaseFirstLetter = (str) => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
24
402
  const toEventHandlerName = (eventName) => `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
@@ -62,9 +440,9 @@ const toGraph = (object) => {
62
440
  });
63
441
  };
64
442
 
65
- var __defProp$2 = Object.defineProperty;
66
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
67
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
443
+ var __defProp$1 = Object.defineProperty;
444
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
445
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
68
446
  const functions = [
69
447
  "activeTexture",
70
448
  "attachShader",
@@ -784,18 +1162,18 @@ const extensions = {
784
1162
  const returnsHandle = (method) => method.startsWith("create") || method === "fenceSync";
785
1163
  class WebGL2RenderingContext {
786
1164
  constructor(canvas) {
787
- __publicField$2(this, "getShaderPrecisionFormat", () => {
1165
+ __publicField$1(this, "getShaderPrecisionFormat", () => {
788
1166
  return {
789
1167
  rangeMin: 127,
790
1168
  rangeMax: 127,
791
1169
  precision: 23
792
1170
  };
793
1171
  });
794
- __publicField$2(this, "GL_VERSION", 7938);
795
- __publicField$2(this, "SCISSOR_BOX", 3088);
796
- __publicField$2(this, "VIEWPORT", 2978);
797
- __publicField$2(this, "getProgramInfoLog", () => "");
798
- __publicField$2(this, "getShaderInfoLog", () => "");
1172
+ __publicField$1(this, "GL_VERSION", 7938);
1173
+ __publicField$1(this, "SCISSOR_BOX", 3088);
1174
+ __publicField$1(this, "VIEWPORT", 2978);
1175
+ __publicField$1(this, "getProgramInfoLog", () => "");
1176
+ __publicField$1(this, "getShaderInfoLog", () => "");
799
1177
  this.canvas = canvas;
800
1178
  this.drawingBufferWidth = canvas.width;
801
1179
  this.drawingBufferHeight = canvas.height;
@@ -817,61 +1195,10 @@ class WebGL2RenderingContext {
817
1195
  getExtension(ext) {
818
1196
  return extensions[ext];
819
1197
  }
820
- }
821
-
822
- var __defProp$1 = Object.defineProperty;
823
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
824
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
825
- class MockGPUTexture {
826
- constructor(descriptor) {
827
- __publicField$1(this, "width");
828
- __publicField$1(this, "height");
829
- __publicField$1(this, "depthOrArrayLayers");
830
- __publicField$1(this, "mipLevelCount");
831
- __publicField$1(this, "sampleCount");
832
- __publicField$1(this, "dimension");
833
- __publicField$1(this, "format");
834
- __publicField$1(this, "usage");
835
- this.width = typeof descriptor.size === "number" ? descriptor.size : descriptor.size.width ?? 1;
836
- this.height = typeof descriptor.size === "number" ? 1 : descriptor.size.height ?? 1;
837
- this.depthOrArrayLayers = typeof descriptor.size === "number" ? 1 : descriptor.size.depthOrArrayLayers ?? 1;
838
- this.mipLevelCount = descriptor.mipLevelCount ?? 1;
839
- this.sampleCount = descriptor.sampleCount ?? 1;
840
- this.dimension = descriptor.dimension ?? "2d";
841
- this.format = descriptor.format;
842
- this.usage = descriptor.usage;
843
- }
844
- createView(_descriptor) {
845
- return new MockGPUTextureView();
846
- }
847
- destroy() {
848
- }
849
- }
850
- class MockGPUTextureView {
851
- constructor() {
852
- __publicField$1(this, "label");
853
- }
854
- }
855
- class MockGPUCanvasContext {
856
- constructor(canvas) {
857
- __publicField$1(this, "canvas");
858
- __publicField$1(this, "_configuration", null);
859
- this.canvas = canvas;
860
- }
861
- configure(configuration) {
862
- this._configuration = configuration;
863
- }
864
- unconfigure() {
865
- this._configuration = null;
866
- }
867
- getCurrentTexture() {
868
- const width = this.canvas instanceof HTMLCanvasElement ? this.canvas.width : this.canvas.width;
869
- const height = this.canvas instanceof HTMLCanvasElement ? this.canvas.height : this.canvas.height;
870
- return new MockGPUTexture({
871
- size: { width, height },
872
- format: this._configuration?.format ?? "bgra8unorm",
873
- usage: GPUTextureUsage.RENDER_ATTACHMENT
874
- });
1198
+ // WebGPURenderer's WebGL2 fallback backend lists the supported extensions up front and checks
1199
+ // them with `.includes()`, so this has to return an array rather than the no-op stub's undefined
1200
+ getSupportedExtensions() {
1201
+ return Object.keys(extensions);
875
1202
  }
876
1203
  }
877
1204
 
@@ -1061,6 +1388,7 @@ const createVirtualInstance = (object, parent) => {
1061
1388
  object,
1062
1389
  eventCount: 0,
1063
1390
  handlers: {},
1391
+ previousVisible: void 0,
1064
1392
  isHidden: false
1065
1393
  };
1066
1394
  if (object.children && object.children.length > 0) {
@@ -1144,8 +1472,7 @@ async function waitFor(callback, { interval = 50, timeout = 5e3 } = {}) {
1144
1472
  }
1145
1473
 
1146
1474
  function createTestRenderer(deps) {
1147
- const { THREE: THREE2, createRoot, mockRoots, reconciler, act, extend, mode } = deps;
1148
- extend(THREE2);
1475
+ const { createRoot, mockRoots, reconciler, act, mode } = deps;
1149
1476
  const create = async (element, options) => {
1150
1477
  const canvas = createCanvas({ ...options, mode });
1151
1478
  const _root = createRoot(canvas);
@@ -1233,15 +1560,14 @@ const index$1 = {
1233
1560
  ReactThreeTestInstance: ReactThreeTestInstance
1234
1561
  };
1235
1562
 
1563
+ mockWebGPU();
1236
1564
  const renderer = createTestRenderer({
1237
- THREE: THREE__namespace,
1238
1565
  createRoot: fiber.createRoot,
1239
1566
  mockRoots: fiber._roots,
1240
1567
  reconciler: fiber.reconciler,
1241
1568
  act: react.act,
1242
- extend: fiber.extend,
1243
- mode: "webgl"
1244
- // Default uses WebGL context
1569
+ mode: "webgpu"
1570
+ // The root entry renders with WebGPURenderer
1245
1571
  });
1246
1572
  const { create } = renderer;
1247
1573
  const index = { create, act: react.act, waitFor };
@@ -1250,4 +1576,6 @@ exports.act = react.act;
1250
1576
  exports.ReactThreeTest = index$1;
1251
1577
  exports.create = create;
1252
1578
  exports.default = index;
1579
+ exports.mockWebGPU = mockWebGPU;
1580
+ exports.unmockWebGPU = unmockWebGPU;
1253
1581
  exports.waitFor = waitFor;
package/dist/index.d.cts CHANGED
@@ -88,6 +88,16 @@ interface WaitOptions {
88
88
  }
89
89
  declare function waitFor(callback: () => boolean | void, { interval, timeout }?: WaitOptions): Promise<void>;
90
90
 
91
+ /**
92
+ * Installs WebGPU mocks into the global scope
93
+ * Call this before running tests that use WebGPU
94
+ */
95
+ declare function mockWebGPU(): void;
96
+ /**
97
+ * Removes WebGPU mocks from the global scope
98
+ */
99
+ declare function unmockWebGPU(): void;
100
+
91
101
  declare const index_Act: typeof Act;
92
102
  type index_CreateOptions = CreateOptions;
93
103
  type index_MockSyntheticEvent = MockSyntheticEvent;
@@ -113,5 +123,5 @@ declare const _default: {
113
123
 
114
124
  // @ts-ignore
115
125
  export = _default;
116
- export { index as ReactThreeTest, create, waitFor };
126
+ export { index as ReactThreeTest, create, mockWebGPU, unmockWebGPU, waitFor };
117
127
  export type { WaitOptions };