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