@react-three/test-renderer 8.0.17 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -33,13 +33,13 @@ const treeObjectFactory = (type, props, children) => ({
|
|
|
33
33
|
props,
|
|
34
34
|
children
|
|
35
35
|
});
|
|
36
|
-
|
|
37
36
|
const toTreeBranch = obj => obj.map(child => {
|
|
38
|
-
return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
|
|
37
|
+
return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
|
|
38
|
+
...child.__r3f.memoizedProps
|
|
39
39
|
}, toTreeBranch([...(child.children || []), ...child.__r3f.objects]));
|
|
40
40
|
});
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const toTree = root => root.children.map(obj => treeObjectFactory(lowerCaseFirstLetter(obj.type), {
|
|
42
|
+
...obj.__r3f.memoizedProps
|
|
43
43
|
}, toTreeBranch([...obj.children, ...obj.__r3f.objects])));
|
|
44
44
|
|
|
45
45
|
const graphObjectFactory = (type, name, children) => ({
|
|
@@ -47,7 +47,6 @@ const graphObjectFactory = (type, name, children) => ({
|
|
|
47
47
|
name,
|
|
48
48
|
children
|
|
49
49
|
});
|
|
50
|
-
|
|
51
50
|
const toGraph = object => object.children.map(child => graphObjectFactory(child.type, child.name || '', toGraph(child)));
|
|
52
51
|
|
|
53
52
|
const is = {
|
|
@@ -57,24 +56,19 @@ const is = {
|
|
|
57
56
|
num: a => typeof a === 'number',
|
|
58
57
|
und: a => a === void 0,
|
|
59
58
|
arr: a => Array.isArray(a),
|
|
60
|
-
|
|
61
59
|
equ(a, b) {
|
|
62
60
|
// Wrong type or one of the two undefined, doesn't match
|
|
63
|
-
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
64
|
-
|
|
65
|
-
if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
|
|
66
|
-
|
|
67
|
-
if (is.arr(a) && a == b) return true;
|
|
68
|
-
|
|
61
|
+
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
62
|
+
// Atomic, just compare a against b
|
|
63
|
+
if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
|
|
64
|
+
// Array, shallow compare first to see if it's a match
|
|
65
|
+
if (is.arr(a) && a == b) return true;
|
|
66
|
+
// Last resort, go through keys
|
|
69
67
|
let i;
|
|
70
|
-
|
|
71
68
|
for (i in a) if (!(i in b)) return false;
|
|
72
|
-
|
|
73
69
|
for (i in b) if (a[i] !== b[i]) return false;
|
|
74
|
-
|
|
75
70
|
return is.und(i) ? a === b : true;
|
|
76
71
|
}
|
|
77
|
-
|
|
78
72
|
};
|
|
79
73
|
|
|
80
74
|
const createCanvas = ({
|
|
@@ -85,15 +79,11 @@ const createCanvas = ({
|
|
|
85
79
|
const canvas = document.createElement('canvas');
|
|
86
80
|
canvas.height = height;
|
|
87
81
|
canvas.width = width;
|
|
88
|
-
|
|
89
82
|
canvas.addEventListener = () => {};
|
|
90
|
-
|
|
91
83
|
canvas.removeEventListener = () => {};
|
|
92
|
-
|
|
93
84
|
if (beforeReturn) {
|
|
94
85
|
beforeReturn(canvas);
|
|
95
86
|
}
|
|
96
|
-
|
|
97
87
|
return canvas;
|
|
98
88
|
};
|
|
99
89
|
|
|
@@ -434,40 +424,8 @@ const extensions = {
|
|
|
434
424
|
EXT_sRGB: null,
|
|
435
425
|
WEBGL_compressed_texture_etc1: null
|
|
436
426
|
};
|
|
437
|
-
|
|
438
427
|
class WebGLRenderingContext {
|
|
439
428
|
constructor(canvas) {
|
|
440
|
-
this.getShaderPrecisionFormat = () => {
|
|
441
|
-
return {
|
|
442
|
-
rangeMin: 127,
|
|
443
|
-
rangeMax: 127,
|
|
444
|
-
precision: 23
|
|
445
|
-
};
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
this.GL_VERSION = 7938;
|
|
449
|
-
this.SCISSOR_BOX = 3088;
|
|
450
|
-
this.VIEWPORT = 2978;
|
|
451
|
-
|
|
452
|
-
this.getParameter = paramId => {
|
|
453
|
-
switch (paramId) {
|
|
454
|
-
case this.GL_VERSION:
|
|
455
|
-
return ['WebGL1'];
|
|
456
|
-
|
|
457
|
-
case this.SCISSOR_BOX:
|
|
458
|
-
case this.VIEWPORT:
|
|
459
|
-
return [0, 0, 1, 1];
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
this.getExtension = ext => {
|
|
464
|
-
return extensions[ext];
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
this.getProgramInfoLog = () => '';
|
|
468
|
-
|
|
469
|
-
this.getShaderInfoLog = () => '';
|
|
470
|
-
|
|
471
429
|
this.canvas = canvas;
|
|
472
430
|
this.drawingBufferWidth = canvas.width;
|
|
473
431
|
this.drawingBufferHeight = canvas.height;
|
|
@@ -478,28 +436,46 @@ class WebGLRenderingContext {
|
|
|
478
436
|
});
|
|
479
437
|
Object.assign(this, enums);
|
|
480
438
|
}
|
|
481
|
-
|
|
439
|
+
getShaderPrecisionFormat = () => {
|
|
440
|
+
return {
|
|
441
|
+
rangeMin: 127,
|
|
442
|
+
rangeMax: 127,
|
|
443
|
+
precision: 23
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
GL_VERSION = 7938;
|
|
447
|
+
SCISSOR_BOX = 3088;
|
|
448
|
+
VIEWPORT = 2978;
|
|
449
|
+
getParameter = paramId => {
|
|
450
|
+
switch (paramId) {
|
|
451
|
+
case this.GL_VERSION:
|
|
452
|
+
return ['WebGL1'];
|
|
453
|
+
case this.SCISSOR_BOX:
|
|
454
|
+
case this.VIEWPORT:
|
|
455
|
+
return [0, 0, 1, 1];
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
getExtension = ext => {
|
|
459
|
+
return extensions[ext];
|
|
460
|
+
};
|
|
461
|
+
getProgramInfoLog = () => '';
|
|
462
|
+
getShaderInfoLog = () => '';
|
|
482
463
|
}
|
|
483
|
-
|
|
484
464
|
const createWebGLContext = canvas => new WebGLRenderingContext(canvas);
|
|
485
465
|
|
|
486
466
|
const createEventFirer = (act, store) => {
|
|
487
467
|
const findEventHandler = (element, eventName) => {
|
|
488
468
|
const eventHandlerName = toEventHandlerName(eventName);
|
|
489
469
|
const props = element.props;
|
|
490
|
-
|
|
491
470
|
if (typeof props[eventHandlerName] === 'function') {
|
|
492
471
|
return props[eventHandlerName];
|
|
493
472
|
}
|
|
494
|
-
|
|
495
473
|
if (typeof props[eventName] === 'function') {
|
|
496
474
|
return props[eventName];
|
|
497
475
|
}
|
|
498
|
-
|
|
499
476
|
console.warn(`Handler for ${eventName} was not found. You must pass event names in camelCase or name of the handler https://github.com/pmndrs/react-three-fiber/blob/master/packages/test-renderer/markdown/rttr.md#create-fireevent`);
|
|
500
477
|
return null;
|
|
501
478
|
};
|
|
502
|
-
|
|
503
479
|
const createSyntheticEvent = (element, data) => {
|
|
504
480
|
const raycastEvent = {
|
|
505
481
|
camera: store.getState().camera,
|
|
@@ -511,23 +487,18 @@ const createEventFirer = (act, store) => {
|
|
|
511
487
|
};
|
|
512
488
|
return raycastEvent;
|
|
513
489
|
};
|
|
514
|
-
|
|
515
490
|
const invokeEvent = async (element, eventName, data) => {
|
|
516
491
|
const handler = findEventHandler(element, eventName);
|
|
517
|
-
|
|
518
492
|
if (!handler) {
|
|
519
493
|
return;
|
|
520
494
|
}
|
|
521
|
-
|
|
522
495
|
let returnValue;
|
|
523
496
|
await act(async () => {
|
|
524
497
|
returnValue = handler(createSyntheticEvent(element, data));
|
|
525
498
|
});
|
|
526
499
|
return returnValue;
|
|
527
500
|
};
|
|
528
|
-
|
|
529
501
|
const fireEvent = async (element, eventName, data = {}) => await invokeEvent(element, eventName, data);
|
|
530
|
-
|
|
531
502
|
return fireEvent;
|
|
532
503
|
};
|
|
533
504
|
|
|
@@ -535,7 +506,6 @@ const expectOne = (items, msg) => {
|
|
|
535
506
|
if (items.length === 1) {
|
|
536
507
|
return items[0];
|
|
537
508
|
}
|
|
538
|
-
|
|
539
509
|
const prefix = items.length === 0 ? 'RTTR: No instances found' : `RTTR: Expected 1 but found ${items.length} instances`;
|
|
540
510
|
throw new Error(`${prefix} ${msg}`);
|
|
541
511
|
};
|
|
@@ -544,22 +514,20 @@ const matchProps = (props, filter) => {
|
|
|
544
514
|
// Check for matches if filter contains regex matchers
|
|
545
515
|
const isRegex = filter[key] instanceof RegExp;
|
|
546
516
|
const shouldMatch = isRegex && typeof props[key] === 'string';
|
|
547
|
-
const match = shouldMatch && filter[key].test(props[key]);
|
|
517
|
+
const match = shouldMatch && filter[key].test(props[key]);
|
|
548
518
|
|
|
519
|
+
// Bail if props aren't identical and filters found no match
|
|
549
520
|
if (props[key] !== filter[key] && !match) {
|
|
550
521
|
return false;
|
|
551
522
|
}
|
|
552
523
|
}
|
|
553
|
-
|
|
554
524
|
return true;
|
|
555
525
|
};
|
|
556
526
|
const findAll = (root, decider) => {
|
|
557
527
|
const results = [];
|
|
558
|
-
|
|
559
528
|
if (decider(root)) {
|
|
560
529
|
results.push(root);
|
|
561
530
|
}
|
|
562
|
-
|
|
563
531
|
root.allChildren.forEach(child => {
|
|
564
532
|
results.push(...findAll(child, decider));
|
|
565
533
|
});
|
|
@@ -567,78 +535,60 @@ const findAll = (root, decider) => {
|
|
|
567
535
|
};
|
|
568
536
|
|
|
569
537
|
class ReactThreeTestInstance {
|
|
570
|
-
constructor(
|
|
571
|
-
this.
|
|
572
|
-
exhaustive: false
|
|
573
|
-
}) => {
|
|
574
|
-
if (opts.exhaustive) {
|
|
575
|
-
/**
|
|
576
|
-
* this will return objects like
|
|
577
|
-
* color or effects etc.
|
|
578
|
-
*/
|
|
579
|
-
return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
|
|
580
|
-
} else {
|
|
581
|
-
return (fiber.children || []).map(fib => wrapFiber(fib));
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
this.find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
|
|
586
|
-
|
|
587
|
-
this.findAll = decider => findAll(this, decider);
|
|
588
|
-
|
|
589
|
-
this.findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
|
|
590
|
-
|
|
591
|
-
this.findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
|
|
592
|
-
|
|
593
|
-
this.findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
|
|
594
|
-
|
|
595
|
-
this.findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
|
|
596
|
-
|
|
597
|
-
this._fiber = _fiber;
|
|
538
|
+
constructor(fiber) {
|
|
539
|
+
this._fiber = fiber;
|
|
598
540
|
}
|
|
599
|
-
|
|
600
541
|
get instance() {
|
|
601
542
|
return this._fiber;
|
|
602
543
|
}
|
|
603
|
-
|
|
604
544
|
get type() {
|
|
605
545
|
return this._fiber.type;
|
|
606
546
|
}
|
|
607
|
-
|
|
608
547
|
get props() {
|
|
609
548
|
return this._fiber.__r3f.memoizedProps;
|
|
610
549
|
}
|
|
611
|
-
|
|
612
550
|
get parent() {
|
|
613
551
|
const parent = this._fiber.__r3f.parent;
|
|
614
|
-
|
|
615
552
|
if (parent !== null) {
|
|
616
553
|
return wrapFiber(parent);
|
|
617
554
|
}
|
|
618
|
-
|
|
619
555
|
return parent;
|
|
620
556
|
}
|
|
621
|
-
|
|
622
557
|
get children() {
|
|
623
558
|
return this.getChildren(this._fiber);
|
|
624
559
|
}
|
|
625
|
-
|
|
626
560
|
get allChildren() {
|
|
627
561
|
return this.getChildren(this._fiber, {
|
|
628
562
|
exhaustive: true
|
|
629
563
|
});
|
|
630
564
|
}
|
|
631
|
-
|
|
565
|
+
getChildren = (fiber, opts = {
|
|
566
|
+
exhaustive: false
|
|
567
|
+
}) => {
|
|
568
|
+
if (opts.exhaustive) {
|
|
569
|
+
/**
|
|
570
|
+
* this will return objects like
|
|
571
|
+
* color or effects etc.
|
|
572
|
+
*/
|
|
573
|
+
return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
|
|
574
|
+
} else {
|
|
575
|
+
return (fiber.children || []).map(fib => wrapFiber(fib));
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
|
|
579
|
+
findAll = decider => findAll(this, decider);
|
|
580
|
+
findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
|
|
581
|
+
findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
|
|
582
|
+
findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
|
|
583
|
+
findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
|
|
632
584
|
}
|
|
633
585
|
const fiberToWrapper = new WeakMap();
|
|
634
586
|
const wrapFiber = fiber => {
|
|
635
587
|
let wrapper = fiberToWrapper.get(fiber);
|
|
636
|
-
|
|
637
588
|
if (wrapper === undefined) {
|
|
638
589
|
wrapper = new ReactThreeTestInstance(fiber);
|
|
639
590
|
fiberToWrapper.set(fiber, wrapper);
|
|
640
591
|
}
|
|
641
|
-
|
|
642
592
|
return wrapper;
|
|
643
593
|
};
|
|
644
594
|
|
|
@@ -647,9 +597,9 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
647
597
|
ReactThreeTestInstance: ReactThreeTestInstance
|
|
648
598
|
});
|
|
649
599
|
|
|
600
|
+
// Extend catalogue for render API in tests.
|
|
650
601
|
fiber.extend(THREE__namespace);
|
|
651
602
|
const act = fiber.act;
|
|
652
|
-
|
|
653
603
|
const create = async (element, options) => {
|
|
654
604
|
const canvas = createCanvas({
|
|
655
605
|
width: options == null ? void 0 : options.width,
|
|
@@ -659,87 +609,56 @@ const create = async (element, options) => {
|
|
|
659
609
|
if (contextId === 'webgl' || contextId === 'webgl2') {
|
|
660
610
|
return createWebGLContext(canvas);
|
|
661
611
|
}
|
|
662
|
-
|
|
663
612
|
return null;
|
|
664
613
|
}
|
|
665
|
-
|
|
666
614
|
canvas.getContext = getContext;
|
|
667
615
|
}
|
|
668
616
|
});
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
const _root = fiber.createRoot(_fiber).configure({
|
|
617
|
+
const _root = fiber.createRoot(canvas).configure({
|
|
672
618
|
frameloop: 'never',
|
|
673
619
|
...options,
|
|
674
620
|
events: undefined
|
|
675
621
|
});
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
scene = _root.render(element).getState().scene;
|
|
680
|
-
});
|
|
681
|
-
const _store = fiber._roots.get(_fiber).store;
|
|
622
|
+
const _store = fiber._roots.get(canvas).store;
|
|
623
|
+
await act(async () => _root.render(element));
|
|
624
|
+
const scene = _store.getState().scene;
|
|
682
625
|
return {
|
|
683
626
|
scene: wrapFiber(scene),
|
|
684
|
-
|
|
685
|
-
await act(async () =>
|
|
686
|
-
_root.unmount();
|
|
687
|
-
});
|
|
688
|
-
},
|
|
689
|
-
getInstance: () => {
|
|
690
|
-
var _mockRoots$get;
|
|
691
|
-
|
|
692
|
-
// this is our root
|
|
693
|
-
const fiber$1 = (_mockRoots$get = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get.fiber;
|
|
694
|
-
const current = fiber$1 == null ? void 0 : fiber$1.current.child.child;
|
|
695
|
-
|
|
696
|
-
if (current) {
|
|
697
|
-
const root = {
|
|
698
|
-
/**
|
|
699
|
-
* we wrap our child in a Provider component
|
|
700
|
-
* and context.Provider, so do a little
|
|
701
|
-
* artificial dive to get round this and
|
|
702
|
-
* pass context.Provider as if it was the
|
|
703
|
-
* actual react root
|
|
704
|
-
*/
|
|
705
|
-
current
|
|
706
|
-
};
|
|
707
|
-
/**
|
|
708
|
-
* so this actually returns the instance
|
|
709
|
-
* the user has passed through as a Fiber
|
|
710
|
-
*/
|
|
711
|
-
|
|
712
|
-
return fiber.reconciler.getPublicRootInstance(root);
|
|
713
|
-
} else {
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
627
|
+
async unmount() {
|
|
628
|
+
await act(async () => _root.unmount());
|
|
716
629
|
},
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
const fiber$1 = (_mockRoots$get2 = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get2.fiber;
|
|
630
|
+
getInstance() {
|
|
631
|
+
// Bail if canvas is unmounted
|
|
632
|
+
if (!fiber._roots.has(canvas)) return null;
|
|
721
633
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
634
|
+
// Traverse fiber nodes for R3F root
|
|
635
|
+
const root = {
|
|
636
|
+
current: fiber._roots.get(canvas).fiber.current
|
|
637
|
+
};
|
|
638
|
+
while (!((_root$current$child = root.current.child) != null && _root$current$child.stateNode)) {
|
|
639
|
+
var _root$current$child;
|
|
640
|
+
root.current = root.current.child;
|
|
726
641
|
}
|
|
727
642
|
|
|
728
|
-
|
|
643
|
+
// Return R3F instance from root
|
|
644
|
+
return fiber.reconciler.getPublicRootInstance(root);
|
|
645
|
+
},
|
|
646
|
+
async update(newElement) {
|
|
647
|
+
if (!fiber._roots.has(canvas)) return console.warn('RTTR: attempted to update an unmounted root!');
|
|
648
|
+
await act(async () => _root.render(newElement));
|
|
729
649
|
},
|
|
730
|
-
toTree
|
|
650
|
+
toTree() {
|
|
731
651
|
return toTree(scene);
|
|
732
652
|
},
|
|
733
|
-
toGraph
|
|
653
|
+
toGraph() {
|
|
734
654
|
return toGraph(scene);
|
|
735
655
|
},
|
|
736
656
|
fireEvent: createEventFirer(act, _store),
|
|
737
|
-
|
|
657
|
+
async advanceFrames(frames, delta = 1) {
|
|
738
658
|
const state = _store.getState();
|
|
739
|
-
|
|
740
659
|
const storeSubscribers = state.internal.subscribers;
|
|
741
660
|
const promises = [];
|
|
742
|
-
|
|
661
|
+
for (const subscriber of storeSubscribers) {
|
|
743
662
|
for (let i = 0; i < frames; i++) {
|
|
744
663
|
if (is.arr(delta)) {
|
|
745
664
|
promises.push(new Promise(() => subscriber.ref.current(state, delta[i] || delta[-1])));
|
|
@@ -747,7 +666,7 @@ const create = async (element, options) => {
|
|
|
747
666
|
promises.push(new Promise(() => subscriber.ref.current(state, delta)));
|
|
748
667
|
}
|
|
749
668
|
}
|
|
750
|
-
}
|
|
669
|
+
}
|
|
751
670
|
Promise.all(promises);
|
|
752
671
|
}
|
|
753
672
|
};
|
|
@@ -33,13 +33,13 @@ const treeObjectFactory = (type, props, children) => ({
|
|
|
33
33
|
props,
|
|
34
34
|
children
|
|
35
35
|
});
|
|
36
|
-
|
|
37
36
|
const toTreeBranch = obj => obj.map(child => {
|
|
38
|
-
return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
|
|
37
|
+
return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
|
|
38
|
+
...child.__r3f.memoizedProps
|
|
39
39
|
}, toTreeBranch([...(child.children || []), ...child.__r3f.objects]));
|
|
40
40
|
});
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const toTree = root => root.children.map(obj => treeObjectFactory(lowerCaseFirstLetter(obj.type), {
|
|
42
|
+
...obj.__r3f.memoizedProps
|
|
43
43
|
}, toTreeBranch([...obj.children, ...obj.__r3f.objects])));
|
|
44
44
|
|
|
45
45
|
const graphObjectFactory = (type, name, children) => ({
|
|
@@ -47,7 +47,6 @@ const graphObjectFactory = (type, name, children) => ({
|
|
|
47
47
|
name,
|
|
48
48
|
children
|
|
49
49
|
});
|
|
50
|
-
|
|
51
50
|
const toGraph = object => object.children.map(child => graphObjectFactory(child.type, child.name || '', toGraph(child)));
|
|
52
51
|
|
|
53
52
|
const is = {
|
|
@@ -57,24 +56,19 @@ const is = {
|
|
|
57
56
|
num: a => typeof a === 'number',
|
|
58
57
|
und: a => a === void 0,
|
|
59
58
|
arr: a => Array.isArray(a),
|
|
60
|
-
|
|
61
59
|
equ(a, b) {
|
|
62
60
|
// Wrong type or one of the two undefined, doesn't match
|
|
63
|
-
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
64
|
-
|
|
65
|
-
if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
|
|
66
|
-
|
|
67
|
-
if (is.arr(a) && a == b) return true;
|
|
68
|
-
|
|
61
|
+
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
62
|
+
// Atomic, just compare a against b
|
|
63
|
+
if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
|
|
64
|
+
// Array, shallow compare first to see if it's a match
|
|
65
|
+
if (is.arr(a) && a == b) return true;
|
|
66
|
+
// Last resort, go through keys
|
|
69
67
|
let i;
|
|
70
|
-
|
|
71
68
|
for (i in a) if (!(i in b)) return false;
|
|
72
|
-
|
|
73
69
|
for (i in b) if (a[i] !== b[i]) return false;
|
|
74
|
-
|
|
75
70
|
return is.und(i) ? a === b : true;
|
|
76
71
|
}
|
|
77
|
-
|
|
78
72
|
};
|
|
79
73
|
|
|
80
74
|
const createCanvas = ({
|
|
@@ -85,15 +79,11 @@ const createCanvas = ({
|
|
|
85
79
|
const canvas = document.createElement('canvas');
|
|
86
80
|
canvas.height = height;
|
|
87
81
|
canvas.width = width;
|
|
88
|
-
|
|
89
82
|
canvas.addEventListener = () => {};
|
|
90
|
-
|
|
91
83
|
canvas.removeEventListener = () => {};
|
|
92
|
-
|
|
93
84
|
if (beforeReturn) {
|
|
94
85
|
beforeReturn(canvas);
|
|
95
86
|
}
|
|
96
|
-
|
|
97
87
|
return canvas;
|
|
98
88
|
};
|
|
99
89
|
|
|
@@ -434,40 +424,8 @@ const extensions = {
|
|
|
434
424
|
EXT_sRGB: null,
|
|
435
425
|
WEBGL_compressed_texture_etc1: null
|
|
436
426
|
};
|
|
437
|
-
|
|
438
427
|
class WebGLRenderingContext {
|
|
439
428
|
constructor(canvas) {
|
|
440
|
-
this.getShaderPrecisionFormat = () => {
|
|
441
|
-
return {
|
|
442
|
-
rangeMin: 127,
|
|
443
|
-
rangeMax: 127,
|
|
444
|
-
precision: 23
|
|
445
|
-
};
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
this.GL_VERSION = 7938;
|
|
449
|
-
this.SCISSOR_BOX = 3088;
|
|
450
|
-
this.VIEWPORT = 2978;
|
|
451
|
-
|
|
452
|
-
this.getParameter = paramId => {
|
|
453
|
-
switch (paramId) {
|
|
454
|
-
case this.GL_VERSION:
|
|
455
|
-
return ['WebGL1'];
|
|
456
|
-
|
|
457
|
-
case this.SCISSOR_BOX:
|
|
458
|
-
case this.VIEWPORT:
|
|
459
|
-
return [0, 0, 1, 1];
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
this.getExtension = ext => {
|
|
464
|
-
return extensions[ext];
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
this.getProgramInfoLog = () => '';
|
|
468
|
-
|
|
469
|
-
this.getShaderInfoLog = () => '';
|
|
470
|
-
|
|
471
429
|
this.canvas = canvas;
|
|
472
430
|
this.drawingBufferWidth = canvas.width;
|
|
473
431
|
this.drawingBufferHeight = canvas.height;
|
|
@@ -478,28 +436,46 @@ class WebGLRenderingContext {
|
|
|
478
436
|
});
|
|
479
437
|
Object.assign(this, enums);
|
|
480
438
|
}
|
|
481
|
-
|
|
439
|
+
getShaderPrecisionFormat = () => {
|
|
440
|
+
return {
|
|
441
|
+
rangeMin: 127,
|
|
442
|
+
rangeMax: 127,
|
|
443
|
+
precision: 23
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
GL_VERSION = 7938;
|
|
447
|
+
SCISSOR_BOX = 3088;
|
|
448
|
+
VIEWPORT = 2978;
|
|
449
|
+
getParameter = paramId => {
|
|
450
|
+
switch (paramId) {
|
|
451
|
+
case this.GL_VERSION:
|
|
452
|
+
return ['WebGL1'];
|
|
453
|
+
case this.SCISSOR_BOX:
|
|
454
|
+
case this.VIEWPORT:
|
|
455
|
+
return [0, 0, 1, 1];
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
getExtension = ext => {
|
|
459
|
+
return extensions[ext];
|
|
460
|
+
};
|
|
461
|
+
getProgramInfoLog = () => '';
|
|
462
|
+
getShaderInfoLog = () => '';
|
|
482
463
|
}
|
|
483
|
-
|
|
484
464
|
const createWebGLContext = canvas => new WebGLRenderingContext(canvas);
|
|
485
465
|
|
|
486
466
|
const createEventFirer = (act, store) => {
|
|
487
467
|
const findEventHandler = (element, eventName) => {
|
|
488
468
|
const eventHandlerName = toEventHandlerName(eventName);
|
|
489
469
|
const props = element.props;
|
|
490
|
-
|
|
491
470
|
if (typeof props[eventHandlerName] === 'function') {
|
|
492
471
|
return props[eventHandlerName];
|
|
493
472
|
}
|
|
494
|
-
|
|
495
473
|
if (typeof props[eventName] === 'function') {
|
|
496
474
|
return props[eventName];
|
|
497
475
|
}
|
|
498
|
-
|
|
499
476
|
console.warn(`Handler for ${eventName} was not found. You must pass event names in camelCase or name of the handler https://github.com/pmndrs/react-three-fiber/blob/master/packages/test-renderer/markdown/rttr.md#create-fireevent`);
|
|
500
477
|
return null;
|
|
501
478
|
};
|
|
502
|
-
|
|
503
479
|
const createSyntheticEvent = (element, data) => {
|
|
504
480
|
const raycastEvent = {
|
|
505
481
|
camera: store.getState().camera,
|
|
@@ -511,23 +487,18 @@ const createEventFirer = (act, store) => {
|
|
|
511
487
|
};
|
|
512
488
|
return raycastEvent;
|
|
513
489
|
};
|
|
514
|
-
|
|
515
490
|
const invokeEvent = async (element, eventName, data) => {
|
|
516
491
|
const handler = findEventHandler(element, eventName);
|
|
517
|
-
|
|
518
492
|
if (!handler) {
|
|
519
493
|
return;
|
|
520
494
|
}
|
|
521
|
-
|
|
522
495
|
let returnValue;
|
|
523
496
|
await act(async () => {
|
|
524
497
|
returnValue = handler(createSyntheticEvent(element, data));
|
|
525
498
|
});
|
|
526
499
|
return returnValue;
|
|
527
500
|
};
|
|
528
|
-
|
|
529
501
|
const fireEvent = async (element, eventName, data = {}) => await invokeEvent(element, eventName, data);
|
|
530
|
-
|
|
531
502
|
return fireEvent;
|
|
532
503
|
};
|
|
533
504
|
|
|
@@ -535,7 +506,6 @@ const expectOne = (items, msg) => {
|
|
|
535
506
|
if (items.length === 1) {
|
|
536
507
|
return items[0];
|
|
537
508
|
}
|
|
538
|
-
|
|
539
509
|
const prefix = items.length === 0 ? 'RTTR: No instances found' : `RTTR: Expected 1 but found ${items.length} instances`;
|
|
540
510
|
throw new Error(`${prefix} ${msg}`);
|
|
541
511
|
};
|
|
@@ -544,22 +514,20 @@ const matchProps = (props, filter) => {
|
|
|
544
514
|
// Check for matches if filter contains regex matchers
|
|
545
515
|
const isRegex = filter[key] instanceof RegExp;
|
|
546
516
|
const shouldMatch = isRegex && typeof props[key] === 'string';
|
|
547
|
-
const match = shouldMatch && filter[key].test(props[key]);
|
|
517
|
+
const match = shouldMatch && filter[key].test(props[key]);
|
|
548
518
|
|
|
519
|
+
// Bail if props aren't identical and filters found no match
|
|
549
520
|
if (props[key] !== filter[key] && !match) {
|
|
550
521
|
return false;
|
|
551
522
|
}
|
|
552
523
|
}
|
|
553
|
-
|
|
554
524
|
return true;
|
|
555
525
|
};
|
|
556
526
|
const findAll = (root, decider) => {
|
|
557
527
|
const results = [];
|
|
558
|
-
|
|
559
528
|
if (decider(root)) {
|
|
560
529
|
results.push(root);
|
|
561
530
|
}
|
|
562
|
-
|
|
563
531
|
root.allChildren.forEach(child => {
|
|
564
532
|
results.push(...findAll(child, decider));
|
|
565
533
|
});
|
|
@@ -567,78 +535,60 @@ const findAll = (root, decider) => {
|
|
|
567
535
|
};
|
|
568
536
|
|
|
569
537
|
class ReactThreeTestInstance {
|
|
570
|
-
constructor(
|
|
571
|
-
this.
|
|
572
|
-
exhaustive: false
|
|
573
|
-
}) => {
|
|
574
|
-
if (opts.exhaustive) {
|
|
575
|
-
/**
|
|
576
|
-
* this will return objects like
|
|
577
|
-
* color or effects etc.
|
|
578
|
-
*/
|
|
579
|
-
return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
|
|
580
|
-
} else {
|
|
581
|
-
return (fiber.children || []).map(fib => wrapFiber(fib));
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
this.find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
|
|
586
|
-
|
|
587
|
-
this.findAll = decider => findAll(this, decider);
|
|
588
|
-
|
|
589
|
-
this.findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
|
|
590
|
-
|
|
591
|
-
this.findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
|
|
592
|
-
|
|
593
|
-
this.findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
|
|
594
|
-
|
|
595
|
-
this.findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
|
|
596
|
-
|
|
597
|
-
this._fiber = _fiber;
|
|
538
|
+
constructor(fiber) {
|
|
539
|
+
this._fiber = fiber;
|
|
598
540
|
}
|
|
599
|
-
|
|
600
541
|
get instance() {
|
|
601
542
|
return this._fiber;
|
|
602
543
|
}
|
|
603
|
-
|
|
604
544
|
get type() {
|
|
605
545
|
return this._fiber.type;
|
|
606
546
|
}
|
|
607
|
-
|
|
608
547
|
get props() {
|
|
609
548
|
return this._fiber.__r3f.memoizedProps;
|
|
610
549
|
}
|
|
611
|
-
|
|
612
550
|
get parent() {
|
|
613
551
|
const parent = this._fiber.__r3f.parent;
|
|
614
|
-
|
|
615
552
|
if (parent !== null) {
|
|
616
553
|
return wrapFiber(parent);
|
|
617
554
|
}
|
|
618
|
-
|
|
619
555
|
return parent;
|
|
620
556
|
}
|
|
621
|
-
|
|
622
557
|
get children() {
|
|
623
558
|
return this.getChildren(this._fiber);
|
|
624
559
|
}
|
|
625
|
-
|
|
626
560
|
get allChildren() {
|
|
627
561
|
return this.getChildren(this._fiber, {
|
|
628
562
|
exhaustive: true
|
|
629
563
|
});
|
|
630
564
|
}
|
|
631
|
-
|
|
565
|
+
getChildren = (fiber, opts = {
|
|
566
|
+
exhaustive: false
|
|
567
|
+
}) => {
|
|
568
|
+
if (opts.exhaustive) {
|
|
569
|
+
/**
|
|
570
|
+
* this will return objects like
|
|
571
|
+
* color or effects etc.
|
|
572
|
+
*/
|
|
573
|
+
return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
|
|
574
|
+
} else {
|
|
575
|
+
return (fiber.children || []).map(fib => wrapFiber(fib));
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
|
|
579
|
+
findAll = decider => findAll(this, decider);
|
|
580
|
+
findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
|
|
581
|
+
findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
|
|
582
|
+
findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
|
|
583
|
+
findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
|
|
632
584
|
}
|
|
633
585
|
const fiberToWrapper = new WeakMap();
|
|
634
586
|
const wrapFiber = fiber => {
|
|
635
587
|
let wrapper = fiberToWrapper.get(fiber);
|
|
636
|
-
|
|
637
588
|
if (wrapper === undefined) {
|
|
638
589
|
wrapper = new ReactThreeTestInstance(fiber);
|
|
639
590
|
fiberToWrapper.set(fiber, wrapper);
|
|
640
591
|
}
|
|
641
|
-
|
|
642
592
|
return wrapper;
|
|
643
593
|
};
|
|
644
594
|
|
|
@@ -647,9 +597,9 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
647
597
|
ReactThreeTestInstance: ReactThreeTestInstance
|
|
648
598
|
});
|
|
649
599
|
|
|
600
|
+
// Extend catalogue for render API in tests.
|
|
650
601
|
fiber.extend(THREE__namespace);
|
|
651
602
|
const act = fiber.act;
|
|
652
|
-
|
|
653
603
|
const create = async (element, options) => {
|
|
654
604
|
const canvas = createCanvas({
|
|
655
605
|
width: options == null ? void 0 : options.width,
|
|
@@ -659,87 +609,56 @@ const create = async (element, options) => {
|
|
|
659
609
|
if (contextId === 'webgl' || contextId === 'webgl2') {
|
|
660
610
|
return createWebGLContext(canvas);
|
|
661
611
|
}
|
|
662
|
-
|
|
663
612
|
return null;
|
|
664
613
|
}
|
|
665
|
-
|
|
666
614
|
canvas.getContext = getContext;
|
|
667
615
|
}
|
|
668
616
|
});
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
const _root = fiber.createRoot(_fiber).configure({
|
|
617
|
+
const _root = fiber.createRoot(canvas).configure({
|
|
672
618
|
frameloop: 'never',
|
|
673
619
|
...options,
|
|
674
620
|
events: undefined
|
|
675
621
|
});
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
scene = _root.render(element).getState().scene;
|
|
680
|
-
});
|
|
681
|
-
const _store = fiber._roots.get(_fiber).store;
|
|
622
|
+
const _store = fiber._roots.get(canvas).store;
|
|
623
|
+
await act(async () => _root.render(element));
|
|
624
|
+
const scene = _store.getState().scene;
|
|
682
625
|
return {
|
|
683
626
|
scene: wrapFiber(scene),
|
|
684
|
-
|
|
685
|
-
await act(async () =>
|
|
686
|
-
_root.unmount();
|
|
687
|
-
});
|
|
688
|
-
},
|
|
689
|
-
getInstance: () => {
|
|
690
|
-
var _mockRoots$get;
|
|
691
|
-
|
|
692
|
-
// this is our root
|
|
693
|
-
const fiber$1 = (_mockRoots$get = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get.fiber;
|
|
694
|
-
const current = fiber$1 == null ? void 0 : fiber$1.current.child.child;
|
|
695
|
-
|
|
696
|
-
if (current) {
|
|
697
|
-
const root = {
|
|
698
|
-
/**
|
|
699
|
-
* we wrap our child in a Provider component
|
|
700
|
-
* and context.Provider, so do a little
|
|
701
|
-
* artificial dive to get round this and
|
|
702
|
-
* pass context.Provider as if it was the
|
|
703
|
-
* actual react root
|
|
704
|
-
*/
|
|
705
|
-
current
|
|
706
|
-
};
|
|
707
|
-
/**
|
|
708
|
-
* so this actually returns the instance
|
|
709
|
-
* the user has passed through as a Fiber
|
|
710
|
-
*/
|
|
711
|
-
|
|
712
|
-
return fiber.reconciler.getPublicRootInstance(root);
|
|
713
|
-
} else {
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
627
|
+
async unmount() {
|
|
628
|
+
await act(async () => _root.unmount());
|
|
716
629
|
},
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
const fiber$1 = (_mockRoots$get2 = fiber._roots.get(_fiber)) == null ? void 0 : _mockRoots$get2.fiber;
|
|
630
|
+
getInstance() {
|
|
631
|
+
// Bail if canvas is unmounted
|
|
632
|
+
if (!fiber._roots.has(canvas)) return null;
|
|
721
633
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
634
|
+
// Traverse fiber nodes for R3F root
|
|
635
|
+
const root = {
|
|
636
|
+
current: fiber._roots.get(canvas).fiber.current
|
|
637
|
+
};
|
|
638
|
+
while (!((_root$current$child = root.current.child) != null && _root$current$child.stateNode)) {
|
|
639
|
+
var _root$current$child;
|
|
640
|
+
root.current = root.current.child;
|
|
726
641
|
}
|
|
727
642
|
|
|
728
|
-
|
|
643
|
+
// Return R3F instance from root
|
|
644
|
+
return fiber.reconciler.getPublicRootInstance(root);
|
|
645
|
+
},
|
|
646
|
+
async update(newElement) {
|
|
647
|
+
if (!fiber._roots.has(canvas)) return console.warn('RTTR: attempted to update an unmounted root!');
|
|
648
|
+
await act(async () => _root.render(newElement));
|
|
729
649
|
},
|
|
730
|
-
toTree
|
|
650
|
+
toTree() {
|
|
731
651
|
return toTree(scene);
|
|
732
652
|
},
|
|
733
|
-
toGraph
|
|
653
|
+
toGraph() {
|
|
734
654
|
return toGraph(scene);
|
|
735
655
|
},
|
|
736
656
|
fireEvent: createEventFirer(act, _store),
|
|
737
|
-
|
|
657
|
+
async advanceFrames(frames, delta = 1) {
|
|
738
658
|
const state = _store.getState();
|
|
739
|
-
|
|
740
659
|
const storeSubscribers = state.internal.subscribers;
|
|
741
660
|
const promises = [];
|
|
742
|
-
|
|
661
|
+
for (const subscriber of storeSubscribers) {
|
|
743
662
|
for (let i = 0; i < frames; i++) {
|
|
744
663
|
if (is.arr(delta)) {
|
|
745
664
|
promises.push(new Promise(() => subscriber.ref.current(state, delta[i] || delta[-1])));
|
|
@@ -747,7 +666,7 @@ const create = async (element, options) => {
|
|
|
747
666
|
promises.push(new Promise(() => subscriber.ref.current(state, delta)));
|
|
748
667
|
}
|
|
749
668
|
}
|
|
750
|
-
}
|
|
669
|
+
}
|
|
751
670
|
Promise.all(promises);
|
|
752
671
|
}
|
|
753
672
|
};
|
|
@@ -9,13 +9,13 @@ const treeObjectFactory = (type, props, children) => ({
|
|
|
9
9
|
props,
|
|
10
10
|
children
|
|
11
11
|
});
|
|
12
|
-
|
|
13
12
|
const toTreeBranch = obj => obj.map(child => {
|
|
14
|
-
return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
|
|
13
|
+
return treeObjectFactory(lowerCaseFirstLetter(child.type || child.constructor.name), {
|
|
14
|
+
...child.__r3f.memoizedProps
|
|
15
15
|
}, toTreeBranch([...(child.children || []), ...child.__r3f.objects]));
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const toTree = root => root.children.map(obj => treeObjectFactory(lowerCaseFirstLetter(obj.type), {
|
|
18
|
+
...obj.__r3f.memoizedProps
|
|
19
19
|
}, toTreeBranch([...obj.children, ...obj.__r3f.objects])));
|
|
20
20
|
|
|
21
21
|
const graphObjectFactory = (type, name, children) => ({
|
|
@@ -23,7 +23,6 @@ const graphObjectFactory = (type, name, children) => ({
|
|
|
23
23
|
name,
|
|
24
24
|
children
|
|
25
25
|
});
|
|
26
|
-
|
|
27
26
|
const toGraph = object => object.children.map(child => graphObjectFactory(child.type, child.name || '', toGraph(child)));
|
|
28
27
|
|
|
29
28
|
const is = {
|
|
@@ -33,24 +32,19 @@ const is = {
|
|
|
33
32
|
num: a => typeof a === 'number',
|
|
34
33
|
und: a => a === void 0,
|
|
35
34
|
arr: a => Array.isArray(a),
|
|
36
|
-
|
|
37
35
|
equ(a, b) {
|
|
38
36
|
// Wrong type or one of the two undefined, doesn't match
|
|
39
|
-
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
40
|
-
|
|
41
|
-
if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
|
|
42
|
-
|
|
43
|
-
if (is.arr(a) && a == b) return true;
|
|
44
|
-
|
|
37
|
+
if (typeof a !== typeof b || !!a !== !!b) return false;
|
|
38
|
+
// Atomic, just compare a against b
|
|
39
|
+
if (is.str(a) || is.num(a) || is.obj(a)) return a === b;
|
|
40
|
+
// Array, shallow compare first to see if it's a match
|
|
41
|
+
if (is.arr(a) && a == b) return true;
|
|
42
|
+
// Last resort, go through keys
|
|
45
43
|
let i;
|
|
46
|
-
|
|
47
44
|
for (i in a) if (!(i in b)) return false;
|
|
48
|
-
|
|
49
45
|
for (i in b) if (a[i] !== b[i]) return false;
|
|
50
|
-
|
|
51
46
|
return is.und(i) ? a === b : true;
|
|
52
47
|
}
|
|
53
|
-
|
|
54
48
|
};
|
|
55
49
|
|
|
56
50
|
const createCanvas = ({
|
|
@@ -61,15 +55,11 @@ const createCanvas = ({
|
|
|
61
55
|
const canvas = document.createElement('canvas');
|
|
62
56
|
canvas.height = height;
|
|
63
57
|
canvas.width = width;
|
|
64
|
-
|
|
65
58
|
canvas.addEventListener = () => {};
|
|
66
|
-
|
|
67
59
|
canvas.removeEventListener = () => {};
|
|
68
|
-
|
|
69
60
|
if (beforeReturn) {
|
|
70
61
|
beforeReturn(canvas);
|
|
71
62
|
}
|
|
72
|
-
|
|
73
63
|
return canvas;
|
|
74
64
|
};
|
|
75
65
|
|
|
@@ -410,40 +400,8 @@ const extensions = {
|
|
|
410
400
|
EXT_sRGB: null,
|
|
411
401
|
WEBGL_compressed_texture_etc1: null
|
|
412
402
|
};
|
|
413
|
-
|
|
414
403
|
class WebGLRenderingContext {
|
|
415
404
|
constructor(canvas) {
|
|
416
|
-
this.getShaderPrecisionFormat = () => {
|
|
417
|
-
return {
|
|
418
|
-
rangeMin: 127,
|
|
419
|
-
rangeMax: 127,
|
|
420
|
-
precision: 23
|
|
421
|
-
};
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
this.GL_VERSION = 7938;
|
|
425
|
-
this.SCISSOR_BOX = 3088;
|
|
426
|
-
this.VIEWPORT = 2978;
|
|
427
|
-
|
|
428
|
-
this.getParameter = paramId => {
|
|
429
|
-
switch (paramId) {
|
|
430
|
-
case this.GL_VERSION:
|
|
431
|
-
return ['WebGL1'];
|
|
432
|
-
|
|
433
|
-
case this.SCISSOR_BOX:
|
|
434
|
-
case this.VIEWPORT:
|
|
435
|
-
return [0, 0, 1, 1];
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
this.getExtension = ext => {
|
|
440
|
-
return extensions[ext];
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
this.getProgramInfoLog = () => '';
|
|
444
|
-
|
|
445
|
-
this.getShaderInfoLog = () => '';
|
|
446
|
-
|
|
447
405
|
this.canvas = canvas;
|
|
448
406
|
this.drawingBufferWidth = canvas.width;
|
|
449
407
|
this.drawingBufferHeight = canvas.height;
|
|
@@ -454,28 +412,46 @@ class WebGLRenderingContext {
|
|
|
454
412
|
});
|
|
455
413
|
Object.assign(this, enums);
|
|
456
414
|
}
|
|
457
|
-
|
|
415
|
+
getShaderPrecisionFormat = () => {
|
|
416
|
+
return {
|
|
417
|
+
rangeMin: 127,
|
|
418
|
+
rangeMax: 127,
|
|
419
|
+
precision: 23
|
|
420
|
+
};
|
|
421
|
+
};
|
|
422
|
+
GL_VERSION = 7938;
|
|
423
|
+
SCISSOR_BOX = 3088;
|
|
424
|
+
VIEWPORT = 2978;
|
|
425
|
+
getParameter = paramId => {
|
|
426
|
+
switch (paramId) {
|
|
427
|
+
case this.GL_VERSION:
|
|
428
|
+
return ['WebGL1'];
|
|
429
|
+
case this.SCISSOR_BOX:
|
|
430
|
+
case this.VIEWPORT:
|
|
431
|
+
return [0, 0, 1, 1];
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
getExtension = ext => {
|
|
435
|
+
return extensions[ext];
|
|
436
|
+
};
|
|
437
|
+
getProgramInfoLog = () => '';
|
|
438
|
+
getShaderInfoLog = () => '';
|
|
458
439
|
}
|
|
459
|
-
|
|
460
440
|
const createWebGLContext = canvas => new WebGLRenderingContext(canvas);
|
|
461
441
|
|
|
462
442
|
const createEventFirer = (act, store) => {
|
|
463
443
|
const findEventHandler = (element, eventName) => {
|
|
464
444
|
const eventHandlerName = toEventHandlerName(eventName);
|
|
465
445
|
const props = element.props;
|
|
466
|
-
|
|
467
446
|
if (typeof props[eventHandlerName] === 'function') {
|
|
468
447
|
return props[eventHandlerName];
|
|
469
448
|
}
|
|
470
|
-
|
|
471
449
|
if (typeof props[eventName] === 'function') {
|
|
472
450
|
return props[eventName];
|
|
473
451
|
}
|
|
474
|
-
|
|
475
452
|
console.warn(`Handler for ${eventName} was not found. You must pass event names in camelCase or name of the handler https://github.com/pmndrs/react-three-fiber/blob/master/packages/test-renderer/markdown/rttr.md#create-fireevent`);
|
|
476
453
|
return null;
|
|
477
454
|
};
|
|
478
|
-
|
|
479
455
|
const createSyntheticEvent = (element, data) => {
|
|
480
456
|
const raycastEvent = {
|
|
481
457
|
camera: store.getState().camera,
|
|
@@ -487,23 +463,18 @@ const createEventFirer = (act, store) => {
|
|
|
487
463
|
};
|
|
488
464
|
return raycastEvent;
|
|
489
465
|
};
|
|
490
|
-
|
|
491
466
|
const invokeEvent = async (element, eventName, data) => {
|
|
492
467
|
const handler = findEventHandler(element, eventName);
|
|
493
|
-
|
|
494
468
|
if (!handler) {
|
|
495
469
|
return;
|
|
496
470
|
}
|
|
497
|
-
|
|
498
471
|
let returnValue;
|
|
499
472
|
await act(async () => {
|
|
500
473
|
returnValue = handler(createSyntheticEvent(element, data));
|
|
501
474
|
});
|
|
502
475
|
return returnValue;
|
|
503
476
|
};
|
|
504
|
-
|
|
505
477
|
const fireEvent = async (element, eventName, data = {}) => await invokeEvent(element, eventName, data);
|
|
506
|
-
|
|
507
478
|
return fireEvent;
|
|
508
479
|
};
|
|
509
480
|
|
|
@@ -511,7 +482,6 @@ const expectOne = (items, msg) => {
|
|
|
511
482
|
if (items.length === 1) {
|
|
512
483
|
return items[0];
|
|
513
484
|
}
|
|
514
|
-
|
|
515
485
|
const prefix = items.length === 0 ? 'RTTR: No instances found' : `RTTR: Expected 1 but found ${items.length} instances`;
|
|
516
486
|
throw new Error(`${prefix} ${msg}`);
|
|
517
487
|
};
|
|
@@ -520,22 +490,20 @@ const matchProps = (props, filter) => {
|
|
|
520
490
|
// Check for matches if filter contains regex matchers
|
|
521
491
|
const isRegex = filter[key] instanceof RegExp;
|
|
522
492
|
const shouldMatch = isRegex && typeof props[key] === 'string';
|
|
523
|
-
const match = shouldMatch && filter[key].test(props[key]);
|
|
493
|
+
const match = shouldMatch && filter[key].test(props[key]);
|
|
524
494
|
|
|
495
|
+
// Bail if props aren't identical and filters found no match
|
|
525
496
|
if (props[key] !== filter[key] && !match) {
|
|
526
497
|
return false;
|
|
527
498
|
}
|
|
528
499
|
}
|
|
529
|
-
|
|
530
500
|
return true;
|
|
531
501
|
};
|
|
532
502
|
const findAll = (root, decider) => {
|
|
533
503
|
const results = [];
|
|
534
|
-
|
|
535
504
|
if (decider(root)) {
|
|
536
505
|
results.push(root);
|
|
537
506
|
}
|
|
538
|
-
|
|
539
507
|
root.allChildren.forEach(child => {
|
|
540
508
|
results.push(...findAll(child, decider));
|
|
541
509
|
});
|
|
@@ -543,78 +511,60 @@ const findAll = (root, decider) => {
|
|
|
543
511
|
};
|
|
544
512
|
|
|
545
513
|
class ReactThreeTestInstance {
|
|
546
|
-
constructor(
|
|
547
|
-
this.
|
|
548
|
-
exhaustive: false
|
|
549
|
-
}) => {
|
|
550
|
-
if (opts.exhaustive) {
|
|
551
|
-
/**
|
|
552
|
-
* this will return objects like
|
|
553
|
-
* color or effects etc.
|
|
554
|
-
*/
|
|
555
|
-
return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
|
|
556
|
-
} else {
|
|
557
|
-
return (fiber.children || []).map(fib => wrapFiber(fib));
|
|
558
|
-
}
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
this.find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
|
|
562
|
-
|
|
563
|
-
this.findAll = decider => findAll(this, decider);
|
|
564
|
-
|
|
565
|
-
this.findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
|
|
566
|
-
|
|
567
|
-
this.findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
|
|
568
|
-
|
|
569
|
-
this.findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
|
|
570
|
-
|
|
571
|
-
this.findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
|
|
572
|
-
|
|
573
|
-
this._fiber = _fiber;
|
|
514
|
+
constructor(fiber) {
|
|
515
|
+
this._fiber = fiber;
|
|
574
516
|
}
|
|
575
|
-
|
|
576
517
|
get instance() {
|
|
577
518
|
return this._fiber;
|
|
578
519
|
}
|
|
579
|
-
|
|
580
520
|
get type() {
|
|
581
521
|
return this._fiber.type;
|
|
582
522
|
}
|
|
583
|
-
|
|
584
523
|
get props() {
|
|
585
524
|
return this._fiber.__r3f.memoizedProps;
|
|
586
525
|
}
|
|
587
|
-
|
|
588
526
|
get parent() {
|
|
589
527
|
const parent = this._fiber.__r3f.parent;
|
|
590
|
-
|
|
591
528
|
if (parent !== null) {
|
|
592
529
|
return wrapFiber(parent);
|
|
593
530
|
}
|
|
594
|
-
|
|
595
531
|
return parent;
|
|
596
532
|
}
|
|
597
|
-
|
|
598
533
|
get children() {
|
|
599
534
|
return this.getChildren(this._fiber);
|
|
600
535
|
}
|
|
601
|
-
|
|
602
536
|
get allChildren() {
|
|
603
537
|
return this.getChildren(this._fiber, {
|
|
604
538
|
exhaustive: true
|
|
605
539
|
});
|
|
606
540
|
}
|
|
607
|
-
|
|
541
|
+
getChildren = (fiber, opts = {
|
|
542
|
+
exhaustive: false
|
|
543
|
+
}) => {
|
|
544
|
+
if (opts.exhaustive) {
|
|
545
|
+
/**
|
|
546
|
+
* this will return objects like
|
|
547
|
+
* color or effects etc.
|
|
548
|
+
*/
|
|
549
|
+
return [...(fiber.children || []).map(fib => wrapFiber(fib)), ...fiber.__r3f.objects.map(fib => wrapFiber(fib))];
|
|
550
|
+
} else {
|
|
551
|
+
return (fiber.children || []).map(fib => wrapFiber(fib));
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
find = decider => expectOne(findAll(this, decider), `matching custom checker: ${decider.toString()}`);
|
|
555
|
+
findAll = decider => findAll(this, decider);
|
|
556
|
+
findByType = type => expectOne(findAll(this, node => Boolean(node.type && node.type === type)), `with node type: "${type || 'Unknown'}"`);
|
|
557
|
+
findAllByType = type => findAll(this, node => Boolean(node.type && node.type === type));
|
|
558
|
+
findByProps = props => expectOne(this.findAllByProps(props), `with props: ${JSON.stringify(props)}`);
|
|
559
|
+
findAllByProps = props => findAll(this, node => Boolean(node.props && matchProps(node.props, props)));
|
|
608
560
|
}
|
|
609
561
|
const fiberToWrapper = new WeakMap();
|
|
610
562
|
const wrapFiber = fiber => {
|
|
611
563
|
let wrapper = fiberToWrapper.get(fiber);
|
|
612
|
-
|
|
613
564
|
if (wrapper === undefined) {
|
|
614
565
|
wrapper = new ReactThreeTestInstance(fiber);
|
|
615
566
|
fiberToWrapper.set(fiber, wrapper);
|
|
616
567
|
}
|
|
617
|
-
|
|
618
568
|
return wrapper;
|
|
619
569
|
};
|
|
620
570
|
|
|
@@ -623,9 +573,9 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
623
573
|
ReactThreeTestInstance: ReactThreeTestInstance
|
|
624
574
|
});
|
|
625
575
|
|
|
576
|
+
// Extend catalogue for render API in tests.
|
|
626
577
|
extend(THREE);
|
|
627
578
|
const act = act$1;
|
|
628
|
-
|
|
629
579
|
const create = async (element, options) => {
|
|
630
580
|
const canvas = createCanvas({
|
|
631
581
|
width: options == null ? void 0 : options.width,
|
|
@@ -635,87 +585,56 @@ const create = async (element, options) => {
|
|
|
635
585
|
if (contextId === 'webgl' || contextId === 'webgl2') {
|
|
636
586
|
return createWebGLContext(canvas);
|
|
637
587
|
}
|
|
638
|
-
|
|
639
588
|
return null;
|
|
640
589
|
}
|
|
641
|
-
|
|
642
590
|
canvas.getContext = getContext;
|
|
643
591
|
}
|
|
644
592
|
});
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
const _root = createRoot(_fiber).configure({
|
|
593
|
+
const _root = createRoot(canvas).configure({
|
|
648
594
|
frameloop: 'never',
|
|
649
595
|
...options,
|
|
650
596
|
events: undefined
|
|
651
597
|
});
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
scene = _root.render(element).getState().scene;
|
|
656
|
-
});
|
|
657
|
-
const _store = _roots.get(_fiber).store;
|
|
598
|
+
const _store = _roots.get(canvas).store;
|
|
599
|
+
await act(async () => _root.render(element));
|
|
600
|
+
const scene = _store.getState().scene;
|
|
658
601
|
return {
|
|
659
602
|
scene: wrapFiber(scene),
|
|
660
|
-
|
|
661
|
-
await act(async () =>
|
|
662
|
-
_root.unmount();
|
|
663
|
-
});
|
|
664
|
-
},
|
|
665
|
-
getInstance: () => {
|
|
666
|
-
var _mockRoots$get;
|
|
667
|
-
|
|
668
|
-
// this is our root
|
|
669
|
-
const fiber = (_mockRoots$get = _roots.get(_fiber)) == null ? void 0 : _mockRoots$get.fiber;
|
|
670
|
-
const current = fiber == null ? void 0 : fiber.current.child.child;
|
|
671
|
-
|
|
672
|
-
if (current) {
|
|
673
|
-
const root = {
|
|
674
|
-
/**
|
|
675
|
-
* we wrap our child in a Provider component
|
|
676
|
-
* and context.Provider, so do a little
|
|
677
|
-
* artificial dive to get round this and
|
|
678
|
-
* pass context.Provider as if it was the
|
|
679
|
-
* actual react root
|
|
680
|
-
*/
|
|
681
|
-
current
|
|
682
|
-
};
|
|
683
|
-
/**
|
|
684
|
-
* so this actually returns the instance
|
|
685
|
-
* the user has passed through as a Fiber
|
|
686
|
-
*/
|
|
687
|
-
|
|
688
|
-
return reconciler.getPublicRootInstance(root);
|
|
689
|
-
} else {
|
|
690
|
-
return null;
|
|
691
|
-
}
|
|
603
|
+
async unmount() {
|
|
604
|
+
await act(async () => _root.unmount());
|
|
692
605
|
},
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
const fiber = (_mockRoots$get2 = _roots.get(_fiber)) == null ? void 0 : _mockRoots$get2.fiber;
|
|
606
|
+
getInstance() {
|
|
607
|
+
// Bail if canvas is unmounted
|
|
608
|
+
if (!_roots.has(canvas)) return null;
|
|
697
609
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
610
|
+
// Traverse fiber nodes for R3F root
|
|
611
|
+
const root = {
|
|
612
|
+
current: _roots.get(canvas).fiber.current
|
|
613
|
+
};
|
|
614
|
+
while (!((_root$current$child = root.current.child) != null && _root$current$child.stateNode)) {
|
|
615
|
+
var _root$current$child;
|
|
616
|
+
root.current = root.current.child;
|
|
702
617
|
}
|
|
703
618
|
|
|
704
|
-
|
|
619
|
+
// Return R3F instance from root
|
|
620
|
+
return reconciler.getPublicRootInstance(root);
|
|
621
|
+
},
|
|
622
|
+
async update(newElement) {
|
|
623
|
+
if (!_roots.has(canvas)) return console.warn('RTTR: attempted to update an unmounted root!');
|
|
624
|
+
await act(async () => _root.render(newElement));
|
|
705
625
|
},
|
|
706
|
-
toTree
|
|
626
|
+
toTree() {
|
|
707
627
|
return toTree(scene);
|
|
708
628
|
},
|
|
709
|
-
toGraph
|
|
629
|
+
toGraph() {
|
|
710
630
|
return toGraph(scene);
|
|
711
631
|
},
|
|
712
632
|
fireEvent: createEventFirer(act, _store),
|
|
713
|
-
|
|
633
|
+
async advanceFrames(frames, delta = 1) {
|
|
714
634
|
const state = _store.getState();
|
|
715
|
-
|
|
716
635
|
const storeSubscribers = state.internal.subscribers;
|
|
717
636
|
const promises = [];
|
|
718
|
-
|
|
637
|
+
for (const subscriber of storeSubscribers) {
|
|
719
638
|
for (let i = 0; i < frames; i++) {
|
|
720
639
|
if (is.arr(delta)) {
|
|
721
640
|
promises.push(new Promise(() => subscriber.ref.current(state, delta[i] || delta[-1])));
|
|
@@ -723,7 +642,7 @@ const create = async (element, options) => {
|
|
|
723
642
|
promises.push(new Promise(() => subscriber.ref.current(state, delta)));
|
|
724
643
|
}
|
|
725
644
|
}
|
|
726
|
-
}
|
|
645
|
+
}
|
|
727
646
|
Promise.all(promises);
|
|
728
647
|
}
|
|
729
648
|
};
|