vitest-native 0.8.0 → 0.9.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 +332 -0
- package/README.md +15 -1
- package/dist/cli.cjs +506 -0
- package/dist/cli.d.cts +4 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +502 -0
- package/dist/ecosystem-BIWaVwYL.cjs +294 -0
- package/dist/ecosystem-EFtHnKS9.mjs +256 -0
- package/dist/{index-vlK4zxuK.d.mts → index-CEgRDdhd.d.cts} +13 -3
- package/dist/{index-YjjYELG7.d.cts → index-j-0tueBr.d.mts} +11 -5
- package/dist/index.cjs +345 -200
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +341 -196
- package/dist/jest-compat/setup.mjs +65 -1
- 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 +76 -3
- package/dist/native/loader.mjs +35 -6
- package/dist/native/match.mjs +107 -8
- package/dist/native/registry.mjs +471 -0
- package/dist/native/reset.mjs +18 -12
- package/dist/native/runner.mjs +13 -7
- package/dist/native/setup.mjs +15 -1
- package/dist/native/transform.mjs +88 -19
- package/dist/native/worker.mjs +10 -1
- package/dist/pool-CJmjRgsB.mjs +117 -0
- package/dist/pool-DzsEo9vv.cjs +121 -0
- package/dist/{preset-map-BY9zk9Pj.cjs → preset-map-CG4FMtsl.cjs} +1 -0
- package/dist/{preset-map-DCWaM08s.mjs → preset-map-CNsZKfvu.mjs} +1 -0
- package/dist/{presets-7eMfp7o2.cjs → presets-C4faM3ds.cjs} +133 -2
- package/dist/{presets-23FJ76O4.mjs → presets-CuDrNA_W.mjs} +128 -3
- package/dist/presets.cjs +2 -1
- package/dist/presets.d.cts +2 -2
- package/dist/presets.d.mts +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/setup.cjs +318 -130
- package/dist/setup.mjs +318 -130
- 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 +2 -1
- package/package.json +17 -5
- package/dist/pool-B7LBfcMQ.mjs +0 -67
- package/dist/pool-p54QV1dQ.cjs +0 -69
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-CNsZKfvu.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-CuDrNA_W.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,152 @@ 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
|
-
var
|
|
569
|
-
_value;
|
|
568
|
+
var AnimatedNode = class {
|
|
570
569
|
_listeners = /* @__PURE__ */ new Map();
|
|
570
|
+
_children = /* @__PURE__ */ new Set();
|
|
571
571
|
_listenerIdCounter = 0;
|
|
572
|
-
_tracking = null;
|
|
573
|
-
constructor(value = 0) {
|
|
574
|
-
this._value = value;
|
|
575
|
-
}
|
|
576
|
-
setValue(value) {
|
|
577
|
-
this._value = value;
|
|
578
|
-
this._listeners.forEach((fn) => fn({ value }));
|
|
579
|
-
}
|
|
580
572
|
getValue() {
|
|
581
|
-
return this.
|
|
573
|
+
return this.__getValue();
|
|
574
|
+
}
|
|
575
|
+
_attachToParents() {}
|
|
576
|
+
_detachFromParents() {}
|
|
577
|
+
_consumerCount() {
|
|
578
|
+
return this._listeners.size + this._children.size;
|
|
582
579
|
}
|
|
583
580
|
addListener(callback) {
|
|
584
581
|
const id = String(++this._listenerIdCounter);
|
|
585
582
|
this._listeners.set(id, callback);
|
|
583
|
+
if (this._consumerCount() === 1) this._attachToParents();
|
|
586
584
|
return id;
|
|
587
585
|
}
|
|
588
586
|
removeListener(id) {
|
|
589
|
-
this._listeners.delete(id);
|
|
587
|
+
if (this._listeners.delete(id) && this._consumerCount() === 0) this._detachFromParents();
|
|
590
588
|
}
|
|
591
589
|
removeAllListeners() {
|
|
590
|
+
const had = this._listeners.size > 0;
|
|
592
591
|
this._listeners.clear();
|
|
592
|
+
if (had && this._consumerCount() === 0) this._detachFromParents();
|
|
593
593
|
}
|
|
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
|
-
};
|
|
594
|
+
/** Graph edge: `fn` runs whenever this node's value may have changed. */
|
|
595
|
+
__addChild(fn) {
|
|
596
|
+
this._children.add(fn);
|
|
597
|
+
if (this._consumerCount() === 1) this._attachToParents();
|
|
598
|
+
}
|
|
599
|
+
__removeChild(fn) {
|
|
600
|
+
if (this._children.delete(fn) && this._consumerCount() === 0) this._detachFromParents();
|
|
601
|
+
}
|
|
602
|
+
/** Notify consumers with the node's CURRENT (offset-inclusive) value. */
|
|
603
|
+
_notify() {
|
|
604
|
+
if (this._listeners.size > 0) {
|
|
605
|
+
const value = this.__getValue();
|
|
606
|
+
this._listeners.forEach((fn) => fn({ value }));
|
|
614
607
|
}
|
|
615
|
-
|
|
608
|
+
this._children.forEach((fn) => fn());
|
|
609
|
+
}
|
|
610
|
+
interpolate(config) {
|
|
611
|
+
const { inputRange, outputRange } = config || {};
|
|
612
|
+
if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(Number(this.__getValue()) || 0);
|
|
613
|
+
return new AnimatedInterpolation(this, config);
|
|
616
614
|
}
|
|
617
615
|
stopAnimation(callback) {
|
|
618
|
-
callback?.(this.
|
|
616
|
+
callback?.(this.__getValue());
|
|
619
617
|
}
|
|
620
618
|
resetAnimation(callback) {
|
|
621
|
-
callback?.(this.
|
|
619
|
+
callback?.(this.__getValue());
|
|
622
620
|
}
|
|
623
621
|
toJSON() {
|
|
624
|
-
return this.
|
|
622
|
+
return this.__getValue();
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
var AnimatedValue = class extends AnimatedNode {
|
|
626
|
+
_value;
|
|
627
|
+
_offset = 0;
|
|
628
|
+
_tracking = null;
|
|
629
|
+
constructor(value = 0) {
|
|
630
|
+
super();
|
|
631
|
+
this._value = value;
|
|
632
|
+
}
|
|
633
|
+
setValue(value) {
|
|
634
|
+
this._value = value;
|
|
635
|
+
this._notify();
|
|
636
|
+
}
|
|
637
|
+
__getValue() {
|
|
638
|
+
return this._value + this._offset;
|
|
639
|
+
}
|
|
640
|
+
setOffset(offset) {
|
|
641
|
+
this._offset = offset;
|
|
642
|
+
}
|
|
643
|
+
flattenOffset() {
|
|
644
|
+
this._value += this._offset;
|
|
645
|
+
this._offset = 0;
|
|
646
|
+
}
|
|
647
|
+
extractOffset() {
|
|
648
|
+
this._offset += this._value;
|
|
649
|
+
this._value = 0;
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
var AnimatedInterpolation = class extends AnimatedNode {
|
|
653
|
+
_parent;
|
|
654
|
+
_config;
|
|
655
|
+
_preparedString = null;
|
|
656
|
+
constructor(parent, config) {
|
|
657
|
+
super();
|
|
658
|
+
this._parent = parent;
|
|
659
|
+
this._config = config;
|
|
660
|
+
const { inputRange, outputRange } = config;
|
|
661
|
+
checkValidRanges(inputRange, outputRange);
|
|
662
|
+
if (typeof outputRange[0] === "string") this._preparedString = prepareStringInterpolation(outputRange);
|
|
663
|
+
}
|
|
664
|
+
_propagate = () => this._notify();
|
|
665
|
+
_attachToParents() {
|
|
666
|
+
this._parent.__addChild(this._propagate);
|
|
667
|
+
}
|
|
668
|
+
_detachFromParents() {
|
|
669
|
+
this._parent.__removeChild(this._propagate);
|
|
670
|
+
}
|
|
671
|
+
__getValue() {
|
|
672
|
+
const { inputRange, outputRange, extrapolate = "extend", extrapolateLeft, extrapolateRight, easing = IDENTITY_EASING } = this._config;
|
|
673
|
+
const input = Number(this._parent.__getValue());
|
|
674
|
+
if (this._preparedString) return interpolateString(this._preparedString, input, inputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
675
|
+
return interpolateNumeric(input, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
676
|
+
}
|
|
677
|
+
interpolate(config) {
|
|
678
|
+
if (this._preparedString) throw new Error("Cannot chain an interpolation off a string-valued interpolation");
|
|
679
|
+
return super.interpolate(config);
|
|
625
680
|
}
|
|
626
|
-
setOffset(_offset) {}
|
|
627
|
-
flattenOffset() {}
|
|
628
|
-
extractOffset() {}
|
|
629
681
|
};
|
|
682
|
+
var AnimatedOp = class extends AnimatedNode {
|
|
683
|
+
_compute;
|
|
684
|
+
_parents;
|
|
685
|
+
_propagate = () => this._notify();
|
|
686
|
+
constructor(inputs, compute) {
|
|
687
|
+
super();
|
|
688
|
+
this._compute = compute;
|
|
689
|
+
this._parents = inputs.filter((i) => i instanceof AnimatedNode);
|
|
690
|
+
}
|
|
691
|
+
_attachToParents() {
|
|
692
|
+
for (const parent of this._parents) parent.__addChild(this._propagate);
|
|
693
|
+
}
|
|
694
|
+
_detachFromParents() {
|
|
695
|
+
for (const parent of this._parents) parent.__removeChild(this._propagate);
|
|
696
|
+
}
|
|
697
|
+
__getValue() {
|
|
698
|
+
return this._compute();
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
/** Numeric value of an operand that may be a node, a number, or junk (→ 0). */
|
|
702
|
+
function operandValue(v) {
|
|
703
|
+
if (v instanceof AnimatedNode) {
|
|
704
|
+
const n = Number(v.__getValue());
|
|
705
|
+
return Number.isNaN(n) ? 0 : n;
|
|
706
|
+
}
|
|
707
|
+
return typeof v === "number" ? v : 0;
|
|
708
|
+
}
|
|
630
709
|
var AnimatedValueXY = class {
|
|
631
710
|
x;
|
|
632
711
|
y;
|
|
712
|
+
_listenerIdCounter = 0;
|
|
713
|
+
_joint = /* @__PURE__ */ new Map();
|
|
633
714
|
constructor(value) {
|
|
634
715
|
this.x = new AnimatedValue(value?.x ?? 0);
|
|
635
716
|
this.y = new AnimatedValue(value?.y ?? 0);
|
|
@@ -638,31 +719,52 @@ var AnimatedValueXY = class {
|
|
|
638
719
|
this.x.setValue(value.x);
|
|
639
720
|
this.y.setValue(value.y);
|
|
640
721
|
}
|
|
641
|
-
setOffset(
|
|
642
|
-
|
|
643
|
-
|
|
722
|
+
setOffset(offset) {
|
|
723
|
+
this.x.setOffset(offset.x);
|
|
724
|
+
this.y.setOffset(offset.y);
|
|
725
|
+
}
|
|
726
|
+
flattenOffset() {
|
|
727
|
+
this.x.flattenOffset();
|
|
728
|
+
this.y.flattenOffset();
|
|
729
|
+
}
|
|
730
|
+
extractOffset() {
|
|
731
|
+
this.x.extractOffset();
|
|
732
|
+
this.y.extractOffset();
|
|
733
|
+
}
|
|
734
|
+
__getValue() {
|
|
735
|
+
return {
|
|
736
|
+
x: this.x.__getValue(),
|
|
737
|
+
y: this.y.__getValue()
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
getValue() {
|
|
741
|
+
return this.__getValue();
|
|
742
|
+
}
|
|
644
743
|
stopAnimation(callback) {
|
|
645
|
-
callback?.(
|
|
646
|
-
x: this.x.getValue(),
|
|
647
|
-
y: this.y.getValue()
|
|
648
|
-
});
|
|
744
|
+
callback?.(this.__getValue());
|
|
649
745
|
}
|
|
650
746
|
resetAnimation(callback) {
|
|
651
|
-
callback?.(
|
|
652
|
-
x: this.x.getValue(),
|
|
653
|
-
y: this.y.getValue()
|
|
654
|
-
});
|
|
747
|
+
callback?.(this.__getValue());
|
|
655
748
|
}
|
|
656
|
-
addListener(
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
749
|
+
addListener(callback) {
|
|
750
|
+
const emit = () => callback(this.__getValue());
|
|
751
|
+
const id = String(++this._listenerIdCounter);
|
|
752
|
+
const pair = {
|
|
753
|
+
x: this.x.addListener(emit),
|
|
754
|
+
y: this.y.addListener(emit)
|
|
660
755
|
};
|
|
756
|
+
this._joint.set(id, pair);
|
|
757
|
+
return pair;
|
|
661
758
|
}
|
|
662
759
|
removeListener(id) {
|
|
663
760
|
this.x.removeListener(id.x);
|
|
664
761
|
this.y.removeListener(id.y);
|
|
665
762
|
}
|
|
763
|
+
removeAllListeners() {
|
|
764
|
+
this.x.removeAllListeners();
|
|
765
|
+
this.y.removeAllListeners();
|
|
766
|
+
this._joint.clear();
|
|
767
|
+
}
|
|
666
768
|
getLayout() {
|
|
667
769
|
return {
|
|
668
770
|
left: this.x,
|
|
@@ -760,26 +862,25 @@ function parseColorString(color) {
|
|
|
760
862
|
1
|
|
761
863
|
];
|
|
762
864
|
}
|
|
763
|
-
var AnimatedColor = class {
|
|
865
|
+
var AnimatedColor = class extends AnimatedNode {
|
|
764
866
|
r;
|
|
765
867
|
g;
|
|
766
868
|
b;
|
|
767
869
|
a;
|
|
768
|
-
_listeners = /* @__PURE__ */ new Map();
|
|
769
|
-
_listenerIdCounter = 0;
|
|
770
870
|
constructor(color) {
|
|
871
|
+
super();
|
|
771
872
|
if (typeof color === "string") {
|
|
772
873
|
const [r, g, b, a] = parseColorString(color);
|
|
773
874
|
this.r = new AnimatedValue(r);
|
|
774
875
|
this.g = new AnimatedValue(g);
|
|
775
876
|
this.b = new AnimatedValue(b);
|
|
776
877
|
this.a = new AnimatedValue(a);
|
|
777
|
-
} else if (color && typeof color === "object"
|
|
878
|
+
} else if (color && typeof color === "object" && color.r instanceof AnimatedValue) {
|
|
778
879
|
this.r = color.r;
|
|
779
880
|
this.g = color.g;
|
|
780
881
|
this.b = color.b;
|
|
781
882
|
this.a = color.a;
|
|
782
|
-
} else if (typeof color.r === "number") {
|
|
883
|
+
} else if (color && typeof color === "object" && typeof color.r === "number") {
|
|
783
884
|
this.r = new AnimatedValue(color.r);
|
|
784
885
|
this.g = new AnimatedValue(color.g ?? 0);
|
|
785
886
|
this.b = new AnimatedValue(color.b ?? 0);
|
|
@@ -790,12 +891,12 @@ var AnimatedColor = class {
|
|
|
790
891
|
this.b = new AnimatedValue(0);
|
|
791
892
|
this.a = new AnimatedValue(1);
|
|
792
893
|
}
|
|
793
|
-
|
|
794
|
-
this.r
|
|
795
|
-
this.g
|
|
796
|
-
this.b
|
|
797
|
-
this.a
|
|
798
|
-
|
|
894
|
+
for (const channel of [
|
|
895
|
+
this.r,
|
|
896
|
+
this.g,
|
|
897
|
+
this.b,
|
|
898
|
+
this.a
|
|
899
|
+
]) channel.__addChild(() => this._notify());
|
|
799
900
|
}
|
|
800
901
|
setValue(value) {
|
|
801
902
|
if (typeof value === "string") {
|
|
@@ -810,31 +911,12 @@ var AnimatedColor = class {
|
|
|
810
911
|
this.b.setValue(value.b ?? 0);
|
|
811
912
|
this.a.setValue(value.a ?? 1);
|
|
812
913
|
}
|
|
813
|
-
const colorStr = this.__getValue();
|
|
814
|
-
this._listeners.forEach((fn) => fn({ value: colorStr }));
|
|
815
914
|
}
|
|
816
915
|
__getValue() {
|
|
817
916
|
return `rgba(${Math.round(this.r.getValue())}, ${Math.round(this.g.getValue())}, ${Math.round(this.b.getValue())}, ${this.a.getValue()})`;
|
|
818
917
|
}
|
|
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
918
|
setOffset(_offset) {}
|
|
831
919
|
flattenOffset() {}
|
|
832
|
-
stopAnimation(callback) {
|
|
833
|
-
callback?.(this.__getValue());
|
|
834
|
-
}
|
|
835
|
-
resetAnimation(callback) {
|
|
836
|
-
callback?.(this.__getValue());
|
|
837
|
-
}
|
|
838
920
|
};
|
|
839
921
|
function createAnimation(onStart) {
|
|
840
922
|
return {
|
|
@@ -849,9 +931,9 @@ function createAnimation(onStart) {
|
|
|
849
931
|
};
|
|
850
932
|
}
|
|
851
933
|
function resolveAnimatedLeaf(v) {
|
|
852
|
-
if (v instanceof
|
|
934
|
+
if (v instanceof AnimatedNode) return v.__getValue();
|
|
853
935
|
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();
|
|
936
|
+
if (v && typeof v === "object" && !Array.isArray(v) && typeof v.getValue === "function") return v.getValue();
|
|
855
937
|
return v;
|
|
856
938
|
}
|
|
857
939
|
function resolveAnimatedStyle(style) {
|
|
@@ -862,16 +944,40 @@ function resolveAnimatedStyle(style) {
|
|
|
862
944
|
const out = {};
|
|
863
945
|
for (const key of Object.keys(style)) {
|
|
864
946
|
const val = style[key];
|
|
865
|
-
if (key === "transform" && Array.isArray(val)) out[key] = val.map((t) => t && typeof t === "object" && !(t instanceof
|
|
947
|
+
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
948
|
else out[key] = resolveAnimatedLeaf(val);
|
|
867
949
|
}
|
|
868
950
|
return out;
|
|
869
951
|
}
|
|
870
952
|
return style;
|
|
871
953
|
}
|
|
954
|
+
function collectAnimatedNodes(style, out) {
|
|
955
|
+
if (style instanceof AnimatedNode) {
|
|
956
|
+
out.add(style);
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (Array.isArray(style)) {
|
|
960
|
+
for (const s of style) collectAnimatedNodes(s, out);
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
if (style && typeof style === "object") for (const key of Object.keys(style)) collectAnimatedNodes(style[key], out);
|
|
964
|
+
}
|
|
965
|
+
function useAnimatedStyleSubscription(style) {
|
|
966
|
+
const [, force] = React.useReducer((n) => n + 1, 0);
|
|
967
|
+
React.useEffect(() => {
|
|
968
|
+
const nodes = /* @__PURE__ */ new Set();
|
|
969
|
+
collectAnimatedNodes(style, nodes);
|
|
970
|
+
if (nodes.size === 0) return void 0;
|
|
971
|
+
for (const node of nodes) node.__addChild(force);
|
|
972
|
+
return () => {
|
|
973
|
+
for (const node of nodes) node.__removeChild(force);
|
|
974
|
+
};
|
|
975
|
+
});
|
|
976
|
+
}
|
|
872
977
|
function createAnimatedWrapper(displayName) {
|
|
873
978
|
const hostName = displayName.replace(/^Animated\./, "");
|
|
874
979
|
const Component = React.forwardRef((props, ref) => {
|
|
980
|
+
useAnimatedStyleSubscription(props?.style);
|
|
875
981
|
if (props && props.style !== void 0) {
|
|
876
982
|
const { style, ...rest } = props;
|
|
877
983
|
return React.createElement(hostName, {
|
|
@@ -890,7 +996,7 @@ function createAnimatedWrapper(displayName) {
|
|
|
890
996
|
}
|
|
891
997
|
function stopTracking(value) {
|
|
892
998
|
if (value._tracking) {
|
|
893
|
-
value._tracking.source.
|
|
999
|
+
value._tracking.source.__removeChild(value._tracking.child);
|
|
894
1000
|
value._tracking = null;
|
|
895
1001
|
}
|
|
896
1002
|
}
|
|
@@ -898,14 +1004,32 @@ function startTracking(value, toValue) {
|
|
|
898
1004
|
stopTracking(value);
|
|
899
1005
|
if (toValue instanceof AnimatedValue) {
|
|
900
1006
|
value.setValue(toValue.getValue());
|
|
1007
|
+
const child = () => value.setValue(toValue.__getValue());
|
|
1008
|
+
toValue.__addChild(child);
|
|
901
1009
|
value._tracking = {
|
|
902
1010
|
source: toValue,
|
|
903
|
-
|
|
904
|
-
value.setValue(v);
|
|
905
|
-
})
|
|
1011
|
+
child
|
|
906
1012
|
};
|
|
907
1013
|
} else value.setValue(toValue);
|
|
908
1014
|
}
|
|
1015
|
+
var AnimatedDiffClamp = class extends AnimatedNode {
|
|
1016
|
+
_current;
|
|
1017
|
+
constructor(a, min, max) {
|
|
1018
|
+
super();
|
|
1019
|
+
let lastInput = operandValue(a);
|
|
1020
|
+
this._current = Math.min(Math.max(lastInput, min), max);
|
|
1021
|
+
if (a instanceof AnimatedNode) a.__addChild(() => {
|
|
1022
|
+
const value = Number(a.__getValue());
|
|
1023
|
+
const diff = value - lastInput;
|
|
1024
|
+
lastInput = value;
|
|
1025
|
+
this._current = Math.min(Math.max(this._current + diff, min), max);
|
|
1026
|
+
this._notify();
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
__getValue() {
|
|
1030
|
+
return this._current;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
909
1033
|
function createAnimatedMock() {
|
|
910
1034
|
return {
|
|
911
1035
|
Value: AnimatedValue,
|
|
@@ -1070,37 +1194,15 @@ function createAnimatedMock() {
|
|
|
1070
1194
|
delay: vi.fn((_time) => {
|
|
1071
1195
|
return createAnimation();
|
|
1072
1196
|
}),
|
|
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
|
-
}),
|
|
1197
|
+
add: vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) + operandValue(b))),
|
|
1198
|
+
subtract: vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) - operandValue(b))),
|
|
1199
|
+
multiply: vi.fn((a, b) => new AnimatedOp([a, b], () => operandValue(a) * operandValue(b))),
|
|
1200
|
+
divide: vi.fn((a, b) => new AnimatedOp([a, b], () => {
|
|
1201
|
+
const divisor = operandValue(b);
|
|
1202
|
+
return divisor === 0 ? 0 : operandValue(a) / divisor;
|
|
1203
|
+
})),
|
|
1204
|
+
modulo: vi.fn((a, modulus) => new AnimatedOp([a], () => (operandValue(a) % modulus + modulus) % modulus)),
|
|
1205
|
+
diffClamp: vi.fn((a, min, max) => new AnimatedDiffClamp(a, min, max)),
|
|
1104
1206
|
event: vi.fn((argMapping, config) => {
|
|
1105
1207
|
const handler = vi.fn((...args) => {
|
|
1106
1208
|
argMapping.forEach((mapping, index) => {
|
|
@@ -1129,6 +1231,15 @@ function createAnimatedMock() {
|
|
|
1129
1231
|
unforkEvent: vi.fn(),
|
|
1130
1232
|
createAnimatedComponent: vi.fn((component) => {
|
|
1131
1233
|
const Wrapper = React.forwardRef((props, ref) => {
|
|
1234
|
+
useAnimatedStyleSubscription(props?.style);
|
|
1235
|
+
if (props && props.style !== void 0) {
|
|
1236
|
+
const { style, ...rest } = props;
|
|
1237
|
+
return React.createElement(component, {
|
|
1238
|
+
...rest,
|
|
1239
|
+
style: resolveAnimatedStyle(style),
|
|
1240
|
+
ref
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1132
1243
|
return React.createElement(component, {
|
|
1133
1244
|
...props,
|
|
1134
1245
|
ref
|
|
@@ -2030,7 +2141,6 @@ function createProcessColorMock() {
|
|
|
2030
2141
|
return (Math.round(parseFloat(a) * 255) << 24) + (r << 16) + (g << 8) + b >>> 0;
|
|
2031
2142
|
}
|
|
2032
2143
|
}
|
|
2033
|
-
return 4278190080;
|
|
2034
2144
|
});
|
|
2035
2145
|
}
|
|
2036
2146
|
function createFindNodeHandleMock() {
|
|
@@ -2100,17 +2210,23 @@ function createTouchableMock() {
|
|
|
2100
2210
|
}
|
|
2101
2211
|
function createUseAnimatedValueMock() {
|
|
2102
2212
|
return vi.fn((initialValue) => {
|
|
2103
|
-
|
|
2213
|
+
const ref = React.useRef(null);
|
|
2214
|
+
if (ref.current == null) ref.current = new AnimatedValue(initialValue);
|
|
2215
|
+
return ref.current;
|
|
2104
2216
|
});
|
|
2105
2217
|
}
|
|
2106
2218
|
function createUseAnimatedValueXYMock() {
|
|
2107
2219
|
return vi.fn((initialValue) => {
|
|
2108
|
-
|
|
2220
|
+
const ref = React.useRef(null);
|
|
2221
|
+
if (ref.current == null) ref.current = new AnimatedValueXY(initialValue);
|
|
2222
|
+
return ref.current;
|
|
2109
2223
|
});
|
|
2110
2224
|
}
|
|
2111
2225
|
function createUseAnimatedColorMock() {
|
|
2112
2226
|
return vi.fn((initialValue) => {
|
|
2113
|
-
|
|
2227
|
+
const ref = React.useRef(null);
|
|
2228
|
+
if (ref.current == null) ref.current = new AnimatedColor(initialValue);
|
|
2229
|
+
return ref.current;
|
|
2114
2230
|
});
|
|
2115
2231
|
}
|
|
2116
2232
|
function buildReactNativeMock(platform = "ios") {
|
|
@@ -2278,7 +2394,54 @@ function buildReactNativeMock(platform = "ios") {
|
|
|
2278
2394
|
const VIRTUAL_RN_PATH = "\0vitest-native:react-native";
|
|
2279
2395
|
let originalResolveFilename = null;
|
|
2280
2396
|
let installed = false;
|
|
2397
|
+
let rnMock$1 = null;
|
|
2281
2398
|
const presetRedirects = /* @__PURE__ */ new Map();
|
|
2399
|
+
const presetMocks = /* @__PURE__ */ new Map();
|
|
2400
|
+
const leafModulePaths = /* @__PURE__ */ new Set();
|
|
2401
|
+
/**
|
|
2402
|
+
* The leaf module name a subpath require points at ("pkg/lib/Swipeable" or
|
|
2403
|
+
* ".../Platform.ios.js" → "Platform"). Mirrors native/match.mjs.
|
|
2404
|
+
*/
|
|
2405
|
+
function subpathLeafOf(request) {
|
|
2406
|
+
const base = request.split("/").pop();
|
|
2407
|
+
if (!base) return null;
|
|
2408
|
+
return base.split(".")[0] || null;
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Wrap a leaf export in Babel-CJS interop shape: the real compiled deep entry
|
|
2412
|
+
* exports `{ __esModule: true, default: X }`. A live Proxy keeps
|
|
2413
|
+
* direct-property consumers (`require('pkg/Sub').OS`) working too.
|
|
2414
|
+
*/
|
|
2415
|
+
function withDefaultInterop(value) {
|
|
2416
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return {
|
|
2417
|
+
__esModule: true,
|
|
2418
|
+
default: value
|
|
2419
|
+
};
|
|
2420
|
+
return new Proxy(value, {
|
|
2421
|
+
get: (t, p, r) => p === "default" ? t : p === "__esModule" ? true : Reflect.get(t, p, r),
|
|
2422
|
+
has: (t, p) => p === "default" || p === "__esModule" || Reflect.has(t, p)
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
/**
|
|
2426
|
+
* Get or create a synthetic Module._cache entry for a subpath require whose
|
|
2427
|
+
* leaf name matches an export on the mock. Returns its virtual path, or null
|
|
2428
|
+
* when the leaf has no matching export (caller falls back to the root mock).
|
|
2429
|
+
*/
|
|
2430
|
+
function leafModulePath(Module, keyPrefix, mock, request) {
|
|
2431
|
+
const leaf = subpathLeafOf(request);
|
|
2432
|
+
if (!leaf || !Object.prototype.hasOwnProperty.call(mock, leaf)) return null;
|
|
2433
|
+
const virtualPath = `${keyPrefix}:${leaf}`;
|
|
2434
|
+
if (!Module._cache[virtualPath]) {
|
|
2435
|
+
const syntheticModule = new Module(virtualPath);
|
|
2436
|
+
syntheticModule.id = virtualPath;
|
|
2437
|
+
syntheticModule.filename = virtualPath;
|
|
2438
|
+
syntheticModule.loaded = true;
|
|
2439
|
+
syntheticModule.exports = withDefaultInterop(mock[leaf]);
|
|
2440
|
+
Module._cache[virtualPath] = syntheticModule;
|
|
2441
|
+
leafModulePaths.add(virtualPath);
|
|
2442
|
+
}
|
|
2443
|
+
return virtualPath;
|
|
2444
|
+
}
|
|
2282
2445
|
function installCjsBridge(mockObject) {
|
|
2283
2446
|
if (installed) return;
|
|
2284
2447
|
try {
|
|
@@ -2289,16 +2452,36 @@ function installCjsBridge(mockObject) {
|
|
|
2289
2452
|
syntheticModule.loaded = true;
|
|
2290
2453
|
syntheticModule.exports = mockObject;
|
|
2291
2454
|
Module._cache[VIRTUAL_RN_PATH] = syntheticModule;
|
|
2455
|
+
rnMock$1 = mockObject;
|
|
2292
2456
|
originalResolveFilename = Module._resolveFilename;
|
|
2293
2457
|
Module._resolveFilename = function(request, parent, isMain, options) {
|
|
2294
|
-
if (request === "react-native" || request.startsWith("react-native/"))
|
|
2458
|
+
if (request === "react-native" || request.startsWith("react-native/")) {
|
|
2459
|
+
if (request === "react-native/package.json") try {
|
|
2460
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2461
|
+
} catch {}
|
|
2462
|
+
else if (request !== "react-native" && rnMock$1) {
|
|
2463
|
+
const leafPath = leafModulePath(Module, VIRTUAL_RN_PATH, rnMock$1, request);
|
|
2464
|
+
if (leafPath) return leafPath;
|
|
2465
|
+
}
|
|
2466
|
+
return VIRTUAL_RN_PATH;
|
|
2467
|
+
}
|
|
2295
2468
|
const exactMatch = presetRedirects.get(request);
|
|
2296
2469
|
if (exactMatch) return exactMatch;
|
|
2297
2470
|
const slashIdx = request.indexOf("/", request.startsWith("@") ? request.indexOf("/") + 1 : 0);
|
|
2298
2471
|
if (slashIdx !== -1) {
|
|
2299
2472
|
const pkg = request.slice(0, slashIdx);
|
|
2300
2473
|
const subpathMatch = presetRedirects.get(pkg);
|
|
2301
|
-
if (subpathMatch)
|
|
2474
|
+
if (subpathMatch) {
|
|
2475
|
+
if (request.endsWith(".json")) try {
|
|
2476
|
+
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2477
|
+
} catch {}
|
|
2478
|
+
else {
|
|
2479
|
+
const mock = presetMocks.get(pkg);
|
|
2480
|
+
const leafPath = mock && leafModulePath(Module, subpathMatch, mock, request);
|
|
2481
|
+
if (leafPath) return leafPath;
|
|
2482
|
+
}
|
|
2483
|
+
return subpathMatch;
|
|
2484
|
+
}
|
|
2302
2485
|
}
|
|
2303
2486
|
return originalResolveFilename.call(this, request, parent, isMain, options);
|
|
2304
2487
|
};
|
|
@@ -2318,6 +2501,10 @@ function uninstallCjsBridge() {
|
|
|
2318
2501
|
delete Module._cache[VIRTUAL_RN_PATH];
|
|
2319
2502
|
for (const virtualPath of presetRedirects.values()) delete Module._cache[virtualPath];
|
|
2320
2503
|
presetRedirects.clear();
|
|
2504
|
+
presetMocks.clear();
|
|
2505
|
+
for (const virtualPath of leafModulePaths) delete Module._cache[virtualPath];
|
|
2506
|
+
leafModulePaths.clear();
|
|
2507
|
+
rnMock$1 = null;
|
|
2321
2508
|
installed = false;
|
|
2322
2509
|
} catch (e) {
|
|
2323
2510
|
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge uninstall failed: ${e?.message}`);
|
|
@@ -2334,6 +2521,7 @@ function installPresetCjsBridge(moduleName, mockObject) {
|
|
|
2334
2521
|
syntheticModule.exports = mockObject;
|
|
2335
2522
|
Module._cache[virtualPath] = syntheticModule;
|
|
2336
2523
|
presetRedirects.set(moduleName, virtualPath);
|
|
2524
|
+
presetMocks.set(moduleName, mockObject);
|
|
2337
2525
|
} catch (e) {
|
|
2338
2526
|
if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] Preset CJS bridge for ${moduleName} failed: ${e?.message}`);
|
|
2339
2527
|
}
|