vitest-native 0.8.0 → 0.10.0
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 +1063 -0
- package/README.md +47 -2
- package/dist/cli.cjs +642 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +638 -0
- package/dist/ecosystem-CO5vqExO.mjs +318 -0
- package/dist/ecosystem-IuZ-Gv0R.cjs +356 -0
- package/dist/errors-Dm5yLNTF.mjs +64 -0
- package/dist/errors-flXDIeWk.cjs +75 -0
- package/dist/errors.d.mts +46 -0
- package/dist/errors.mjs +78 -0
- package/dist/helpers.cjs +6 -23
- package/dist/helpers.d.cts +0 -6
- package/dist/helpers.d.mts +0 -6
- package/dist/helpers.mjs +6 -23
- package/dist/{index-vlK4zxuK.d.mts → index-BJL4cQ-l.d.cts} +22 -7
- package/dist/{index-YjjYELG7.d.cts → index-CvCU0cLl.d.mts} +20 -9
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +563 -232
- package/dist/jest-compat/interop.mjs +15 -0
- package/dist/jest-compat/setup.mjs +164 -5
- package/dist/matchers.cjs +16 -7
- package/dist/matchers.mjs +16 -7
- package/dist/native/boundary.mjs +108 -30
- package/dist/native/compile-cache.mjs +10 -5
- package/dist/native/explain.mjs +69 -0
- package/dist/native/hooks.mjs +151 -4
- package/dist/native/loader.mjs +61 -12
- package/dist/native/match.mjs +107 -8
- package/dist/native/module-reset.mjs +63 -0
- package/dist/native/registry.mjs +540 -0
- package/dist/native/reset.mjs +18 -12
- package/dist/native/resolve.d.mts +22 -0
- package/dist/native/resolve.mjs +21 -13
- package/dist/native/runner.mjs +34 -7
- package/dist/native/setup.mjs +19 -3
- package/dist/native/transform.mjs +195 -21
- package/dist/native/worker.mjs +69 -17
- package/dist/pool-Bcxp4Qrg.mjs +118 -0
- package/dist/pool-CFND7plG.cjs +122 -0
- package/dist/{preset-map-DCWaM08s.mjs → preset-map-BpDG_D5m.mjs} +1 -1
- package/dist/{preset-map-BY9zk9Pj.cjs → preset-map-DxilQ4pI.cjs} +1 -1
- package/dist/{presets-7eMfp7o2.cjs → presets-BGTqVH6C.cjs} +227 -52
- package/dist/{presets-23FJ76O4.mjs → presets-CK85x8ey.mjs} +222 -53
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/rntl-matchers.d.ts +35 -0
- package/dist/serializer.cjs +33 -3
- package/dist/serializer.mjs +33 -3
- package/dist/setup.mjs +544 -193
- package/docs/hot-default-design.md +129 -0
- package/docs/migrating-from-jest.md +43 -7
- package/docs/migrating-from-vitest-react-native.md +1 -1
- package/docs/release-readiness.md +24 -6
- package/docs/versioning.md +133 -0
- package/package.json +40 -38
- package/dist/index.cjs +0 -643
- package/dist/index.d.cts +0 -14
- package/dist/pool-B7LBfcMQ.mjs +0 -67
- package/dist/pool-p54QV1dQ.cjs +0 -69
- package/dist/presets.cjs +0 -17
- package/dist/presets.d.cts +0 -2
- package/dist/setup.cjs +0 -2514
- package/dist/setup.d.cts +0 -1
package/dist/setup.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __require } from "./chunk-CjcI7cDX.mjs";
|
|
2
|
-
import { t as AUTO_DETECT_PRESETS } from "./preset-map-
|
|
3
|
-
import {
|
|
2
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-BpDG_D5m.mjs";
|
|
3
|
+
import { D as buildPressableHostProps, E as createPressableMock, c as createTouchableOpacityMock, d as createFlatListMock, f as createScrollViewMock, i as createViewMock, l as createVirtualizedListMock, o as createTouchableWithoutFeedbackMock, p as createTextInputMock, s as createTouchableHighlightMock, t as presets_exports, u as createSectionListMock } from "./presets-CK85x8ey.mjs";
|
|
4
4
|
import { serializer } from "./serializer.mjs";
|
|
5
5
|
import { animatedMatchers } from "./matchers.mjs";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
@@ -565,71 +565,246 @@ function checkValidRanges(inputRange, outputRange) {
|
|
|
565
565
|
for (let i = 1; i < inputRange.length; ++i) if (!(inputRange[i] >= inputRange[i - 1])) throw new Error("inputRange must be monotonically non-decreasing " + String(inputRange));
|
|
566
566
|
if (inputRange.length !== outputRange.length) throw new Error("inputRange (" + inputRange.length + ") and outputRange (" + outputRange.length + ") must have the same length");
|
|
567
567
|
}
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
let _warnedGetValue = false;
|
|
569
|
+
function warnGetValueOnce() {
|
|
570
|
+
if (_warnedGetValue) return;
|
|
571
|
+
_warnedGetValue = true;
|
|
572
|
+
console.warn("[vitest-native] Animated node .getValue() is not a React Native API — real React Native exposes only __getValue(). This call works under engine:'mock' and throws under engine:'native'. Use __getValue() so the suite runs on both.");
|
|
573
|
+
}
|
|
574
|
+
var AnimatedNode = class {
|
|
570
575
|
_listeners = /* @__PURE__ */ new Map();
|
|
576
|
+
_children = /* @__PURE__ */ new Set();
|
|
571
577
|
_listenerIdCounter = 0;
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
578
|
+
/**
|
|
579
|
+
* NOT a React Native API — real React Native exposes only `__getValue()`.
|
|
580
|
+
*
|
|
581
|
+
* Kept because suites already use it, but it is a portability trap: the same call
|
|
582
|
+
* throws under `engine: 'native'`, where React Native itself is running. Warned once
|
|
583
|
+
* per process so the message is a signpost rather than noise, and recorded in
|
|
584
|
+
* crosscheck/known-differences.json.
|
|
585
|
+
*/
|
|
586
|
+
getValue() {
|
|
587
|
+
warnGetValueOnce();
|
|
588
|
+
return this.__getValue();
|
|
575
589
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
this._listeners.
|
|
590
|
+
/** Matches React Native's AnimatedNode.hasListeners(). */
|
|
591
|
+
hasListeners() {
|
|
592
|
+
return this._listeners.size > 0;
|
|
579
593
|
}
|
|
580
|
-
|
|
581
|
-
|
|
594
|
+
_attachToParents() {}
|
|
595
|
+
_detachFromParents() {}
|
|
596
|
+
_consumerCount() {
|
|
597
|
+
return this._listeners.size + this._children.size;
|
|
582
598
|
}
|
|
583
599
|
addListener(callback) {
|
|
584
600
|
const id = String(++this._listenerIdCounter);
|
|
585
601
|
this._listeners.set(id, callback);
|
|
602
|
+
if (this._consumerCount() === 1) this._attachToParents();
|
|
586
603
|
return id;
|
|
587
604
|
}
|
|
588
605
|
removeListener(id) {
|
|
589
|
-
this._listeners.delete(id);
|
|
606
|
+
if (this._listeners.delete(id) && this._consumerCount() === 0) this._detachFromParents();
|
|
590
607
|
}
|
|
591
608
|
removeAllListeners() {
|
|
609
|
+
const had = this._listeners.size > 0;
|
|
592
610
|
this._listeners.clear();
|
|
611
|
+
if (had && this._consumerCount() === 0) this._detachFromParents();
|
|
593
612
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
},
|
|
608
|
-
addListener: () => "0",
|
|
609
|
-
removeListener: () => {},
|
|
610
|
-
removeAllListeners: () => {},
|
|
611
|
-
stopAnimation: (cb) => cb?.(compute()),
|
|
612
|
-
resetAnimation: (cb) => cb?.(compute())
|
|
613
|
-
};
|
|
613
|
+
/** Graph edge: `fn` runs whenever this node's value may have changed. */
|
|
614
|
+
__addChild(fn) {
|
|
615
|
+
this._children.add(fn);
|
|
616
|
+
if (this._consumerCount() === 1) this._attachToParents();
|
|
617
|
+
}
|
|
618
|
+
__removeChild(fn) {
|
|
619
|
+
if (this._children.delete(fn) && this._consumerCount() === 0) this._detachFromParents();
|
|
620
|
+
}
|
|
621
|
+
/** Notify consumers with the node's CURRENT (offset-inclusive) value. */
|
|
622
|
+
_notify() {
|
|
623
|
+
if (this._listeners.size > 0) {
|
|
624
|
+
const value = this.__getValue();
|
|
625
|
+
this._listeners.forEach((fn) => fn({ value }));
|
|
614
626
|
}
|
|
615
|
-
|
|
627
|
+
this._children.forEach((fn) => fn());
|
|
628
|
+
}
|
|
629
|
+
interpolate(config) {
|
|
630
|
+
const { inputRange, outputRange } = config || {};
|
|
631
|
+
if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(Number(this.__getValue()) || 0);
|
|
632
|
+
return new AnimatedInterpolation(this, config);
|
|
633
|
+
}
|
|
634
|
+
toJSON() {
|
|
635
|
+
return this.__getValue();
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
var AnimatedValue = class extends AnimatedNode {
|
|
639
|
+
_value;
|
|
640
|
+
_offset = 0;
|
|
641
|
+
_runningAnimation = null;
|
|
642
|
+
_trackingNode = null;
|
|
643
|
+
_tracking = null;
|
|
644
|
+
constructor(value = 0) {
|
|
645
|
+
super();
|
|
646
|
+
this._value = value;
|
|
647
|
+
}
|
|
648
|
+
setValue(value) {
|
|
649
|
+
this._value = value;
|
|
650
|
+
this._notify();
|
|
651
|
+
}
|
|
652
|
+
__getValue() {
|
|
653
|
+
return this._value + this._offset;
|
|
654
|
+
}
|
|
655
|
+
setOffset(offset) {
|
|
656
|
+
this._offset = offset;
|
|
657
|
+
}
|
|
658
|
+
flattenOffset() {
|
|
659
|
+
this._value += this._offset;
|
|
660
|
+
this._offset = 0;
|
|
661
|
+
}
|
|
662
|
+
extractOffset() {
|
|
663
|
+
this._offset += this._value;
|
|
664
|
+
this._value = 0;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Drive this value from an animation object, as React Native's
|
|
668
|
+
* AnimatedValue.animate() does: stop whatever is running, then start the new one,
|
|
669
|
+
* feeding each frame back through setValue and reporting completion.
|
|
670
|
+
*
|
|
671
|
+
* KNOWN DIVERGENCE: this mock's own timing/spring/decay do NOT route through here.
|
|
672
|
+
* They apply their target value synchronously (see createAnimation), whereas real
|
|
673
|
+
* React Native's timing() calls value.animate(). So a suite spying on `animate` sees
|
|
674
|
+
* nothing under engine:'mock' and a call under engine:'native'. Wiring them through
|
|
675
|
+
* would mean reworking the synchronous-completion model a lot of tests depend on, so
|
|
676
|
+
* the divergence is recorded in crosscheck/known-differences.json instead. Pinned by
|
|
677
|
+
* a test, so changing it is a decision rather than an accident.
|
|
678
|
+
*
|
|
679
|
+
* React Native passes the previous animation and the node itself as the last two
|
|
680
|
+
* arguments; both are forwarded so a caller supplying a real Animation sees the same
|
|
681
|
+
* call shape.
|
|
682
|
+
*/
|
|
683
|
+
animate(animation, callback) {
|
|
684
|
+
const previous = this._runningAnimation;
|
|
685
|
+
this._runningAnimation?.stop?.();
|
|
686
|
+
this._runningAnimation = animation;
|
|
687
|
+
animation?.start?.(this.__getValue(), (value) => this.setValue(value), (result) => {
|
|
688
|
+
this._runningAnimation = null;
|
|
689
|
+
callback?.(result);
|
|
690
|
+
}, previous, this);
|
|
616
691
|
}
|
|
617
692
|
stopAnimation(callback) {
|
|
618
|
-
|
|
693
|
+
this._runningAnimation?.stop?.();
|
|
694
|
+
this._runningAnimation = null;
|
|
695
|
+
callback?.(this.__getValue());
|
|
619
696
|
}
|
|
620
697
|
resetAnimation(callback) {
|
|
621
|
-
|
|
698
|
+
this.stopAnimation(callback);
|
|
622
699
|
}
|
|
623
|
-
|
|
624
|
-
|
|
700
|
+
/**
|
|
701
|
+
* Matches React Native: detach the current tracking node, if any. Also clears the
|
|
702
|
+
* mock's own toValue-follows-value link, so a caller stopping tracking gets what the
|
|
703
|
+
* name promises regardless of which mechanism set it up.
|
|
704
|
+
*/
|
|
705
|
+
stopTracking() {
|
|
706
|
+
this._trackingNode?.__detach?.();
|
|
707
|
+
this._trackingNode = null;
|
|
708
|
+
stopTrackingLink(this);
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Matches React Native: replace any existing tracking and kick the new one once so it
|
|
712
|
+
* takes effect immediately rather than on the next frame.
|
|
713
|
+
*/
|
|
714
|
+
track(tracking) {
|
|
715
|
+
this.stopTracking();
|
|
716
|
+
this._trackingNode = tracking;
|
|
717
|
+
this._trackingNode?.update?.();
|
|
625
718
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
719
|
+
};
|
|
720
|
+
var AnimatedInterpolation = class extends AnimatedNode {
|
|
721
|
+
_parent;
|
|
722
|
+
_config;
|
|
723
|
+
_preparedString = null;
|
|
724
|
+
constructor(parent, config) {
|
|
725
|
+
super();
|
|
726
|
+
this._parent = parent;
|
|
727
|
+
this._config = config;
|
|
728
|
+
const { inputRange, outputRange } = config;
|
|
729
|
+
checkValidRanges(inputRange, outputRange);
|
|
730
|
+
if (typeof outputRange[0] === "string") this._preparedString = prepareStringInterpolation(outputRange);
|
|
731
|
+
}
|
|
732
|
+
_propagate = () => this._notify();
|
|
733
|
+
_attachToParents() {
|
|
734
|
+
this._parent.__addChild(this._propagate);
|
|
735
|
+
}
|
|
736
|
+
_detachFromParents() {
|
|
737
|
+
this._parent.__removeChild(this._propagate);
|
|
738
|
+
}
|
|
739
|
+
__getValue() {
|
|
740
|
+
const { inputRange, outputRange, extrapolate = "extend", extrapolateLeft, extrapolateRight, easing = IDENTITY_EASING } = this._config;
|
|
741
|
+
const input = Number(this._parent.__getValue());
|
|
742
|
+
if (this._preparedString) return interpolateString(this._preparedString, input, inputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
743
|
+
return interpolateNumeric(input, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
744
|
+
}
|
|
745
|
+
interpolate(config) {
|
|
746
|
+
if (this._preparedString) throw new Error("Cannot chain an interpolation off a string-valued interpolation");
|
|
747
|
+
return super.interpolate(config);
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
var AnimatedOp = class extends AnimatedNode {
|
|
751
|
+
_compute;
|
|
752
|
+
_parents;
|
|
753
|
+
_propagate = () => this._notify();
|
|
754
|
+
constructor(inputs, compute) {
|
|
755
|
+
super();
|
|
756
|
+
this._compute = compute;
|
|
757
|
+
this._parents = inputs.filter((i) => i instanceof AnimatedNode);
|
|
758
|
+
}
|
|
759
|
+
_attachToParents() {
|
|
760
|
+
for (const parent of this._parents) parent.__addChild(this._propagate);
|
|
761
|
+
}
|
|
762
|
+
_detachFromParents() {
|
|
763
|
+
for (const parent of this._parents) parent.__removeChild(this._propagate);
|
|
764
|
+
}
|
|
765
|
+
__getValue() {
|
|
766
|
+
return this._compute();
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
/** Numeric value of an operand that may be a node, a number, or junk (→ 0). */
|
|
770
|
+
function operandValue(v) {
|
|
771
|
+
if (v instanceof AnimatedNode) {
|
|
772
|
+
const n = Number(v.__getValue());
|
|
773
|
+
return Number.isNaN(n) ? 0 : n;
|
|
774
|
+
}
|
|
775
|
+
return typeof v === "number" ? v : 0;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* React Native exposes its AnimatedEvent class as `Animated.Event`, in its own words
|
|
779
|
+
* "so it can be used as a type for type checkers". That is what this covers: a named
|
|
780
|
+
* class consumers can reference and instanceof against.
|
|
781
|
+
*
|
|
782
|
+
* `Animated.event()` in this mock returns a plain spy function rather than an instance
|
|
783
|
+
* of this class, because suites assert on it with vi.fn matchers. So
|
|
784
|
+
* `Animated.event(...) instanceof Animated.Event` is false here and true under real
|
|
785
|
+
* React Native — a divergence the cross-check records rather than papers over.
|
|
786
|
+
*/
|
|
787
|
+
var AnimatedEvent = class {
|
|
788
|
+
_argMapping;
|
|
789
|
+
_listeners = [];
|
|
790
|
+
constructor(argMapping = [], config) {
|
|
791
|
+
this._argMapping = argMapping;
|
|
792
|
+
if (config?.listener) this._listeners.push(config.listener);
|
|
793
|
+
}
|
|
794
|
+
__addListener(callback) {
|
|
795
|
+
this._listeners.push(callback);
|
|
796
|
+
}
|
|
797
|
+
__removeListener(callback) {
|
|
798
|
+
this._listeners = this._listeners.filter((l) => l !== callback);
|
|
799
|
+
}
|
|
800
|
+
__attach() {}
|
|
801
|
+
__detach() {}
|
|
629
802
|
};
|
|
630
803
|
var AnimatedValueXY = class {
|
|
631
804
|
x;
|
|
632
805
|
y;
|
|
806
|
+
_listenerIdCounter = 0;
|
|
807
|
+
_joint = /* @__PURE__ */ new Map();
|
|
633
808
|
constructor(value) {
|
|
634
809
|
this.x = new AnimatedValue(value?.x ?? 0);
|
|
635
810
|
this.y = new AnimatedValue(value?.y ?? 0);
|
|
@@ -638,31 +813,66 @@ var AnimatedValueXY = class {
|
|
|
638
813
|
this.x.setValue(value.x);
|
|
639
814
|
this.y.setValue(value.y);
|
|
640
815
|
}
|
|
641
|
-
setOffset(
|
|
642
|
-
|
|
643
|
-
|
|
816
|
+
setOffset(offset) {
|
|
817
|
+
this.x.setOffset(offset.x);
|
|
818
|
+
this.y.setOffset(offset.y);
|
|
819
|
+
}
|
|
820
|
+
flattenOffset() {
|
|
821
|
+
this.x.flattenOffset();
|
|
822
|
+
this.y.flattenOffset();
|
|
823
|
+
}
|
|
824
|
+
extractOffset() {
|
|
825
|
+
this.x.extractOffset();
|
|
826
|
+
this.y.extractOffset();
|
|
827
|
+
}
|
|
828
|
+
__getValue() {
|
|
829
|
+
return {
|
|
830
|
+
x: this.x.__getValue(),
|
|
831
|
+
y: this.y.__getValue()
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
getValue() {
|
|
835
|
+
return this.__getValue();
|
|
836
|
+
}
|
|
644
837
|
stopAnimation(callback) {
|
|
645
|
-
callback?.(
|
|
646
|
-
x: this.x.getValue(),
|
|
647
|
-
y: this.y.getValue()
|
|
648
|
-
});
|
|
838
|
+
callback?.(this.__getValue());
|
|
649
839
|
}
|
|
650
840
|
resetAnimation(callback) {
|
|
651
|
-
callback?.(
|
|
652
|
-
x: this.x.getValue(),
|
|
653
|
-
y: this.y.getValue()
|
|
654
|
-
});
|
|
841
|
+
callback?.(this.__getValue());
|
|
655
842
|
}
|
|
656
|
-
addListener(
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
843
|
+
addListener(callback) {
|
|
844
|
+
const emit = () => callback(this.__getValue());
|
|
845
|
+
const id = String(++this._listenerIdCounter);
|
|
846
|
+
const pair = {
|
|
847
|
+
x: this.x.addListener(emit),
|
|
848
|
+
y: this.y.addListener(emit)
|
|
660
849
|
};
|
|
850
|
+
this._joint.set(id, pair);
|
|
851
|
+
return pair;
|
|
661
852
|
}
|
|
662
853
|
removeListener(id) {
|
|
663
854
|
this.x.removeListener(id.x);
|
|
664
855
|
this.y.removeListener(id.y);
|
|
665
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* ValueXY composes two AnimatedValues rather than extending AnimatedNode, so it does
|
|
859
|
+
* not inherit these; React Native's does expose them.
|
|
860
|
+
*/
|
|
861
|
+
hasListeners() {
|
|
862
|
+
return this.x.hasListeners() || this.y.hasListeners();
|
|
863
|
+
}
|
|
864
|
+
/** React Native inherits this from AnimatedNode, where it returns __getValue(). */
|
|
865
|
+
toJSON() {
|
|
866
|
+
return {
|
|
867
|
+
x: this.x.__getValue(),
|
|
868
|
+
y: this.y.__getValue()
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
removeAllListeners() {
|
|
872
|
+
this.x.removeAllListeners();
|
|
873
|
+
this.y.removeAllListeners();
|
|
874
|
+
this._joint.clear();
|
|
875
|
+
}
|
|
666
876
|
getLayout() {
|
|
667
877
|
return {
|
|
668
878
|
left: this.x,
|
|
@@ -760,26 +970,31 @@ function parseColorString(color) {
|
|
|
760
970
|
1
|
|
761
971
|
];
|
|
762
972
|
}
|
|
763
|
-
var AnimatedColor = class {
|
|
973
|
+
var AnimatedColor = class extends AnimatedNode {
|
|
764
974
|
r;
|
|
765
975
|
g;
|
|
766
976
|
b;
|
|
767
977
|
a;
|
|
768
|
-
|
|
769
|
-
|
|
978
|
+
stopAnimation(callback) {
|
|
979
|
+
callback?.(this.__getValue());
|
|
980
|
+
}
|
|
981
|
+
resetAnimation(callback) {
|
|
982
|
+
this.stopAnimation(callback);
|
|
983
|
+
}
|
|
770
984
|
constructor(color) {
|
|
985
|
+
super();
|
|
771
986
|
if (typeof color === "string") {
|
|
772
987
|
const [r, g, b, a] = parseColorString(color);
|
|
773
988
|
this.r = new AnimatedValue(r);
|
|
774
989
|
this.g = new AnimatedValue(g);
|
|
775
990
|
this.b = new AnimatedValue(b);
|
|
776
991
|
this.a = new AnimatedValue(a);
|
|
777
|
-
} else if (color && typeof color === "object"
|
|
992
|
+
} else if (color && typeof color === "object" && color.r instanceof AnimatedValue) {
|
|
778
993
|
this.r = color.r;
|
|
779
994
|
this.g = color.g;
|
|
780
995
|
this.b = color.b;
|
|
781
996
|
this.a = color.a;
|
|
782
|
-
} else if (typeof color.r === "number") {
|
|
997
|
+
} else if (color && typeof color === "object" && typeof color.r === "number") {
|
|
783
998
|
this.r = new AnimatedValue(color.r);
|
|
784
999
|
this.g = new AnimatedValue(color.g ?? 0);
|
|
785
1000
|
this.b = new AnimatedValue(color.b ?? 0);
|
|
@@ -790,12 +1005,12 @@ var AnimatedColor = class {
|
|
|
790
1005
|
this.b = new AnimatedValue(0);
|
|
791
1006
|
this.a = new AnimatedValue(1);
|
|
792
1007
|
}
|
|
793
|
-
|
|
794
|
-
this.r
|
|
795
|
-
this.g
|
|
796
|
-
this.b
|
|
797
|
-
this.a
|
|
798
|
-
|
|
1008
|
+
for (const channel of [
|
|
1009
|
+
this.r,
|
|
1010
|
+
this.g,
|
|
1011
|
+
this.b,
|
|
1012
|
+
this.a
|
|
1013
|
+
]) channel.__addChild(() => this._notify());
|
|
799
1014
|
}
|
|
800
1015
|
setValue(value) {
|
|
801
1016
|
if (typeof value === "string") {
|
|
@@ -810,31 +1025,12 @@ var AnimatedColor = class {
|
|
|
810
1025
|
this.b.setValue(value.b ?? 0);
|
|
811
1026
|
this.a.setValue(value.a ?? 1);
|
|
812
1027
|
}
|
|
813
|
-
const colorStr = this.__getValue();
|
|
814
|
-
this._listeners.forEach((fn) => fn({ value: colorStr }));
|
|
815
1028
|
}
|
|
816
1029
|
__getValue() {
|
|
817
1030
|
return `rgba(${Math.round(this.r.getValue())}, ${Math.round(this.g.getValue())}, ${Math.round(this.b.getValue())}, ${this.a.getValue()})`;
|
|
818
1031
|
}
|
|
819
|
-
addListener(callback) {
|
|
820
|
-
const id = String(++this._listenerIdCounter);
|
|
821
|
-
this._listeners.set(id, callback);
|
|
822
|
-
return id;
|
|
823
|
-
}
|
|
824
|
-
removeListener(id) {
|
|
825
|
-
this._listeners.delete(id);
|
|
826
|
-
}
|
|
827
|
-
removeAllListeners() {
|
|
828
|
-
this._listeners.clear();
|
|
829
|
-
}
|
|
830
1032
|
setOffset(_offset) {}
|
|
831
1033
|
flattenOffset() {}
|
|
832
|
-
stopAnimation(callback) {
|
|
833
|
-
callback?.(this.__getValue());
|
|
834
|
-
}
|
|
835
|
-
resetAnimation(callback) {
|
|
836
|
-
callback?.(this.__getValue());
|
|
837
|
-
}
|
|
838
1034
|
};
|
|
839
1035
|
function createAnimation(onStart) {
|
|
840
1036
|
return {
|
|
@@ -849,9 +1045,9 @@ function createAnimation(onStart) {
|
|
|
849
1045
|
};
|
|
850
1046
|
}
|
|
851
1047
|
function resolveAnimatedLeaf(v) {
|
|
852
|
-
if (v instanceof
|
|
1048
|
+
if (v instanceof AnimatedNode) return v.__getValue();
|
|
853
1049
|
if (v && typeof v === "object" && typeof v.__getValue === "function") return v.__getValue();
|
|
854
|
-
if (v && typeof v === "object" && typeof v.getValue === "function") return v.getValue();
|
|
1050
|
+
if (v && typeof v === "object" && !Array.isArray(v) && typeof v.getValue === "function") return v.getValue();
|
|
855
1051
|
return v;
|
|
856
1052
|
}
|
|
857
1053
|
function resolveAnimatedStyle(style) {
|
|
@@ -862,16 +1058,40 @@ function resolveAnimatedStyle(style) {
|
|
|
862
1058
|
const out = {};
|
|
863
1059
|
for (const key of Object.keys(style)) {
|
|
864
1060
|
const val = style[key];
|
|
865
|
-
if (key === "transform" && Array.isArray(val)) out[key] = val.map((t) => t && typeof t === "object" && !(t instanceof
|
|
1061
|
+
if (key === "transform" && Array.isArray(val)) out[key] = val.map((t) => t && typeof t === "object" && !(t instanceof AnimatedNode) ? Object.fromEntries(Object.keys(t).map((tk) => [tk, resolveAnimatedLeaf(t[tk])])) : resolveAnimatedLeaf(t));
|
|
866
1062
|
else out[key] = resolveAnimatedLeaf(val);
|
|
867
1063
|
}
|
|
868
1064
|
return out;
|
|
869
1065
|
}
|
|
870
1066
|
return style;
|
|
871
1067
|
}
|
|
1068
|
+
function collectAnimatedNodes(style, out) {
|
|
1069
|
+
if (style instanceof AnimatedNode) {
|
|
1070
|
+
out.add(style);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
if (Array.isArray(style)) {
|
|
1074
|
+
for (const s of style) collectAnimatedNodes(s, out);
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
if (style && typeof style === "object") for (const key of Object.keys(style)) collectAnimatedNodes(style[key], out);
|
|
1078
|
+
}
|
|
1079
|
+
function useAnimatedStyleSubscription(style) {
|
|
1080
|
+
const [, force] = React.useReducer((n) => n + 1, 0);
|
|
1081
|
+
React.useEffect(() => {
|
|
1082
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
1083
|
+
collectAnimatedNodes(style, nodes);
|
|
1084
|
+
if (nodes.size === 0) return void 0;
|
|
1085
|
+
for (const node of nodes) node.__addChild(force);
|
|
1086
|
+
return () => {
|
|
1087
|
+
for (const node of nodes) node.__removeChild(force);
|
|
1088
|
+
};
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
872
1091
|
function createAnimatedWrapper(displayName) {
|
|
873
1092
|
const hostName = displayName.replace(/^Animated\./, "");
|
|
874
1093
|
const Component = React.forwardRef((props, ref) => {
|
|
1094
|
+
useAnimatedStyleSubscription(props?.style);
|
|
875
1095
|
if (props && props.style !== void 0) {
|
|
876
1096
|
const { style, ...rest } = props;
|
|
877
1097
|
return React.createElement(hostName, {
|
|
@@ -888,28 +1108,55 @@ function createAnimatedWrapper(displayName) {
|
|
|
888
1108
|
Component.displayName = displayName;
|
|
889
1109
|
return Component;
|
|
890
1110
|
}
|
|
891
|
-
function
|
|
1111
|
+
function stopTrackingLink(value) {
|
|
892
1112
|
if (value._tracking) {
|
|
893
|
-
value._tracking.source.
|
|
1113
|
+
value._tracking.source.__removeChild(value._tracking.child);
|
|
894
1114
|
value._tracking = null;
|
|
895
1115
|
}
|
|
896
1116
|
}
|
|
897
1117
|
function startTracking(value, toValue) {
|
|
898
|
-
|
|
1118
|
+
stopTrackingLink(value);
|
|
899
1119
|
if (toValue instanceof AnimatedValue) {
|
|
900
1120
|
value.setValue(toValue.getValue());
|
|
1121
|
+
const child = () => value.setValue(toValue.__getValue());
|
|
1122
|
+
toValue.__addChild(child);
|
|
901
1123
|
value._tracking = {
|
|
902
1124
|
source: toValue,
|
|
903
|
-
|
|
904
|
-
value.setValue(v);
|
|
905
|
-
})
|
|
1125
|
+
child
|
|
906
1126
|
};
|
|
907
1127
|
} else value.setValue(toValue);
|
|
908
1128
|
}
|
|
1129
|
+
var AnimatedDiffClamp = class extends AnimatedNode {
|
|
1130
|
+
_current;
|
|
1131
|
+
constructor(a, min, max) {
|
|
1132
|
+
super();
|
|
1133
|
+
let lastInput = operandValue(a);
|
|
1134
|
+
this._current = Math.min(Math.max(lastInput, min), max);
|
|
1135
|
+
if (a instanceof AnimatedNode) a.__addChild(() => {
|
|
1136
|
+
const value = Number(a.__getValue());
|
|
1137
|
+
const diff = value - lastInput;
|
|
1138
|
+
lastInput = value;
|
|
1139
|
+
this._current = Math.min(Math.max(this._current + diff, min), max);
|
|
1140
|
+
this._notify();
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
__getValue() {
|
|
1144
|
+
return this._current;
|
|
1145
|
+
}
|
|
1146
|
+
};
|
|
909
1147
|
function createAnimatedMock() {
|
|
910
1148
|
return {
|
|
911
1149
|
Value: AnimatedValue,
|
|
912
1150
|
ValueXY: AnimatedValueXY,
|
|
1151
|
+
Node: AnimatedNode,
|
|
1152
|
+
Interpolation: AnimatedInterpolation,
|
|
1153
|
+
Event: AnimatedEvent,
|
|
1154
|
+
/**
|
|
1155
|
+
* React Native attaches a native event handler to a view and hands back a detach
|
|
1156
|
+
* function. There is no native side here, so this records nothing and returns the
|
|
1157
|
+
* same shape — enough for a caller to attach and detach without throwing.
|
|
1158
|
+
*/
|
|
1159
|
+
attachNativeEvent: vi.fn((_viewRef, _eventName, _argMapping) => ({ detach() {} })),
|
|
913
1160
|
Color: AnimatedColor,
|
|
914
1161
|
timing: vi.fn((value, config) => {
|
|
915
1162
|
return createAnimation(() => {
|
|
@@ -1070,37 +1317,15 @@ function createAnimatedMock() {
|
|
|
1070
1317
|
delay: vi.fn((_time) => {
|
|
1071
1318
|
return createAnimation();
|
|
1072
1319
|
}),
|
|
1073
|
-
add: vi.fn((a, b) =>
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
divide: vi.fn((a, b) => {
|
|
1083
|
-
const aVal = a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0;
|
|
1084
|
-
const bVal = b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0;
|
|
1085
|
-
return new AnimatedValue(bVal === 0 ? 0 : aVal / bVal);
|
|
1086
|
-
}),
|
|
1087
|
-
modulo: vi.fn((a, modulus) => {
|
|
1088
|
-
return new AnimatedValue(((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) % modulus + modulus) % modulus);
|
|
1089
|
-
}),
|
|
1090
|
-
diffClamp: vi.fn((a, min, max) => {
|
|
1091
|
-
const result = new AnimatedValue(Math.min(Math.max(a instanceof AnimatedValue ? a.getValue() : 0, min), max));
|
|
1092
|
-
if (a instanceof AnimatedValue) {
|
|
1093
|
-
let lastInput = a.getValue();
|
|
1094
|
-
let current = result.getValue();
|
|
1095
|
-
a.addListener(({ value }) => {
|
|
1096
|
-
const diff = value - lastInput;
|
|
1097
|
-
lastInput = value;
|
|
1098
|
-
current = Math.min(Math.max(current + diff, min), max);
|
|
1099
|
-
result.setValue(current);
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
return result;
|
|
1103
|
-
}),
|
|
1320
|
+
add: vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) + operandValue(b))),
|
|
1321
|
+
subtract: vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) - operandValue(b))),
|
|
1322
|
+
multiply: vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) * operandValue(b))),
|
|
1323
|
+
divide: vi.fn((a, b) => new AnimatedOp([a, b], () => {
|
|
1324
|
+
const divisor = operandValue(b);
|
|
1325
|
+
return divisor === 0 ? 0 : operandValue(a) / divisor;
|
|
1326
|
+
})),
|
|
1327
|
+
modulo: vi.fn((a, modulus) => new AnimatedOp([a], () => (operandValue(a) % modulus + modulus) % modulus)),
|
|
1328
|
+
diffClamp: vi.fn((a, min, max) => new AnimatedDiffClamp(a, min, max)),
|
|
1104
1329
|
event: vi.fn((argMapping, config) => {
|
|
1105
1330
|
const handler = vi.fn((...args) => {
|
|
1106
1331
|
argMapping.forEach((mapping, index) => {
|
|
@@ -1129,6 +1354,15 @@ function createAnimatedMock() {
|
|
|
1129
1354
|
unforkEvent: vi.fn(),
|
|
1130
1355
|
createAnimatedComponent: vi.fn((component) => {
|
|
1131
1356
|
const Wrapper = React.forwardRef((props, ref) => {
|
|
1357
|
+
useAnimatedStyleSubscription(props?.style);
|
|
1358
|
+
if (props && props.style !== void 0) {
|
|
1359
|
+
const { style, ...rest } = props;
|
|
1360
|
+
return React.createElement(component, {
|
|
1361
|
+
...rest,
|
|
1362
|
+
style: resolveAnimatedStyle(style),
|
|
1363
|
+
ref
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1132
1366
|
return React.createElement(component, {
|
|
1133
1367
|
...props,
|
|
1134
1368
|
ref
|
|
@@ -1167,10 +1401,19 @@ function createLinkingMock() {
|
|
|
1167
1401
|
}
|
|
1168
1402
|
//#endregion
|
|
1169
1403
|
//#region src/mocks/apis/AppState.ts
|
|
1404
|
+
/**
|
|
1405
|
+
* Resting app state, written once — see Keyboard.ts for why not twice.
|
|
1406
|
+
*
|
|
1407
|
+
* "active" (a foregrounded app) is the mock's choice, not something real React
|
|
1408
|
+
* Native reports under Node: there it reads from a native module that only exists on
|
|
1409
|
+
* a device, so it is undefined, as it also is under Jest with React Native's own
|
|
1410
|
+
* preset. Recorded in crosscheck/known-differences.json.
|
|
1411
|
+
*/
|
|
1412
|
+
const RESTING_STATE = "active";
|
|
1170
1413
|
function createAppStateMock() {
|
|
1171
1414
|
const listeners = /* @__PURE__ */ new Map();
|
|
1172
1415
|
const mock = {
|
|
1173
|
-
currentState:
|
|
1416
|
+
currentState: RESTING_STATE,
|
|
1174
1417
|
isAvailable: true,
|
|
1175
1418
|
addEventListener: vi.fn((type, handler) => {
|
|
1176
1419
|
if (!listeners.has(type)) listeners.set(type, /* @__PURE__ */ new Set());
|
|
@@ -1182,7 +1425,7 @@ function createAppStateMock() {
|
|
|
1182
1425
|
listeners.get("change")?.forEach((fn) => fn(state));
|
|
1183
1426
|
},
|
|
1184
1427
|
_reset: () => {
|
|
1185
|
-
mock.currentState =
|
|
1428
|
+
mock.currentState = RESTING_STATE;
|
|
1186
1429
|
listeners.clear();
|
|
1187
1430
|
}
|
|
1188
1431
|
};
|
|
@@ -1190,15 +1433,28 @@ function createAppStateMock() {
|
|
|
1190
1433
|
}
|
|
1191
1434
|
//#endregion
|
|
1192
1435
|
//#region src/mocks/apis/Keyboard.ts
|
|
1436
|
+
/**
|
|
1437
|
+
* The keyboard's resting state, written once.
|
|
1438
|
+
*
|
|
1439
|
+
* It used to be repeated at construction and in dismiss/_hide/_reset, which is the
|
|
1440
|
+
* shape that lets a wrong initial value pass every gate: suites call `_reset()`
|
|
1441
|
+
* before asserting, so they observe the reset path and never the value the mock is
|
|
1442
|
+
* actually built with. Changing the construction-time values alone was caught by
|
|
1443
|
+
* neither the mock suite nor the cross-check. One constant, so the two cannot drift.
|
|
1444
|
+
*/
|
|
1445
|
+
const RESTING$1 = {
|
|
1446
|
+
visible: false,
|
|
1447
|
+
keyboardHeight: 0
|
|
1448
|
+
};
|
|
1193
1449
|
function createKeyboardMock() {
|
|
1194
|
-
let visible =
|
|
1195
|
-
|
|
1450
|
+
let { visible, keyboardHeight } = RESTING$1;
|
|
1451
|
+
const rest = () => {
|
|
1452
|
+
visible = RESTING$1.visible;
|
|
1453
|
+
keyboardHeight = RESTING$1.keyboardHeight;
|
|
1454
|
+
};
|
|
1196
1455
|
const listeners = /* @__PURE__ */ new Map();
|
|
1197
1456
|
return {
|
|
1198
|
-
dismiss: vi.fn(
|
|
1199
|
-
visible = false;
|
|
1200
|
-
keyboardHeight = 0;
|
|
1201
|
-
}),
|
|
1457
|
+
dismiss: vi.fn(rest),
|
|
1202
1458
|
addListener: vi.fn((event, handler) => {
|
|
1203
1459
|
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
1204
1460
|
listeners.get(event).add(handler);
|
|
@@ -1230,13 +1486,11 @@ function createKeyboardMock() {
|
|
|
1230
1486
|
} }));
|
|
1231
1487
|
},
|
|
1232
1488
|
_hide: () => {
|
|
1233
|
-
|
|
1234
|
-
keyboardHeight = 0;
|
|
1489
|
+
rest();
|
|
1235
1490
|
listeners.get("keyboardDidHide")?.forEach((fn) => fn({}));
|
|
1236
1491
|
},
|
|
1237
1492
|
_reset: () => {
|
|
1238
|
-
|
|
1239
|
-
keyboardHeight = 0;
|
|
1493
|
+
rest();
|
|
1240
1494
|
listeners.clear();
|
|
1241
1495
|
}
|
|
1242
1496
|
};
|
|
@@ -1326,8 +1580,10 @@ function createPermissionsAndroidMock() {
|
|
|
1326
1580
|
}
|
|
1327
1581
|
//#endregion
|
|
1328
1582
|
//#region src/mocks/apis/Appearance.ts
|
|
1583
|
+
/** Resting colour scheme, written once — see Keyboard.ts for why not twice. */
|
|
1584
|
+
const RESTING_SCHEME = "light";
|
|
1329
1585
|
function createAppearanceMock() {
|
|
1330
|
-
let colorScheme =
|
|
1586
|
+
let colorScheme = RESTING_SCHEME;
|
|
1331
1587
|
const listeners = /* @__PURE__ */ new Set();
|
|
1332
1588
|
return {
|
|
1333
1589
|
getColorScheme: vi.fn(() => colorScheme),
|
|
@@ -1342,7 +1598,7 @@ function createAppearanceMock() {
|
|
|
1342
1598
|
} };
|
|
1343
1599
|
}),
|
|
1344
1600
|
_reset: () => {
|
|
1345
|
-
colorScheme =
|
|
1601
|
+
colorScheme = RESTING_SCHEME;
|
|
1346
1602
|
listeners.clear();
|
|
1347
1603
|
}
|
|
1348
1604
|
};
|
|
@@ -1365,8 +1621,50 @@ function createPixelRatioMock(getDimensions) {
|
|
|
1365
1621
|
//#endregion
|
|
1366
1622
|
//#region src/mocks/apis/LayoutAnimation.ts
|
|
1367
1623
|
function createLayoutAnimationMock() {
|
|
1624
|
+
const configureNext = vi.fn();
|
|
1625
|
+
const presets = {
|
|
1626
|
+
easeInEaseOut: {
|
|
1627
|
+
duration: 300,
|
|
1628
|
+
create: {
|
|
1629
|
+
type: "easeInEaseOut",
|
|
1630
|
+
property: "opacity"
|
|
1631
|
+
},
|
|
1632
|
+
update: { type: "easeInEaseOut" },
|
|
1633
|
+
delete: {
|
|
1634
|
+
type: "easeInEaseOut",
|
|
1635
|
+
property: "opacity"
|
|
1636
|
+
}
|
|
1637
|
+
},
|
|
1638
|
+
linear: {
|
|
1639
|
+
duration: 500,
|
|
1640
|
+
create: {
|
|
1641
|
+
type: "linear",
|
|
1642
|
+
property: "opacity"
|
|
1643
|
+
},
|
|
1644
|
+
update: { type: "linear" },
|
|
1645
|
+
delete: {
|
|
1646
|
+
type: "linear",
|
|
1647
|
+
property: "opacity"
|
|
1648
|
+
}
|
|
1649
|
+
},
|
|
1650
|
+
spring: {
|
|
1651
|
+
duration: 700,
|
|
1652
|
+
create: {
|
|
1653
|
+
type: "linear",
|
|
1654
|
+
property: "opacity"
|
|
1655
|
+
},
|
|
1656
|
+
update: {
|
|
1657
|
+
type: "spring",
|
|
1658
|
+
springDamping: .4
|
|
1659
|
+
},
|
|
1660
|
+
delete: {
|
|
1661
|
+
type: "linear",
|
|
1662
|
+
property: "opacity"
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1368
1666
|
return {
|
|
1369
|
-
configureNext
|
|
1667
|
+
configureNext,
|
|
1370
1668
|
create: vi.fn(() => ({
|
|
1371
1669
|
duration: 300,
|
|
1372
1670
|
create: {
|
|
@@ -1392,47 +1690,14 @@ function createLayoutAnimationMock() {
|
|
|
1392
1690
|
scaleY: "scaleY",
|
|
1393
1691
|
scaleXY: "scaleXY"
|
|
1394
1692
|
},
|
|
1395
|
-
Presets:
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
delete: {
|
|
1404
|
-
type: "easeInEaseOut",
|
|
1405
|
-
property: "opacity"
|
|
1406
|
-
}
|
|
1407
|
-
},
|
|
1408
|
-
linear: {
|
|
1409
|
-
duration: 500,
|
|
1410
|
-
create: {
|
|
1411
|
-
type: "linear",
|
|
1412
|
-
property: "opacity"
|
|
1413
|
-
},
|
|
1414
|
-
update: { type: "linear" },
|
|
1415
|
-
delete: {
|
|
1416
|
-
type: "linear",
|
|
1417
|
-
property: "opacity"
|
|
1418
|
-
}
|
|
1419
|
-
},
|
|
1420
|
-
spring: {
|
|
1421
|
-
duration: 700,
|
|
1422
|
-
create: {
|
|
1423
|
-
type: "linear",
|
|
1424
|
-
property: "opacity"
|
|
1425
|
-
},
|
|
1426
|
-
update: {
|
|
1427
|
-
type: "spring",
|
|
1428
|
-
springDamping: .4
|
|
1429
|
-
},
|
|
1430
|
-
delete: {
|
|
1431
|
-
type: "linear",
|
|
1432
|
-
property: "opacity"
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1693
|
+
Presets: presets,
|
|
1694
|
+
easeInEaseOut: (onAnimationDidEnd) => configureNext(presets.easeInEaseOut, onAnimationDidEnd),
|
|
1695
|
+
linear: (onAnimationDidEnd) => configureNext(presets.linear, onAnimationDidEnd),
|
|
1696
|
+
spring: (onAnimationDidEnd) => configureNext(presets.spring, onAnimationDidEnd),
|
|
1697
|
+
checkConfig: vi.fn(() => {
|
|
1698
|
+
console.error("LayoutAnimation.checkConfig(...) has been disabled.");
|
|
1699
|
+
}),
|
|
1700
|
+
setEnabled: vi.fn()
|
|
1436
1701
|
};
|
|
1437
1702
|
}
|
|
1438
1703
|
//#endregion
|
|
@@ -1655,10 +1920,14 @@ function createEasingMock() {
|
|
|
1655
1920
|
}
|
|
1656
1921
|
//#endregion
|
|
1657
1922
|
//#region src/mocks/apis/I18nManager.ts
|
|
1923
|
+
/** Resting layout direction, written once — see Keyboard.ts for why not twice. */
|
|
1924
|
+
const RESTING = {
|
|
1925
|
+
isRTL: false,
|
|
1926
|
+
doLeftAndRightSwapInRTL: true
|
|
1927
|
+
};
|
|
1658
1928
|
function createI18nManagerMock() {
|
|
1659
1929
|
const mock = {
|
|
1660
|
-
|
|
1661
|
-
doLeftAndRightSwapInRTL: true,
|
|
1930
|
+
...RESTING,
|
|
1662
1931
|
allowRTL: vi.fn((_allow) => {}),
|
|
1663
1932
|
forceRTL: vi.fn((force) => {
|
|
1664
1933
|
mock.isRTL = force;
|
|
@@ -1671,8 +1940,7 @@ function createI18nManagerMock() {
|
|
|
1671
1940
|
doLeftAndRightSwapInRTL: mock.doLeftAndRightSwapInRTL
|
|
1672
1941
|
})),
|
|
1673
1942
|
_reset: () => {
|
|
1674
|
-
mock
|
|
1675
|
-
mock.doLeftAndRightSwapInRTL = true;
|
|
1943
|
+
Object.assign(mock, RESTING);
|
|
1676
1944
|
}
|
|
1677
1945
|
};
|
|
1678
1946
|
return mock;
|
|
@@ -2030,7 +2298,6 @@ function createProcessColorMock() {
|
|
|
2030
2298
|
return (Math.round(parseFloat(a) * 255) << 24) + (r << 16) + (g << 8) + b >>> 0;
|
|
2031
2299
|
}
|
|
2032
2300
|
}
|
|
2033
|
-
return 4278190080;
|
|
2034
2301
|
});
|
|
2035
2302
|
}
|
|
2036
2303
|
function createFindNodeHandleMock() {
|
|
@@ -2100,17 +2367,23 @@ function createTouchableMock() {
|
|
|
2100
2367
|
}
|
|
2101
2368
|
function createUseAnimatedValueMock() {
|
|
2102
2369
|
return vi.fn((initialValue) => {
|
|
2103
|
-
|
|
2370
|
+
const ref = React.useRef(null);
|
|
2371
|
+
if (ref.current == null) ref.current = new AnimatedValue(initialValue);
|
|
2372
|
+
return ref.current;
|
|
2104
2373
|
});
|
|
2105
2374
|
}
|
|
2106
2375
|
function createUseAnimatedValueXYMock() {
|
|
2107
2376
|
return vi.fn((initialValue) => {
|
|
2108
|
-
|
|
2377
|
+
const ref = React.useRef(null);
|
|
2378
|
+
if (ref.current == null) ref.current = new AnimatedValueXY(initialValue);
|
|
2379
|
+
return ref.current;
|
|
2109
2380
|
});
|
|
2110
2381
|
}
|
|
2111
2382
|
function createUseAnimatedColorMock() {
|
|
2112
2383
|
return vi.fn((initialValue) => {
|
|
2113
|
-
|
|
2384
|
+
const ref = React.useRef(null);
|
|
2385
|
+
if (ref.current == null) ref.current = new AnimatedColor(initialValue);
|
|
2386
|
+
return ref.current;
|
|
2114
2387
|
});
|
|
2115
2388
|
}
|
|
2116
2389
|
function buildReactNativeMock(platform = "ios") {
|
|
@@ -2278,7 +2551,54 @@ function buildReactNativeMock(platform = "ios") {
|
|
|
2278
2551
|
const VIRTUAL_RN_PATH = "\0vitest-native:react-native";
|
|
2279
2552
|
let originalResolveFilename = null;
|
|
2280
2553
|
let installed = false;
|
|
2554
|
+
let rnMock$1 = null;
|
|
2281
2555
|
const presetRedirects = /* @__PURE__ */ new Map();
|
|
2556
|
+
const presetMocks = /* @__PURE__ */ new Map();
|
|
2557
|
+
const leafModulePaths = /* @__PURE__ */ new Set();
|
|
2558
|
+
/**
|
|
2559
|
+
* The leaf module name a subpath require points at ("pkg/lib/Swipeable" or
|
|
2560
|
+
* ".../Platform.ios.js" → "Platform"). Mirrors native/match.mjs.
|
|
2561
|
+
*/
|
|
2562
|
+
function subpathLeafOf(request) {
|
|
2563
|
+
const base = request.split("/").pop();
|
|
2564
|
+
if (!base) return null;
|
|
2565
|
+
return base.split(".")[0] || null;
|
|
2566
|
+
}
|
|
2567
|
+
/**
|
|
2568
|
+
* Wrap a leaf export in Babel-CJS interop shape: the real compiled deep entry
|
|
2569
|
+
* exports `{ __esModule: true, default: X }`. A live Proxy keeps
|
|
2570
|
+
* direct-property consumers (`require('pkg/Sub').OS`) working too.
|
|
2571
|
+
*/
|
|
2572
|
+
function withDefaultInterop(value) {
|
|
2573
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return {
|
|
2574
|
+
__esModule: true,
|
|
2575
|
+
default: value
|
|
2576
|
+
};
|
|
2577
|
+
return new Proxy(value, {
|
|
2578
|
+
get: (t, p, r) => p === "default" ? t : p === "__esModule" ? true : Reflect.get(t, p, r),
|
|
2579
|
+
has: (t, p) => p === "default" || p === "__esModule" || Reflect.has(t, p)
|
|
2580
|
+
});
|
|
2581
|
+
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Get or create a synthetic Module._cache entry for a subpath require whose
|
|
2584
|
+
* leaf name matches an export on the mock. Returns its virtual path, or null
|
|
2585
|
+
* when the leaf has no matching export (caller falls back to the root mock).
|
|
2586
|
+
*/
|
|
2587
|
+
function leafModulePath(Module, keyPrefix, mock, request) {
|
|
2588
|
+
const leaf = subpathLeafOf(request);
|
|
2589
|
+
if (!leaf || !Object.prototype.hasOwnProperty.call(mock, leaf)) return null;
|
|
2590
|
+
const virtualPath = `${keyPrefix}:${leaf}`;
|
|
2591
|
+
if (!Module._cache[virtualPath]) {
|
|
2592
|
+
const syntheticModule = new Module(virtualPath);
|
|
2593
|
+
syntheticModule.id = virtualPath;
|
|
2594
|
+
syntheticModule.filename = virtualPath;
|
|
2595
|
+
syntheticModule.loaded = true;
|
|
2596
|
+
syntheticModule.exports = withDefaultInterop(mock[leaf]);
|
|
2597
|
+
Module._cache[virtualPath] = syntheticModule;
|
|
2598
|
+
leafModulePaths.add(virtualPath);
|
|
2599
|
+
}
|
|
2600
|
+
return virtualPath;
|
|
2601
|
+
}
|
|
2282
2602
|
function installCjsBridge(mockObject) {
|
|
2283
2603
|
if (installed) return;
|
|
2284
2604
|
try {
|
|
@@ -2289,16 +2609,36 @@ function installCjsBridge(mockObject) {
|
|
|
2289
2609
|
syntheticModule.loaded = true;
|
|
2290
2610
|
syntheticModule.exports = mockObject;
|
|
2291
2611
|
Module._cache[VIRTUAL_RN_PATH] = syntheticModule;
|
|
2612
|
+
rnMock$1 = mockObject;
|
|
2292
2613
|
originalResolveFilename = Module._resolveFilename;
|
|
2293
2614
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
2294
|
-
if (request === "react-native" || request.startsWith("react-native/"))
|
|
2615
|
+
if (request === "react-native" || request.startsWith("react-native/")) {
|
|
2616
|
+
if (request === "react-native/package.json") try {
|
|
2617
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2618
|
+
} catch {}
|
|
2619
|
+
else if (request !== "react-native" && rnMock$1) {
|
|
2620
|
+
const leafPath = leafModulePath(Module, VIRTUAL_RN_PATH, rnMock$1, request);
|
|
2621
|
+
if (leafPath) return leafPath;
|
|
2622
|
+
}
|
|
2623
|
+
return VIRTUAL_RN_PATH;
|
|
2624
|
+
}
|
|
2295
2625
|
const exactMatch = presetRedirects.get(request);
|
|
2296
2626
|
if (exactMatch) return exactMatch;
|
|
2297
2627
|
const slashIdx = request.indexOf("/", request.startsWith("@") ? request.indexOf("/") + 1 : 0);
|
|
2298
2628
|
if (slashIdx !== -1) {
|
|
2299
2629
|
const pkg = request.slice(0, slashIdx);
|
|
2300
2630
|
const subpathMatch = presetRedirects.get(pkg);
|
|
2301
|
-
if (subpathMatch)
|
|
2631
|
+
if (subpathMatch) {
|
|
2632
|
+
if (request.endsWith(".json")) try {
|
|
2633
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2634
|
+
} catch {}
|
|
2635
|
+
else {
|
|
2636
|
+
const mock = presetMocks.get(pkg);
|
|
2637
|
+
const leafPath = mock && leafModulePath(Module, subpathMatch, mock, request);
|
|
2638
|
+
if (leafPath) return leafPath;
|
|
2639
|
+
}
|
|
2640
|
+
return subpathMatch;
|
|
2641
|
+
}
|
|
2302
2642
|
}
|
|
2303
2643
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2304
2644
|
};
|
|
@@ -2318,6 +2658,10 @@ function uninstallCjsBridge() {
|
|
|
2318
2658
|
delete Module._cache[VIRTUAL_RN_PATH];
|
|
2319
2659
|
for (const virtualPath of presetRedirects.values()) delete Module._cache[virtualPath];
|
|
2320
2660
|
presetRedirects.clear();
|
|
2661
|
+
presetMocks.clear();
|
|
2662
|
+
for (const virtualPath of leafModulePaths) delete Module._cache[virtualPath];
|
|
2663
|
+
leafModulePaths.clear();
|
|
2664
|
+
rnMock$1 = null;
|
|
2321
2665
|
installed = false;
|
|
2322
2666
|
} catch (e) {
|
|
2323
2667
|
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge uninstall failed: ${e?.message}`);
|
|
@@ -2334,6 +2678,7 @@ function installPresetCjsBridge(moduleName, mockObject) {
|
|
|
2334
2678
|
syntheticModule.exports = mockObject;
|
|
2335
2679
|
Module._cache[virtualPath] = syntheticModule;
|
|
2336
2680
|
presetRedirects.set(moduleName, virtualPath);
|
|
2681
|
+
presetMocks.set(moduleName, mockObject);
|
|
2337
2682
|
} catch (e) {
|
|
2338
2683
|
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] Preset CJS bridge for ${moduleName} failed: ${e?.message}`);
|
|
2339
2684
|
}
|
|
@@ -2368,6 +2713,12 @@ if (process.env.VITEST_NATIVE_MOCKS) try {
|
|
|
2368
2713
|
if (diagnostics) console.warn(`[vitest-native] Failed to parse VITEST_NATIVE_MOCKS: ${e?.message}`);
|
|
2369
2714
|
}
|
|
2370
2715
|
let explicitPresetNames = null;
|
|
2716
|
+
let disabledPresetNames = [];
|
|
2717
|
+
if (process.env.VITEST_NATIVE_PRESET_DISABLED) try {
|
|
2718
|
+
disabledPresetNames = JSON.parse(process.env.VITEST_NATIVE_PRESET_DISABLED);
|
|
2719
|
+
} catch {
|
|
2720
|
+
disabledPresetNames = [];
|
|
2721
|
+
}
|
|
2371
2722
|
if (process.env.VITEST_NATIVE_PRESET_NAMES) try {
|
|
2372
2723
|
explicitPresetNames = JSON.parse(process.env.VITEST_NATIVE_PRESET_NAMES);
|
|
2373
2724
|
} catch (e) {
|
|
@@ -2448,7 +2799,7 @@ function loadExplicitPresets(names) {
|
|
|
2448
2799
|
}
|
|
2449
2800
|
return loaded;
|
|
2450
2801
|
}
|
|
2451
|
-
const presets = explicitPresetNames ? loadExplicitPresets(explicitPresetNames) : autoDetectPresets();
|
|
2802
|
+
const presets = explicitPresetNames ? loadExplicitPresets(explicitPresetNames) : autoDetectPresets().filter((p) => !disabledPresetNames.includes(p.name));
|
|
2452
2803
|
g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || {};
|
|
2453
2804
|
for (const preset of presets) for (const [modName, presetModule] of Object.entries(preset.modules)) {
|
|
2454
2805
|
const presetMock = presetModule.factory();
|