@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.
- package/CHANGELOG.md +440 -434
- package/README.md +61 -61
- package/dist/declarations/src/createTestInstance.d.ts +10 -8
- package/dist/declarations/src/index.d.ts +6 -6
- package/dist/declarations/src/types/index.d.ts +1 -1
- package/dist/declarations/src/types/internal.d.ts +8 -19
- package/dist/declarations/src/types/public.d.ts +8 -8
- package/dist/react-three-test-renderer.cjs.d.ts +1 -0
- package/dist/react-three-test-renderer.cjs.dev.js +48 -67
- package/dist/react-three-test-renderer.cjs.prod.js +48 -67
- package/dist/react-three-test-renderer.esm.js +44 -64
- package/package.json +29 -29
- package/dist/declarations/src/WebGL2RenderingContext.d.ts +0 -16
- package/dist/declarations/src/createTestCanvas.d.ts +0 -2
- package/dist/declarations/src/fireEvent.d.ts +0 -4
- package/dist/declarations/src/helpers/graph.d.ts +0 -3
- package/dist/declarations/src/helpers/is.d.ts +0 -9
- package/dist/declarations/src/helpers/strings.d.ts +0 -2
- package/dist/declarations/src/helpers/testInstance.d.ts +0 -5
- package/dist/declarations/src/helpers/tree.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
# React Three Test Renderer ⚛️🔼🧪
|
|
2
|
-
|
|
3
|
-
[](https://npmjs.com/package/@react-three/test-renderer)
|
|
4
|
-
[](https://npmjs.com/package/@react-three/test-renderer)
|
|
5
|
-
[](https://twitter.com/pmndrs)
|
|
6
|
-
[](https://twitter.com/_josh_ellis_)
|
|
7
|
-
[](https://discord.gg/ZZjjNvJ)
|
|
8
|
-
|
|
9
|
-
`@react-three/test-renderer` is a React testing <a href="https://reactjs.org/docs/codebase-overview.html#renderers">renderer</a> for threejs in node.
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
yarn add @react-three/fiber three
|
|
13
|
-
yarn add -D @react-three/test-renderer
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## The problem
|
|
19
|
-
|
|
20
|
-
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.
|
|
21
|
-
|
|
22
|
-
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.
|
|
23
|
-
|
|
24
|
-
## The solution
|
|
25
|
-
|
|
26
|
-
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.
|
|
27
|
-
|
|
28
|
-
Essentially, this package makes it easy to grab a snapshot of the Scene Graph rendered by `three` without the need for webgl & browser.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## Usage
|
|
33
|
-
|
|
34
|
-
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.
|
|
35
|
-
|
|
36
|
-
```tsx
|
|
37
|
-
import ReactThreeTestRenderer from '@react-three/test-renderer'
|
|
38
|
-
|
|
39
|
-
const renderer = await ReactThreeTestRenderer.create(
|
|
40
|
-
<mesh>
|
|
41
|
-
<boxGeometry args={[2, 2]} />
|
|
42
|
-
<meshStandardMaterial
|
|
43
|
-
args={[
|
|
44
|
-
{
|
|
45
|
-
color: 0x0000ff,
|
|
46
|
-
},
|
|
47
|
-
]}
|
|
48
|
-
/>
|
|
49
|
-
</mesh>,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
// assertions using the TestInstance & Scene Graph
|
|
53
|
-
console.log(renderer.toGraph())
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
## API
|
|
59
|
-
|
|
60
|
-
- [React Three Test Renderer API](/packages/test-renderer/markdown/rttr.md)
|
|
61
|
-
- [React Three Test Instance API](/packages/test-renderer/markdown/rttr-instance.md)
|
|
1
|
+
# React Three Test Renderer ⚛️🔼🧪
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@react-three/test-renderer)
|
|
4
|
+
[](https://npmjs.com/package/@react-three/test-renderer)
|
|
5
|
+
[](https://twitter.com/pmndrs)
|
|
6
|
+
[](https://twitter.com/_josh_ellis_)
|
|
7
|
+
[](https://discord.gg/ZZjjNvJ)
|
|
8
|
+
|
|
9
|
+
`@react-three/test-renderer` is a React testing <a href="https://reactjs.org/docs/codebase-overview.html#renderers">renderer</a> for threejs in node.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add @react-three/fiber three
|
|
13
|
+
yarn add -D @react-three/test-renderer
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## The problem
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
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.
|
|
23
|
+
|
|
24
|
+
## The solution
|
|
25
|
+
|
|
26
|
+
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.
|
|
27
|
+
|
|
28
|
+
Essentially, this package makes it easy to grab a snapshot of the Scene Graph rendered by `three` without the need for webgl & browser.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
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.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import ReactThreeTestRenderer from '@react-three/test-renderer'
|
|
38
|
+
|
|
39
|
+
const renderer = await ReactThreeTestRenderer.create(
|
|
40
|
+
<mesh>
|
|
41
|
+
<boxGeometry args={[2, 2]} />
|
|
42
|
+
<meshStandardMaterial
|
|
43
|
+
args={[
|
|
44
|
+
{
|
|
45
|
+
color: 0x0000ff,
|
|
46
|
+
},
|
|
47
|
+
]}
|
|
48
|
+
/>
|
|
49
|
+
</mesh>,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// assertions using the TestInstance & Scene Graph
|
|
53
|
+
console.log(renderer.toGraph())
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## API
|
|
59
|
+
|
|
60
|
+
- [React Three Test Renderer API](/packages/test-renderer/markdown/rttr.md)
|
|
61
|
+
- [React Three Test Instance API](/packages/test-renderer/markdown/rttr-instance.md)
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type * as THREE from 'three';
|
|
2
|
+
import type { Instance } from '@react-three/fiber';
|
|
3
|
+
import type { Obj } from "./types/internal.js";
|
|
4
|
+
export declare class ReactThreeTestInstance<TObject extends THREE.Object3D = THREE.Object3D> {
|
|
5
|
+
_fiber: Instance<TObject>;
|
|
6
|
+
constructor(fiber: Instance<TObject>);
|
|
7
|
+
get fiber(): Instance<TObject>;
|
|
8
|
+
get instance(): TObject;
|
|
7
9
|
get type(): string;
|
|
8
10
|
get props(): Obj;
|
|
9
11
|
get parent(): ReactThreeTestInstance | null;
|
|
10
12
|
get children(): ReactThreeTestInstance[];
|
|
11
13
|
get allChildren(): ReactThreeTestInstance[];
|
|
12
14
|
private getChildren;
|
|
13
|
-
find: (decider: (node: ReactThreeTestInstance) => boolean) => ReactThreeTestInstance;
|
|
14
15
|
findAll: (decider: (node: ReactThreeTestInstance) => boolean) => ReactThreeTestInstance[];
|
|
16
|
+
find: (decider: (node: ReactThreeTestInstance) => boolean) => ReactThreeTestInstance;
|
|
15
17
|
findByType: (type: string) => ReactThreeTestInstance;
|
|
16
18
|
findAllByType: (type: string) => ReactThreeTestInstance[];
|
|
17
19
|
findByProps: (props: Obj) => ReactThreeTestInstance;
|
|
18
20
|
findAllByProps: (props: Obj) => ReactThreeTestInstance[];
|
|
19
21
|
}
|
|
20
|
-
export declare const wrapFiber: (fiber:
|
|
22
|
+
export declare const wrapFiber: (fiber: Instance) => ReactThreeTestInstance;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
declare const create: (element: React.ReactNode, options?: Partial<CreateOptions>
|
|
2
|
+
import { act } from '@react-three/fiber';
|
|
3
|
+
import type { CreateOptions, Renderer } from "./types/public.js";
|
|
4
|
+
import { waitFor, WaitOptions } from "./helpers/waitFor.js";
|
|
5
|
+
declare const create: (element: React.ReactNode, options?: Partial<CreateOptions>) => Promise<Renderer>;
|
|
6
6
|
export { create, act, waitFor };
|
|
7
7
|
export type { WaitOptions };
|
|
8
|
-
export * as ReactThreeTest from
|
|
8
|
+
export * as ReactThreeTest from "./types/index.js";
|
|
9
9
|
declare const _default: {
|
|
10
10
|
create: (element: React.ReactNode, options?: Partial<CreateOptions> | undefined) => Promise<Renderer>;
|
|
11
|
-
act: Act;
|
|
11
|
+
act: import("@react-three/fiber").Act;
|
|
12
12
|
waitFor: typeof waitFor;
|
|
13
13
|
};
|
|
14
14
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./public.js";
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { UseBoundStore } from 'zustand';
|
|
3
|
-
import type { BaseInstance, LocalState, RootState } from '@react-three/fiber';
|
|
4
|
-
export declare type MockUseStoreState = UseBoundStore<RootState>;
|
|
5
|
-
export interface MockInstance extends Omit<BaseInstance, '__r3f'> {
|
|
6
|
-
__r3f: Omit<LocalState, 'root' | 'objects' | 'parent'> & {
|
|
7
|
-
root: MockUseStoreState;
|
|
8
|
-
objects: MockSceneChild[];
|
|
9
|
-
parent: MockInstance;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export interface MockSceneChild extends Omit<MockInstance, 'children'> {
|
|
13
|
-
children: MockSceneChild[];
|
|
14
|
-
}
|
|
15
|
-
export interface MockScene extends Omit<THREE.Scene, 'children'>, Pick<MockInstance, '__r3f'> {
|
|
16
|
-
children: MockSceneChild[];
|
|
17
|
-
}
|
|
18
|
-
export declare type CreateCanvasParameters = {
|
|
1
|
+
export type CreateCanvasParameters = {
|
|
19
2
|
beforeReturn?: (canvas: HTMLCanvasElement) => void;
|
|
20
3
|
width?: number;
|
|
21
4
|
height?: number;
|
|
@@ -23,7 +6,13 @@ export declare type CreateCanvasParameters = {
|
|
|
23
6
|
export interface Obj {
|
|
24
7
|
[key: string]: any;
|
|
25
8
|
}
|
|
26
|
-
|
|
9
|
+
/**
|
|
10
|
+
* this is an empty object of any,
|
|
11
|
+
* the data is passed to a new event
|
|
12
|
+
* and subsequently passed to the
|
|
13
|
+
* event handler you're calling
|
|
14
|
+
*/
|
|
15
|
+
export type MockEventData = {
|
|
27
16
|
[key: string]: any;
|
|
28
17
|
};
|
|
29
18
|
export interface TestInstanceChildOpts {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Camera, RenderProps } from '@react-three/fiber';
|
|
2
|
-
import { ReactThreeTestInstance } from
|
|
3
|
-
import type { MockEventData, CreateCanvasParameters } from
|
|
2
|
+
import { ReactThreeTestInstance } from "../createTestInstance.js";
|
|
3
|
+
import type { MockEventData, CreateCanvasParameters } from "./internal.js";
|
|
4
4
|
export { ReactThreeTestInstance };
|
|
5
|
-
export
|
|
5
|
+
export type MockSyntheticEvent = {
|
|
6
6
|
camera: Camera;
|
|
7
7
|
stopPropagation: () => void;
|
|
8
8
|
target: ReactThreeTestInstance;
|
|
@@ -10,9 +10,8 @@ export declare type MockSyntheticEvent = {
|
|
|
10
10
|
sourceEvent: MockEventData;
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export declare type Renderer = {
|
|
13
|
+
export type CreateOptions = CreateCanvasParameters & RenderProps<HTMLCanvasElement>;
|
|
14
|
+
export type Renderer = {
|
|
16
15
|
scene: ReactThreeTestInstance;
|
|
17
16
|
unmount: () => Promise<void>;
|
|
18
17
|
getInstance: () => null | unknown;
|
|
@@ -27,7 +26,7 @@ export interface SceneGraphItem {
|
|
|
27
26
|
name: string;
|
|
28
27
|
children: SceneGraphItem[] | null;
|
|
29
28
|
}
|
|
30
|
-
export
|
|
29
|
+
export type SceneGraph = SceneGraphItem[];
|
|
31
30
|
export interface TreeNode {
|
|
32
31
|
type: string;
|
|
33
32
|
props: {
|
|
@@ -35,4 +34,5 @@ export interface TreeNode {
|
|
|
35
34
|
};
|
|
36
35
|
children: TreeNode[];
|
|
37
36
|
}
|
|
38
|
-
export
|
|
37
|
+
export type Tree = TreeNode[];
|
|
38
|
+
export type { Act } from '@react-three/fiber';
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export * from "./declarations/src/index";
|
|
2
2
|
export { default } from "./declarations/src/index";
|
|
3
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhY3QtdGhyZWUtdGVzdC1yZW5kZXJlci5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
|
|
@@ -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 =
|
|
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
|
|
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 =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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.
|
|
728
|
-
this.
|
|
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(
|
|
695
|
+
this.findAllByProps = props => this.findAll(node => Boolean(node.props && matchProps(node.props, props)));
|
|
731
696
|
this._fiber = _fiber;
|
|
732
697
|
}
|
|
733
|
-
get
|
|
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.
|
|
708
|
+
return this._fiber.props;
|
|
741
709
|
}
|
|
742
710
|
get parent() {
|
|
743
|
-
const parent = this._fiber.
|
|
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
|
|
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
|
|
774
|
+
await fiber.act(async () => _root.render(element));
|
|
775
|
+
const _scene = _store.getState().scene.__r3f;
|
|
802
776
|
return {
|
|
803
|
-
scene: wrapFiber(
|
|
777
|
+
scene: wrapFiber(_scene),
|
|
804
778
|
async unmount() {
|
|
805
|
-
await act(async () =>
|
|
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 () =>
|
|
801
|
+
await fiber.act(async () => {
|
|
802
|
+
_root.render(newElement);
|
|
803
|
+
});
|
|
826
804
|
},
|
|
827
805
|
toTree() {
|
|
828
|
-
return toTree(
|
|
806
|
+
return toTree(_scene);
|
|
829
807
|
},
|
|
830
808
|
toGraph() {
|
|
831
|
-
return toGraph(
|
|
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
|
-
|
|
816
|
+
storeSubscribers.forEach(subscriber => {
|
|
839
817
|
for (let i = 0; i < frames; i++) {
|
|
840
|
-
if (
|
|
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;
|