@react-three/test-renderer 8.2.0 → 9.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.
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var THREE = require('three');
6
6
  var fiber = require('@react-three/fiber');
7
- var React = require('react');
8
7
 
9
8
  function _interopNamespace(e) {
10
9
  if (e && e.__esModule) return e;
@@ -25,7 +24,6 @@ function _interopNamespace(e) {
25
24
  }
26
25
 
27
26
  var THREE__namespace = /*#__PURE__*/_interopNamespace(THREE);
28
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
27
 
30
28
  const lowerCaseFirstLetter = str => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
31
29
  const toEventHandlerName = eventName => `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
@@ -35,43 +33,20 @@ const treeObjectFactory = (type, props, children) => ({
35
33
  props,
36
34
  children
37
35
  });
38
- const toTreeBranch = obj => obj.map(child => {
39
- return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
40
- ...child.__r3f.memoizedProps
41
- }, toTreeBranch([...(child.children || []), ...child.__r3f.objects]));
36
+ const toTreeBranch = children => children.map(child => {
37
+ return treeObjectFactory(lowerCaseFirstLetter(child.object.type || child.object.constructor.name), child.props, toTreeBranch(child.children));
42
38
  });
43
- const toTree = root => root.children.map(obj => treeObjectFactory(lowerCaseFirstLetter(obj.type), {
44
- ...obj.__r3f.memoizedProps
45
- }, toTreeBranch([...obj.children, ...obj.__r3f.objects])));
39
+ const toTree = root => toTreeBranch(root.children);
46
40
 
47
41
  const graphObjectFactory = (type, name, children) => ({
48
42
  type,
49
43
  name,
50
44
  children
51
45
  });
52
- const toGraph = object => object.children.map(child => graphObjectFactory(child.type, child.name || '', toGraph(child)));
53
-
54
- const is = {
55
- obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
56
- fun: a => typeof a === 'function',
57
- str: a => typeof a === 'string',
58
- num: a => typeof a === 'number',
59
- und: a => a === void 0,
60
- arr: a => Array.isArray(a),
61
- equ(a, b) {
62
- // Wrong type or one of the two undefined, doesn't match
63
- if (typeof a !== typeof b || !!a !== !!b) return false;
64
- // Atomic, just compare a against b
65
- if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
66
- // Array, shallow compare first to see if it's a match
67
- if (is.arr(a) && a == b) return true;
68
- // Last resort, go through keys
69
- let i;
70
- for (i in a) if (!(i in b)) return false;
71
- for (i in b) if (a[i] !== b[i]) return false;
72
- return is.und(i) ? a === b : true;
73
- }
74
- };
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
+ });
75
50
 
76
51
  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'];
77
52
  const enums = {
@@ -711,36 +686,29 @@ class ReactThreeTestInstance {
711
686
  constructor(_fiber) {
712
687
  this.getChildren = (fiber, opts = {
713
688
  exhaustive: false
714
- }) => {
715
- if (opts.exhaustive) {
716
- /**
717
- * this will return objects like
718
- * color or effects etc.
719
- */
720
- return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
721
- } else {
722
- return (fiber.children || []).map(fib => wrapFiber(fib));
723
- }
724
- };
725
- this.find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
689
+ }) => fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
726
690
  this.findAll = decider => findAll(this, decider);
727
- this.findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
728
- this.findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
691
+ this.find = decider => expectOne(this.findAll(decider), `matching custom checker: ${decider.toString()}`);
692
+ this.findByType = type => expectOne(this.findAll(node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
693
+ this.findAllByType = type => this.findAll(node => Boolean(node.type && node.type === type));
729
694
  this.findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
730
- this.findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
695
+ this.findAllByProps = props => this.findAll(node => Boolean(node.props && matchProps(node.props, props)));
731
696
  this._fiber = _fiber;
732
697
  }
733
- get instance() {
698
+ get fiber() {
734
699
  return this._fiber;
735
700
  }
701
+ get instance() {
702
+ return this._fiber.object;
703
+ }
736
704
  get type() {
737
- return this._fiber.type;
705
+ return this._fiber.object.type;
738
706
  }
739
707
  get props() {
740
- return this._fiber.__r3f.memoizedProps;
708
+ return this._fiber.props;
741
709
  }
742
710
  get parent() {
743
- const parent = this._fiber.__r3f.parent;
711
+ const parent = this._fiber.parent;
744
712
  if (parent !== null) {
745
713
  return wrapFiber(parent);
746
714
  }
@@ -765,12 +733,11 @@ const wrapFiber = fiber => {
765
733
  return wrapper;
766
734
  };
767
735
 
768
- const act$1 = React__namespace.unstable_act;
769
736
  async function waitFor(callback, {
770
737
  interval = 50,
771
738
  timeout = 5000
772
739
  } = {}) {
773
- await act$1(async () => {
740
+ await fiber.act(async () => {
774
741
  const start = performance.now();
775
742
  while (true) {
776
743
  const result = callback();
@@ -788,21 +755,30 @@ var index$1 = /*#__PURE__*/Object.freeze({
788
755
 
789
756
  // Extend catalogue for render API in tests.
790
757
  fiber.extend(THREE__namespace);
791
- const act = fiber.act;
792
758
  const create = async (element, options) => {
759
+ var _options$width, _options$height;
793
760
  const canvas = createCanvas(options);
794
761
  const _root = fiber.createRoot(canvas).configure({
795
762
  frameloop: 'never',
763
+ // TODO: remove and use default behavior
764
+ size: {
765
+ width: (_options$width = options == null ? void 0 : options.width) != null ? _options$width : 1280,
766
+ height: (_options$height = options == null ? void 0 : options.height) != null ? _options$height : 800,
767
+ top: 0,
768
+ left: 0
769
+ },
796
770
  ...options,
797
771
  events: undefined
798
772
  });
799
773
  const _store = fiber._roots.get(canvas).store;
800
- await act(async () => _root.render(element));
801
- const scene = _store.getState().scene;
774
+ await fiber.act(async () => _root.render(element));
775
+ const _scene = _store.getState().scene.__r3f;
802
776
  return {
803
- scene: wrapFiber(scene),
777
+ scene: wrapFiber(_scene),
804
778
  async unmount() {
805
- await act(async () => _root.unmount());
779
+ await fiber.act(async () => {
780
+ _root.unmount();
781
+ });
806
782
  },
807
783
  getInstance() {
808
784
  // Bail if canvas is unmounted
@@ -822,40 +798,45 @@ const create = async (element, options) => {
822
798
  },
823
799
  async update(newElement) {
824
800
  if (!fiber._roots.has(canvas)) return console.warn('RTTR: attempted to update an unmounted root!');
825
- await act(async () => _root.render(newElement));
801
+ await fiber.act(async () => {
802
+ _root.render(newElement);
803
+ });
826
804
  },
827
805
  toTree() {
828
- return toTree(scene);
806
+ return toTree(_scene);
829
807
  },
830
808
  toGraph() {
831
- return toGraph(scene);
809
+ return toGraph(_scene);
832
810
  },
833
- fireEvent: createEventFirer(act, _store),
811
+ fireEvent: createEventFirer(fiber.act, _store),
834
812
  async advanceFrames(frames, delta = 1) {
835
813
  const state = _store.getState();
836
814
  const storeSubscribers = state.internal.subscribers;
837
815
  const promises = [];
838
- for (const subscriber of storeSubscribers) {
816
+ storeSubscribers.forEach(subscriber => {
839
817
  for (let i = 0; i < frames; i++) {
840
- if (is.arr(delta)) {
818
+ if (Array.isArray(delta)) {
841
819
  promises.push(new Promise(() => subscriber.ref.current(state, delta[i] || delta[-1])));
842
820
  } else {
843
821
  promises.push(new Promise(() => subscriber.ref.current(state, delta)));
844
822
  }
845
823
  }
846
- }
824
+ });
847
825
  Promise.all(promises);
848
826
  }
849
827
  };
850
828
  };
851
829
  var index = {
852
830
  create,
853
- act,
831
+ act: fiber.act,
854
832
  waitFor
855
833
  };
856
834
 
835
+ Object.defineProperty(exports, 'act', {
836
+ enumerable: true,
837
+ get: function () { return fiber.act; }
838
+ });
857
839
  exports.ReactThreeTest = index$1;
858
- exports.act = act;
859
840
  exports.create = create;
860
841
  exports["default"] = index;
861
842
  exports.waitFor = waitFor;
@@ -1,6 +1,6 @@
1
1
  import * as THREE from 'three';
2
- import { extend, act as act$2, createRoot, _roots, reconciler } from '@react-three/fiber';
3
- import * as React from 'react';
2
+ import { act, extend, createRoot, _roots, reconciler } from '@react-three/fiber';
3
+ export { act } from '@react-three/fiber';
4
4
 
5
5
  const lowerCaseFirstLetter = str => `${str.charAt(0).toLowerCase()}${str.slice(1)}`;
6
6
  const toEventHandlerName = eventName => `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;
@@ -10,43 +10,20 @@ const treeObjectFactory = (type, props, children) => ({
10
10
  props,
11
11
  children
12
12
  });
13
- const toTreeBranch = obj => obj.map(child => {
14
- return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
15
- ...child.__r3f.memoizedProps
16
- }, toTreeBranch([...(child.children || []), ...child.__r3f.objects]));
13
+ const toTreeBranch = children => children.map(child => {
14
+ return treeObjectFactory(lowerCaseFirstLetter(child.object.type || child.object.constructor.name), child.props, toTreeBranch(child.children));
17
15
  });
18
- const toTree = root => root.children.map(obj => treeObjectFactory(lowerCaseFirstLetter(obj.type), {
19
- ...obj.__r3f.memoizedProps
20
- }, toTreeBranch([...obj.children, ...obj.__r3f.objects])));
16
+ const toTree = root => toTreeBranch(root.children);
21
17
 
22
18
  const graphObjectFactory = (type, name, children) => ({
23
19
  type,
24
20
  name,
25
21
  children
26
22
  });
27
- const toGraph = object => object.children.map(child => graphObjectFactory(child.type, child.name || '', toGraph(child)));
28
-
29
- const is = {
30
- obj: a => a === Object(a) && !is.arr(a) && typeof a !== 'function',
31
- fun: a => typeof a === 'function',
32
- str: a => typeof a === 'string',
33
- num: a => typeof a === 'number',
34
- und: a => a === void 0,
35
- arr: a => Array.isArray(a),
36
- equ(a, b) {
37
- // Wrong type or one of the two undefined, doesn't match
38
- if (typeof a !== typeof b || !!a !== !!b) return false;
39
- // Atomic, just compare a against b
40
- if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
41
- // Array, shallow compare first to see if it's a match
42
- if (is.arr(a) && a == b) return true;
43
- // Last resort, go through keys
44
- let i;
45
- for (i in a) if (!(i in b)) return false;
46
- for (i in b) if (a[i] !== b[i]) return false;
47
- return is.und(i) ? a === b : true;
48
- }
49
- };
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
+ });
50
27
 
51
28
  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
29
  const enums = {
@@ -686,36 +663,29 @@ class ReactThreeTestInstance {
686
663
  constructor(_fiber) {
687
664
  this.getChildren = (fiber, opts = {
688
665
  exhaustive: false
689
- }) => {
690
- if (opts.exhaustive) {
691
- /**
692
- * this will return objects like
693
- * color or effects etc.
694
- */
695
- return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
696
- } else {
697
- return (fiber.children || []).map(fib => wrapFiber(fib));
698
- }
699
- };
700
- this.find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
666
+ }) => fiber.children.filter(child => !child.props.attach || opts.exhaustive).map(fib => wrapFiber(fib));
701
667
  this.findAll = decider => findAll(this, decider);
702
- this.findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
703
- this.findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
668
+ this.find = decider => expectOne(this.findAll(decider), `matching custom checker: ${decider.toString()}`);
669
+ this.findByType = type => expectOne(this.findAll(node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
670
+ this.findAllByType = type => this.findAll(node => Boolean(node.type && node.type === type));
704
671
  this.findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
705
- this.findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
672
+ this.findAllByProps = props => this.findAll(node => Boolean(node.props && matchProps(node.props, props)));
706
673
  this._fiber = _fiber;
707
674
  }
708
- get instance() {
675
+ get fiber() {
709
676
  return this._fiber;
710
677
  }
678
+ get instance() {
679
+ return this._fiber.object;
680
+ }
711
681
  get type() {
712
- return this._fiber.type;
682
+ return this._fiber.object.type;
713
683
  }
714
684
  get props() {
715
- return this._fiber.__r3f.memoizedProps;
685
+ return this._fiber.props;
716
686
  }
717
687
  get parent() {
718
- const parent = this._fiber.__r3f.parent;
688
+ const parent = this._fiber.parent;
719
689
  if (parent !== null) {
720
690
  return wrapFiber(parent);
721
691
  }
@@ -740,12 +710,11 @@ const wrapFiber = fiber => {
740
710
  return wrapper;
741
711
  };
742
712
 
743
- const act$1 = React.unstable_act;
744
713
  async function waitFor(callback, {
745
714
  interval = 50,
746
715
  timeout = 5000
747
716
  } = {}) {
748
- await act$1(async () => {
717
+ await act(async () => {
749
718
  const start = performance.now();
750
719
  while (true) {
751
720
  const result = callback();
@@ -763,21 +732,30 @@ var index$1 = /*#__PURE__*/Object.freeze({
763
732
 
764
733
  // Extend catalogue for render API in tests.
765
734
  extend(THREE);
766
- const act = act$2;
767
735
  const create = async (element, options) => {
736
+ var _options$width, _options$height;
768
737
  const canvas = createCanvas(options);
769
738
  const _root = createRoot(canvas).configure({
770
739
  frameloop: 'never',
740
+ // TODO: remove and use default behavior
741
+ size: {
742
+ width: (_options$width = options == null ? void 0 : options.width) != null ? _options$width : 1280,
743
+ height: (_options$height = options == null ? void 0 : options.height) != null ? _options$height : 800,
744
+ top: 0,
745
+ left: 0
746
+ },
771
747
  ...options,
772
748
  events: undefined
773
749
  });
774
750
  const _store = _roots.get(canvas).store;
775
751
  await act(async () => _root.render(element));
776
- const scene = _store.getState().scene;
752
+ const _scene = _store.getState().scene.__r3f;
777
753
  return {
778
- scene: wrapFiber(scene),
754
+ scene: wrapFiber(_scene),
779
755
  async unmount() {
780
- await act(async () => _root.unmount());
756
+ await act(async () => {
757
+ _root.unmount();
758
+ });
781
759
  },
782
760
  getInstance() {
783
761
  // Bail if canvas is unmounted
@@ -797,28 +775,30 @@ const create = async (element, options) => {
797
775
  },
798
776
  async update(newElement) {
799
777
  if (!_roots.has(canvas)) return console.warn('RTTR: attempted to update an unmounted root!');
800
- await act(async () => _root.render(newElement));
778
+ await act(async () => {
779
+ _root.render(newElement);
780
+ });
801
781
  },
802
782
  toTree() {
803
- return toTree(scene);
783
+ return toTree(_scene);
804
784
  },
805
785
  toGraph() {
806
- return toGraph(scene);
786
+ return toGraph(_scene);
807
787
  },
808
788
  fireEvent: createEventFirer(act, _store),
809
789
  async advanceFrames(frames, delta = 1) {
810
790
  const state = _store.getState();
811
791
  const storeSubscribers = state.internal.subscribers;
812
792
  const promises = [];
813
- for (const subscriber of storeSubscribers) {
793
+ storeSubscribers.forEach(subscriber => {
814
794
  for (let i = 0; i < frames; i++) {
815
- if (is.arr(delta)) {
795
+ if (Array.isArray(delta)) {
816
796
  promises.push(new Promise(() => subscriber.ref.current(state, delta[i] || delta[-1])));
817
797
  } else {
818
798
  promises.push(new Promise(() => subscriber.ref.current(state, delta)));
819
799
  }
820
800
  }
821
- }
801
+ });
822
802
  Promise.all(promises);
823
803
  }
824
804
  };
@@ -829,4 +809,4 @@ var index = {
829
809
  waitFor
830
810
  };
831
811
 
832
- export { index$1 as ReactThreeTest, act, create, index as default, waitFor };
812
+ export { index$1 as ReactThreeTest, create, index as default, waitFor };
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@react-three/test-renderer",
3
- "version": "8.2.0",
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": ">=17.0",
26
- "@react-three/fiber": ">=8.0.0",
27
- "three": ">=0.126"
28
- }
29
- }
1
+ {
2
+ "name": "@react-three/test-renderer",
3
+ "version": "9.0.0-alpha.3",
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",
26
+ "@react-three/fiber": "9.0.0-alpha.3",
27
+ "three": ">=0.141"
28
+ }
29
+ }
@@ -1,16 +0,0 @@
1
- export declare class WebGL2RenderingContext {
2
- [key: string]: any;
3
- constructor(canvas: HTMLCanvasElement);
4
- getShaderPrecisionFormat: () => {
5
- rangeMin: number;
6
- rangeMax: number;
7
- precision: number;
8
- };
9
- private GL_VERSION;
10
- private SCISSOR_BOX;
11
- private VIEWPORT;
12
- getParameter(paramId: number): string[] | number[] | undefined;
13
- getExtension(ext: string): any;
14
- getProgramInfoLog: () => string;
15
- getShaderInfoLog: () => string;
16
- }
@@ -1,2 +0,0 @@
1
- import type { CreateCanvasParameters } from './types/internal';
2
- export declare const createCanvas: ({ beforeReturn, width, height }?: CreateCanvasParameters) => HTMLCanvasElement;
@@ -1,4 +0,0 @@
1
- import ReactReconciler from 'react-reconciler';
2
- import { ReactThreeTestInstance } from './createTestInstance';
3
- import type { MockUseStoreState, MockEventData } from './types/internal';
4
- export declare const createEventFirer: (act: ReactReconciler.Reconciler<unknown, unknown, unknown, unknown, unknown>['act'], store: MockUseStoreState) => (element: ReactThreeTestInstance, eventName: string, data?: MockEventData) => Promise<any>;
@@ -1,3 +0,0 @@
1
- import type { MockScene, MockSceneChild } from '../types/internal';
2
- import type { SceneGraphItem } from '../types/public';
3
- export declare const toGraph: (object: MockScene | MockSceneChild) => SceneGraphItem[];
@@ -1,9 +0,0 @@
1
- export declare const is: {
2
- obj: (a: any) => boolean;
3
- fun: (a: any) => boolean;
4
- str: (a: any) => boolean;
5
- num: (a: any) => boolean;
6
- und: (a: any) => boolean;
7
- arr: (a: any) => boolean;
8
- equ(a: any, b: any): boolean;
9
- };
@@ -1,2 +0,0 @@
1
- export declare const lowerCaseFirstLetter: (str: string) => string;
2
- export declare const toEventHandlerName: (eventName: string) => string;
@@ -1,5 +0,0 @@
1
- import { ReactThreeTestInstance } from '../createTestInstance';
2
- import type { Obj } from '../types/internal';
3
- export declare const expectOne: <TItem>(items: TItem[], msg: string) => TItem;
4
- export declare const matchProps: (props: Obj, filter: Obj) => boolean;
5
- export declare const findAll: (root: ReactThreeTestInstance, decider: (node: ReactThreeTestInstance) => boolean) => ReactThreeTestInstance<import("three").Object3D<import("three").Event>>[];
@@ -1,3 +0,0 @@
1
- import type { Tree } from '../types/public';
2
- import type { MockScene } from '../types/internal';
3
- export declare const toTree: (root: MockScene) => Tree;