vitest-native 0.2.1 → 0.3.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/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-D224CC5w.mjs";
3
- import { t as presets_exports } from "./presets-CWH0gtM0.mjs";
2
+ import { t as AUTO_DETECT_PRESETS } from "./preset-map-BTpoNH3G.mjs";
3
+ import { t as presets_exports } from "./presets-DvrcfEPz.mjs";
4
4
  import { serializer } from "./serializer.mjs";
5
5
  import { createRequire } from "node:module";
6
6
  import path from "node:path";
@@ -21,8 +21,15 @@ function createViewMock() {
21
21
  //#region src/mocks/components/Text.ts
22
22
  function createTextMock() {
23
23
  const Text = React.forwardRef((props, ref) => {
24
+ const { onPress, onLongPress, disabled, accessibilityRole, ...rest } = props;
25
+ const resolvedRole = accessibilityRole ?? (!disabled && (onPress || onLongPress) ? "link" : void 0);
24
26
  return React.createElement("Text", {
25
- ...props,
27
+ accessible: true,
28
+ ...rest,
29
+ ...onPress ? { onPress } : {},
30
+ ...onLongPress ? { onLongPress } : {},
31
+ ...disabled ? { disabled } : {},
32
+ ...resolvedRole ? { accessibilityRole: resolvedRole } : {},
26
33
  ref
27
34
  });
28
35
  });
@@ -81,6 +88,7 @@ function createTextInputMock() {
81
88
  //#region src/mocks/components/ScrollView.ts
82
89
  function createScrollViewMock() {
83
90
  const ScrollView = React.forwardRef((props, ref) => {
91
+ const { children, refreshControl, ...rest } = props;
84
92
  const instanceMethods = {
85
93
  scrollTo: vi.fn(),
86
94
  scrollToEnd: vi.fn(),
@@ -90,10 +98,10 @@ function createScrollViewMock() {
90
98
  setNativeProps: vi.fn()
91
99
  };
92
100
  React.useImperativeHandle(ref, () => instanceMethods);
93
- return React.createElement("ScrollView", {
94
- ...props,
101
+ return React.createElement("RCTScrollView", {
102
+ ...rest,
95
103
  ref
96
- });
104
+ }, refreshControl, React.createElement("View", null, children));
97
105
  });
98
106
  ScrollView.displayName = "ScrollView";
99
107
  return ScrollView;
@@ -210,8 +218,15 @@ function createModalMock() {
210
218
  //#region src/mocks/components/Pressable.ts
211
219
  function createPressableMock() {
212
220
  const Pressable = React.forwardRef((props, ref) => {
221
+ const { disabled, accessibilityState, ...rest } = props;
222
+ const mergedA11yState = disabled || accessibilityState ? {
223
+ ...accessibilityState,
224
+ ...disabled ? { disabled: true } : {}
225
+ } : void 0;
213
226
  return React.createElement("Pressable", {
214
- ...props,
227
+ accessible: true,
228
+ ...rest,
229
+ ...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
215
230
  ref
216
231
  });
217
232
  });
@@ -222,8 +237,15 @@ function createPressableMock() {
222
237
  //#region src/mocks/components/TouchableOpacity.ts
223
238
  function createTouchableOpacityMock() {
224
239
  const TouchableOpacity = React.forwardRef((props, ref) => {
240
+ const { disabled, accessibilityState, ...rest } = props;
241
+ const mergedA11yState = disabled || accessibilityState ? {
242
+ ...accessibilityState,
243
+ ...disabled ? { disabled: true } : {}
244
+ } : void 0;
225
245
  return React.createElement("TouchableOpacity", {
226
- ...props,
246
+ accessible: true,
247
+ ...rest,
248
+ ...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
227
249
  ref
228
250
  });
229
251
  });
@@ -234,8 +256,15 @@ function createTouchableOpacityMock() {
234
256
  //#region src/mocks/components/TouchableHighlight.ts
235
257
  function createTouchableHighlightMock() {
236
258
  const TouchableHighlight = React.forwardRef((props, ref) => {
259
+ const { disabled, accessibilityState, ...rest } = props;
260
+ const mergedA11yState = disabled || accessibilityState ? {
261
+ ...accessibilityState,
262
+ ...disabled ? { disabled: true } : {}
263
+ } : void 0;
237
264
  return React.createElement("TouchableHighlight", {
238
- ...props,
265
+ accessible: true,
266
+ ...rest,
267
+ ...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
239
268
  ref
240
269
  });
241
270
  });
@@ -246,8 +275,15 @@ function createTouchableHighlightMock() {
246
275
  //#region src/mocks/components/TouchableWithoutFeedback.ts
247
276
  function createTouchableWithoutFeedbackMock() {
248
277
  const TouchableWithoutFeedback = React.forwardRef((props, ref) => {
278
+ const { disabled, accessibilityState, ...rest } = props;
279
+ const mergedA11yState = disabled || accessibilityState ? {
280
+ ...accessibilityState,
281
+ ...disabled ? { disabled: true } : {}
282
+ } : void 0;
249
283
  return React.createElement("TouchableWithoutFeedback", {
250
- ...props,
284
+ accessible: true,
285
+ ...rest,
286
+ ...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
251
287
  ref
252
288
  });
253
289
  });
@@ -258,8 +294,15 @@ function createTouchableWithoutFeedbackMock() {
258
294
  //#region src/mocks/components/TouchableNativeFeedback.ts
259
295
  function createTouchableNativeFeedbackMock() {
260
296
  const TouchableNativeFeedback = React.forwardRef((props, ref) => {
297
+ const { disabled, accessibilityState, ...rest } = props;
298
+ const mergedA11yState = disabled || accessibilityState ? {
299
+ ...accessibilityState,
300
+ ...disabled ? { disabled: true } : {}
301
+ } : void 0;
261
302
  return React.createElement("TouchableNativeFeedback", {
262
- ...props,
303
+ accessible: true,
304
+ ...rest,
305
+ ...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
263
306
  ref
264
307
  });
265
308
  });
@@ -282,16 +325,22 @@ function createActivityIndicatorMock() {
282
325
  //#region src/mocks/components/Button.ts
283
326
  function createButtonMock() {
284
327
  function Button(props) {
285
- const { title, onPress, disabled, color, accessibilityLabel, testID, ...rest } = props;
328
+ const { title, onPress, disabled, color, accessibilityLabel, accessibilityState, testID, ...rest } = props;
286
329
  return React.createElement("View", {
287
330
  ...rest,
288
- testID
289
- }, React.createElement("Text", {
331
+ testID,
290
332
  onPress: disabled ? void 0 : onPress,
291
333
  accessibilityLabel: accessibilityLabel || title,
292
334
  accessibilityRole: "button",
293
- disabled,
294
- style: color ? { color } : void 0
335
+ accessibilityState: disabled ? {
336
+ ...accessibilityState,
337
+ disabled: true
338
+ } : accessibilityState,
339
+ accessible: true,
340
+ disabled
341
+ }, React.createElement("Text", {
342
+ style: color ? { color } : void 0,
343
+ disabled
295
344
  }, title));
296
345
  }
297
346
  Button.displayName = "Button";
@@ -301,7 +350,7 @@ function createButtonMock() {
301
350
  //#region src/mocks/components/Switch.ts
302
351
  function createSwitchMock() {
303
352
  const Switch = React.forwardRef((props, ref) => {
304
- return React.createElement("Switch", {
353
+ return React.createElement("RCTSwitch", {
305
354
  ...props,
306
355
  ref
307
356
  });
@@ -457,7 +506,7 @@ function createPlatformMock(os = "ios") {
457
506
  isVision: false,
458
507
  isTesting: true,
459
508
  select: vi.fn((specifics) => {
460
- return specifics[os] ?? specifics.default;
509
+ return specifics[os] ?? specifics.native ?? specifics.default;
461
510
  }),
462
511
  constants: {
463
512
  reactNativeVersion: {
@@ -515,12 +564,26 @@ function createDimensionsMock() {
515
564
  }
516
565
  //#endregion
517
566
  //#region src/mocks/apis/StyleSheet.ts
567
+ function flattenImpl(style) {
568
+ if (style == null || style === false) return void 0;
569
+ if (!Array.isArray(style)) return style;
570
+ const result = {};
571
+ let hasAny = false;
572
+ for (const item of style) {
573
+ const flattened = flattenImpl(item);
574
+ if (flattened != null) {
575
+ hasAny = true;
576
+ Object.assign(result, flattened);
577
+ }
578
+ }
579
+ return hasAny ? result : void 0;
580
+ }
518
581
  function createStyleSheetMock() {
519
582
  return {
520
583
  create: vi.fn((styles) => {
521
584
  return styles;
522
585
  }),
523
- flatten: vi.fn((...args) => Object.assign({}, ...args.flat(Infinity).filter(Boolean))),
586
+ flatten: vi.fn((style) => flattenImpl(style)),
524
587
  compose: vi.fn((a, b) => [a, b]),
525
588
  absoluteFill: {
526
589
  position: "absolute",
@@ -542,10 +605,50 @@ function createStyleSheetMock() {
542
605
  }
543
606
  //#endregion
544
607
  //#region src/mocks/apis/Animated.ts
608
+ function toNum(v) {
609
+ return typeof v === "number" ? v : parseFloat(v) || 0;
610
+ }
611
+ function interpolateValue(value, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing) {
612
+ let i = 0;
613
+ for (; i < inputRange.length - 2; i++) if (value <= inputRange[i + 1]) break;
614
+ const inMin = inputRange[i];
615
+ const inMax = inputRange[i + 1];
616
+ const outMin = toNum(outputRange[i]);
617
+ const outMax = toNum(outputRange[i + 1]);
618
+ if (inMax === inMin) {
619
+ const result = value <= inMin ? outMin : outMax;
620
+ if (value < inputRange[0]) {
621
+ const leftMode = extrapolateLeft || extrapolate;
622
+ if (leftMode === "clamp") return toNum(outputRange[0]);
623
+ if (leftMode === "identity") return value;
624
+ }
625
+ if (value > inputRange[inputRange.length - 1]) {
626
+ const rightMode = extrapolateRight || extrapolate;
627
+ if (rightMode === "clamp") return toNum(outputRange[outputRange.length - 1]);
628
+ if (rightMode === "identity") return value;
629
+ }
630
+ return result;
631
+ }
632
+ let t = (value - inMin) / (inMax - inMin);
633
+ if (easing) t = easing(t);
634
+ let result = outMin + t * (outMax - outMin);
635
+ const leftMode = extrapolateLeft || extrapolate;
636
+ const rightMode = extrapolateRight || extrapolate;
637
+ if (value < inputRange[0]) {
638
+ if (leftMode === "clamp") return toNum(outputRange[0]);
639
+ if (leftMode === "identity") return value;
640
+ }
641
+ if (value > inputRange[inputRange.length - 1]) {
642
+ if (rightMode === "clamp") return toNum(outputRange[outputRange.length - 1]);
643
+ if (rightMode === "identity") return value;
644
+ }
645
+ return result;
646
+ }
545
647
  var AnimatedValue = class AnimatedValue {
546
648
  _value;
547
649
  _listeners = /* @__PURE__ */ new Map();
548
650
  _listenerIdCounter = 0;
651
+ _tracking = null;
549
652
  constructor(value = 0) {
550
653
  this._value = value;
551
654
  }
@@ -568,16 +671,9 @@ var AnimatedValue = class AnimatedValue {
568
671
  this._listeners.clear();
569
672
  }
570
673
  interpolate(config) {
571
- const { inputRange, outputRange } = config || {};
674
+ const { inputRange, outputRange, extrapolate = "extend", extrapolateLeft, extrapolateRight, easing } = config || {};
572
675
  if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(this._value);
573
- const val = Math.max(inputRange[0], Math.min(inputRange[inputRange.length - 1], this._value));
574
- let i = 0;
575
- for (; i < inputRange.length - 2; i++) if (val <= inputRange[i + 1]) break;
576
- const inMin = inputRange[i];
577
- const inMax = inputRange[i + 1];
578
- const outMin = typeof outputRange[i] === "number" ? outputRange[i] : parseFloat(outputRange[i]) || 0;
579
- const outMax = typeof outputRange[i + 1] === "number" ? outputRange[i + 1] : parseFloat(outputRange[i + 1]) || 0;
580
- return new AnimatedValue(outMin + (inMax === inMin ? 0 : (val - inMin) / (inMax - inMin)) * (outMax - outMin));
676
+ return new AnimatedValue(interpolateValue(this._value, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing));
581
677
  }
582
678
  stopAnimation(callback) {
583
679
  callback?.(this._value);
@@ -585,6 +681,9 @@ var AnimatedValue = class AnimatedValue {
585
681
  resetAnimation(callback) {
586
682
  callback?.(this._value);
587
683
  }
684
+ toJSON() {
685
+ return this._value;
686
+ }
588
687
  setOffset(_offset) {}
589
688
  flattenOffset() {}
590
689
  extractOffset() {}
@@ -635,33 +734,178 @@ var AnimatedValueXY = class {
635
734
  return [{ translateX: this.x }, { translateY: this.y }];
636
735
  }
637
736
  };
737
+ const namedColorMap = {
738
+ red: [
739
+ 255,
740
+ 0,
741
+ 0,
742
+ 1
743
+ ],
744
+ green: [
745
+ 0,
746
+ 128,
747
+ 0,
748
+ 1
749
+ ],
750
+ blue: [
751
+ 0,
752
+ 0,
753
+ 255,
754
+ 1
755
+ ],
756
+ white: [
757
+ 255,
758
+ 255,
759
+ 255,
760
+ 1
761
+ ],
762
+ black: [
763
+ 0,
764
+ 0,
765
+ 0,
766
+ 1
767
+ ],
768
+ transparent: [
769
+ 0,
770
+ 0,
771
+ 0,
772
+ 0
773
+ ],
774
+ yellow: [
775
+ 255,
776
+ 255,
777
+ 0,
778
+ 1
779
+ ],
780
+ cyan: [
781
+ 0,
782
+ 255,
783
+ 255,
784
+ 1
785
+ ],
786
+ magenta: [
787
+ 255,
788
+ 0,
789
+ 255,
790
+ 1
791
+ ]
792
+ };
793
+ function parseColorString(color) {
794
+ const rgba = color.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/);
795
+ if (rgba) return [
796
+ parseInt(rgba[1]),
797
+ parseInt(rgba[2]),
798
+ parseInt(rgba[3]),
799
+ rgba[4] != null ? parseFloat(rgba[4]) : 1
800
+ ];
801
+ const hex8 = color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
802
+ if (hex8) return [
803
+ parseInt(hex8[1], 16),
804
+ parseInt(hex8[2], 16),
805
+ parseInt(hex8[3], 16),
806
+ parseInt(hex8[4], 16) / 255
807
+ ];
808
+ const hex6 = color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
809
+ if (hex6) return [
810
+ parseInt(hex6[1], 16),
811
+ parseInt(hex6[2], 16),
812
+ parseInt(hex6[3], 16),
813
+ 1
814
+ ];
815
+ const named = namedColorMap[color.toLowerCase()];
816
+ if (named) return named;
817
+ return [
818
+ 0,
819
+ 0,
820
+ 0,
821
+ 1
822
+ ];
823
+ }
638
824
  var AnimatedColor = class {
639
825
  r;
640
826
  g;
641
827
  b;
642
828
  a;
643
- constructor() {
644
- this.r = new AnimatedValue(0);
645
- this.g = new AnimatedValue(0);
646
- this.b = new AnimatedValue(0);
647
- this.a = new AnimatedValue(1);
829
+ _listeners = /* @__PURE__ */ new Map();
830
+ _listenerIdCounter = 0;
831
+ constructor(color) {
832
+ if (typeof color === "string") {
833
+ const [r, g, b, a] = parseColorString(color);
834
+ this.r = new AnimatedValue(r);
835
+ this.g = new AnimatedValue(g);
836
+ this.b = new AnimatedValue(b);
837
+ this.a = new AnimatedValue(a);
838
+ } else if (color && typeof color === "object") if (color.r instanceof AnimatedValue) {
839
+ this.r = color.r;
840
+ this.g = color.g;
841
+ this.b = color.b;
842
+ this.a = color.a;
843
+ } else if (typeof color.r === "number") {
844
+ this.r = new AnimatedValue(color.r);
845
+ this.g = new AnimatedValue(color.g ?? 0);
846
+ this.b = new AnimatedValue(color.b ?? 0);
847
+ this.a = new AnimatedValue(color.a ?? 1);
848
+ } else {
849
+ this.r = new AnimatedValue(0);
850
+ this.g = new AnimatedValue(0);
851
+ this.b = new AnimatedValue(0);
852
+ this.a = new AnimatedValue(1);
853
+ }
854
+ else {
855
+ this.r = new AnimatedValue(0);
856
+ this.g = new AnimatedValue(0);
857
+ this.b = new AnimatedValue(0);
858
+ this.a = new AnimatedValue(1);
859
+ }
860
+ }
861
+ setValue(value) {
862
+ if (typeof value === "string") {
863
+ const [r, g, b, a] = parseColorString(value);
864
+ this.r.setValue(r);
865
+ this.g.setValue(g);
866
+ this.b.setValue(b);
867
+ this.a.setValue(a);
868
+ } else if (value && typeof value === "object" && typeof value.r === "number") {
869
+ this.r.setValue(value.r);
870
+ this.g.setValue(value.g ?? 0);
871
+ this.b.setValue(value.b ?? 0);
872
+ this.a.setValue(value.a ?? 1);
873
+ }
874
+ const colorStr = this.__getValue();
875
+ this._listeners.forEach((fn) => fn({ value: colorStr }));
876
+ }
877
+ __getValue() {
878
+ return `rgba(${Math.round(this.r.getValue())}, ${Math.round(this.g.getValue())}, ${Math.round(this.b.getValue())}, ${this.a.getValue()})`;
879
+ }
880
+ addListener(callback) {
881
+ const id = String(++this._listenerIdCounter);
882
+ this._listeners.set(id, callback);
883
+ return id;
884
+ }
885
+ removeListener(id) {
886
+ this._listeners.delete(id);
887
+ }
888
+ removeAllListeners() {
889
+ this._listeners.clear();
648
890
  }
649
- setValue(_value) {}
650
891
  setOffset(_offset) {}
651
892
  flattenOffset() {}
652
893
  stopAnimation(callback) {
653
- callback?.(0);
894
+ callback?.(this.__getValue());
654
895
  }
655
896
  resetAnimation(callback) {
656
- callback?.(0);
897
+ callback?.(this.__getValue());
657
898
  }
658
899
  };
659
- function createAnimation() {
900
+ function createAnimation(onStart) {
660
901
  return {
661
902
  start: vi.fn((callback) => {
903
+ onStart?.();
662
904
  callback?.({ finished: true });
663
905
  }),
664
- stop: vi.fn(),
906
+ stop: vi.fn((callback) => {
907
+ callback?.({ finished: false });
908
+ }),
665
909
  reset: vi.fn()
666
910
  };
667
911
  }
@@ -675,19 +919,188 @@ function createAnimatedWrapper(displayName) {
675
919
  Component.displayName = displayName;
676
920
  return Component;
677
921
  }
922
+ function stopTracking(value) {
923
+ if (value._tracking) {
924
+ value._tracking.source.removeListener(value._tracking.listenerId);
925
+ value._tracking = null;
926
+ }
927
+ }
928
+ function startTracking(value, toValue) {
929
+ stopTracking(value);
930
+ if (toValue instanceof AnimatedValue) {
931
+ value.setValue(toValue.getValue());
932
+ value._tracking = {
933
+ source: toValue,
934
+ listenerId: toValue.addListener(({ value: v }) => {
935
+ value.setValue(v);
936
+ })
937
+ };
938
+ } else value.setValue(toValue);
939
+ }
678
940
  function createAnimatedMock() {
679
941
  return {
680
942
  Value: AnimatedValue,
681
943
  ValueXY: AnimatedValueXY,
682
944
  Color: AnimatedColor,
683
- timing: vi.fn((_value, _config) => createAnimation()),
684
- spring: vi.fn((_value, _config) => createAnimation()),
945
+ timing: vi.fn((value, config) => {
946
+ return createAnimation(() => {
947
+ if (value instanceof AnimatedValue && config?.toValue != null) startTracking(value, config.toValue);
948
+ });
949
+ }),
950
+ spring: vi.fn((value, config) => {
951
+ return createAnimation(() => {
952
+ if (value instanceof AnimatedValue && config?.toValue != null) startTracking(value, config.toValue);
953
+ });
954
+ }),
685
955
  decay: vi.fn((_value, _config) => createAnimation()),
686
- sequence: vi.fn((_animations) => createAnimation()),
687
- parallel: vi.fn((_animations) => createAnimation()),
688
- stagger: vi.fn((_time, _animations) => createAnimation()),
689
- loop: vi.fn((_animation, _config) => createAnimation()),
690
- delay: vi.fn((_time) => createAnimation()),
956
+ sequence: vi.fn((animations) => {
957
+ let current = 0;
958
+ let cb;
959
+ return {
960
+ start: vi.fn((endCallback) => {
961
+ cb = endCallback;
962
+ if (animations.length === 0) {
963
+ cb?.({ finished: true });
964
+ return;
965
+ }
966
+ if (current >= animations.length) current = 0;
967
+ const runNext = (result) => {
968
+ if (!result.finished) {
969
+ cb?.({ finished: false });
970
+ return;
971
+ }
972
+ current++;
973
+ if (current >= animations.length) {
974
+ cb?.({ finished: true });
975
+ return;
976
+ }
977
+ animations[current]?.start(runNext);
978
+ };
979
+ animations[current]?.start(runNext);
980
+ }),
981
+ stop: vi.fn(() => {
982
+ if (current < animations.length) animations[current]?.stop?.();
983
+ }),
984
+ reset: vi.fn(() => {
985
+ current = 0;
986
+ for (const anim of animations) anim?.reset?.();
987
+ })
988
+ };
989
+ }),
990
+ parallel: vi.fn((animations) => {
991
+ let doneCount = 0;
992
+ let hasBeenStopped = false;
993
+ let cb;
994
+ const validAnims = animations.filter(Boolean);
995
+ return {
996
+ start: vi.fn((endCallback) => {
997
+ cb = endCallback;
998
+ doneCount = 0;
999
+ hasBeenStopped = false;
1000
+ if (validAnims.length === 0) {
1001
+ cb?.({ finished: true });
1002
+ return;
1003
+ }
1004
+ validAnims.forEach((anim) => {
1005
+ anim.start((result) => {
1006
+ doneCount++;
1007
+ if (!result.finished && !hasBeenStopped) {
1008
+ hasBeenStopped = true;
1009
+ validAnims.forEach((other) => {
1010
+ if (other !== anim) other.stop?.();
1011
+ });
1012
+ }
1013
+ if (doneCount >= validAnims.length) cb?.(result);
1014
+ });
1015
+ });
1016
+ }),
1017
+ stop: vi.fn(() => {
1018
+ hasBeenStopped = true;
1019
+ validAnims.forEach((anim) => {
1020
+ anim.stop?.();
1021
+ });
1022
+ }),
1023
+ reset: vi.fn(() => {
1024
+ for (const anim of validAnims) anim?.reset?.();
1025
+ })
1026
+ };
1027
+ }),
1028
+ stagger: vi.fn((_time, animations) => {
1029
+ const validAnims = animations.filter(Boolean);
1030
+ let doneCount = 0;
1031
+ let hasBeenStopped = false;
1032
+ return {
1033
+ start: vi.fn((endCallback) => {
1034
+ doneCount = 0;
1035
+ hasBeenStopped = false;
1036
+ if (validAnims.length === 0) {
1037
+ endCallback?.({ finished: true });
1038
+ return;
1039
+ }
1040
+ validAnims.forEach((anim) => {
1041
+ anim.start?.((result) => {
1042
+ doneCount++;
1043
+ if (!result.finished && !hasBeenStopped) {
1044
+ hasBeenStopped = true;
1045
+ validAnims.forEach((other) => {
1046
+ if (other !== anim) other.stop?.();
1047
+ });
1048
+ }
1049
+ if (doneCount >= validAnims.length) endCallback?.(result);
1050
+ });
1051
+ });
1052
+ }),
1053
+ stop: vi.fn(() => {
1054
+ hasBeenStopped = true;
1055
+ validAnims.forEach((anim) => anim.stop?.());
1056
+ }),
1057
+ reset: vi.fn(() => {
1058
+ validAnims.forEach((anim) => anim.reset?.());
1059
+ })
1060
+ };
1061
+ }),
1062
+ loop: vi.fn((animation, config) => {
1063
+ const iterations = config?.iterations;
1064
+ const resetBeforeIteration = config?.resetBeforeIteration !== false;
1065
+ let stopped = false;
1066
+ let startCallback;
1067
+ return {
1068
+ start: vi.fn((endCallback) => {
1069
+ stopped = false;
1070
+ startCallback = endCallback;
1071
+ if (iterations === 0) {
1072
+ endCallback?.({ finished: true });
1073
+ return;
1074
+ }
1075
+ let iterationCount = 0;
1076
+ const onIteration = (result) => {
1077
+ if (stopped || !result.finished) {
1078
+ startCallback?.(result);
1079
+ return;
1080
+ }
1081
+ iterationCount++;
1082
+ if (iterations != null && iterations > 0 && iterationCount >= iterations) {
1083
+ startCallback?.({ finished: true });
1084
+ return;
1085
+ }
1086
+ if (resetBeforeIteration) animation.reset?.();
1087
+ animation.start(onIteration);
1088
+ };
1089
+ if (resetBeforeIteration) animation.reset?.();
1090
+ animation.start(onIteration);
1091
+ }),
1092
+ stop: vi.fn(() => {
1093
+ stopped = true;
1094
+ animation.stop?.();
1095
+ }),
1096
+ reset: vi.fn(() => {
1097
+ animation.reset?.();
1098
+ })
1099
+ };
1100
+ }),
1101
+ delay: vi.fn((_time) => {
1102
+ return createAnimation();
1103
+ }),
691
1104
  add: vi.fn((a, b) => {
692
1105
  return new AnimatedValue((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) + (b instanceof AnimatedValue ? b.getValue() : typeof b === "number" ? b : 0));
693
1106
  }),
@@ -706,11 +1119,44 @@ function createAnimatedMock() {
706
1119
  return new AnimatedValue(((a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0) % modulus + modulus) % modulus);
707
1120
  }),
708
1121
  diffClamp: vi.fn((a, min, max) => {
709
- const aVal = a instanceof AnimatedValue ? a.getValue() : typeof a === "number" ? a : 0;
710
- return new AnimatedValue(Math.min(Math.max(aVal, min), max));
1122
+ const result = new AnimatedValue(Math.min(Math.max(a instanceof AnimatedValue ? a.getValue() : 0, min), max));
1123
+ if (a instanceof AnimatedValue) {
1124
+ let lastInput = a.getValue();
1125
+ let current = result.getValue();
1126
+ a.addListener(({ value }) => {
1127
+ const diff = value - lastInput;
1128
+ lastInput = value;
1129
+ current = Math.min(Math.max(current + diff, min), max);
1130
+ result.setValue(current);
1131
+ });
1132
+ }
1133
+ return result;
1134
+ }),
1135
+ event: vi.fn((argMapping, config) => {
1136
+ const handler = vi.fn((...args) => {
1137
+ argMapping.forEach((mapping, index) => {
1138
+ if (mapping && args[index]) traverseMapping(mapping, args[index]);
1139
+ });
1140
+ config?.listener?.(...args);
1141
+ });
1142
+ function traverseMapping(mapping, value) {
1143
+ if (mapping instanceof AnimatedValue && typeof value === "number") {
1144
+ mapping.setValue(value);
1145
+ return;
1146
+ }
1147
+ if (typeof mapping === "object" && mapping !== null && typeof value === "object" && value !== null) {
1148
+ for (const key of Object.keys(mapping)) if (key in value) traverseMapping(mapping[key], value[key]);
1149
+ }
1150
+ }
1151
+ return handler;
1152
+ }),
1153
+ forkEvent: vi.fn((handler, listener) => {
1154
+ return (...args) => {
1155
+ if (typeof handler === "function") handler(...args);
1156
+ else if (handler && handler.__isNative) {}
1157
+ listener(...args);
1158
+ };
711
1159
  }),
712
- event: vi.fn((_argMapping, _config) => vi.fn()),
713
- forkEvent: vi.fn(),
714
1160
  unforkEvent: vi.fn(),
715
1161
  createAnimatedComponent: vi.fn((component) => {
716
1162
  const Wrapper = React.forwardRef((props, ref) => {
@@ -934,12 +1380,17 @@ function createAppearanceMock() {
934
1380
  }
935
1381
  //#endregion
936
1382
  //#region src/mocks/apis/PixelRatio.ts
937
- function createPixelRatioMock() {
1383
+ function createPixelRatioMock(getDimensions) {
1384
+ const getScale = () => getDimensions ? getDimensions().scale : 3;
1385
+ const getFontScale = () => getDimensions ? getDimensions().fontScale : 1;
938
1386
  return {
939
- get: vi.fn(() => 3),
940
- getFontScale: vi.fn(() => 1),
941
- getPixelSizeForLayoutSize: vi.fn((layoutSize) => Math.round(layoutSize * 3)),
942
- roundToNearestPixel: vi.fn((layoutSize) => Math.round(layoutSize * 3) / 3)
1387
+ get: vi.fn(() => getScale()),
1388
+ getFontScale: vi.fn(() => getFontScale()),
1389
+ getPixelSizeForLayoutSize: vi.fn((layoutSize) => Math.round(layoutSize * getScale())),
1390
+ roundToNearestPixel: vi.fn((layoutSize) => {
1391
+ const ratio = getScale();
1392
+ return Math.round(layoutSize * ratio) / ratio;
1393
+ })
943
1394
  };
944
1395
  }
945
1396
  //#endregion
@@ -1125,10 +1576,79 @@ function createLogBoxMock() {
1125
1576
  }
1126
1577
  //#endregion
1127
1578
  //#region src/mocks/apis/Easing.ts
1579
+ const NEWTON_ITERATIONS = 4;
1580
+ const NEWTON_MIN_SLOPE = .001;
1581
+ const SUBDIVISION_PRECISION = 1e-7;
1582
+ const SUBDIVISION_MAX_ITERATIONS = 10;
1583
+ const kSplineTableSize = 11;
1584
+ const kSampleStepSize = 1 / (kSplineTableSize - 1);
1585
+ function A(aA1, aA2) {
1586
+ return 1 - 3 * aA2 + 3 * aA1;
1587
+ }
1588
+ function B(aA1, aA2) {
1589
+ return 3 * aA2 - 6 * aA1;
1590
+ }
1591
+ function C(aA1) {
1592
+ return 3 * aA1;
1593
+ }
1594
+ function calcBezier(aT, aA1, aA2) {
1595
+ return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
1596
+ }
1597
+ function getSlope(aT, aA1, aA2) {
1598
+ return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
1599
+ }
1600
+ function binarySubdivide(aX, aA, aB, mX1, mX2) {
1601
+ let currentX;
1602
+ let currentT;
1603
+ let i = 0;
1604
+ let low = aA;
1605
+ let high = aB;
1606
+ do {
1607
+ currentT = low + (high - low) / 2;
1608
+ currentX = calcBezier(currentT, mX1, mX2) - aX;
1609
+ if (currentX > 0) high = currentT;
1610
+ else low = currentT;
1611
+ } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
1612
+ return currentT;
1613
+ }
1614
+ function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
1615
+ let guessT = aGuessT;
1616
+ for (let i = 0; i < NEWTON_ITERATIONS; ++i) {
1617
+ const currentSlope = getSlope(guessT, mX1, mX2);
1618
+ if (currentSlope === 0) return guessT;
1619
+ const currentX = calcBezier(guessT, mX1, mX2) - aX;
1620
+ guessT -= currentX / currentSlope;
1621
+ }
1622
+ return guessT;
1623
+ }
1624
+ function bezier(mX1, mY1, mX2, mY2) {
1625
+ if (!(mX1 >= 0 && mX1 <= 1 && mX2 >= 0 && mX2 <= 1)) throw new Error("bezier x values must be in [0, 1] range");
1626
+ if (mX1 === mY1 && mX2 === mY2) return (x) => x;
1627
+ const sampleValues = new Float32Array(kSplineTableSize);
1628
+ for (let i = 0; i < kSplineTableSize; ++i) sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
1629
+ function getTForX(aX) {
1630
+ let intervalStart = 0;
1631
+ let currentSample = 1;
1632
+ const lastSample = kSplineTableSize - 1;
1633
+ for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) intervalStart += kSampleStepSize;
1634
+ --currentSample;
1635
+ const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
1636
+ const guessForT = intervalStart + dist * kSampleStepSize;
1637
+ const initialSlope = getSlope(guessForT, mX1, mX2);
1638
+ if (initialSlope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
1639
+ else if (initialSlope === 0) return guessForT;
1640
+ else return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
1641
+ }
1642
+ return function(x) {
1643
+ if (x === 0 || x === 1) return x;
1644
+ return calcBezier(getTForX(x), mY1, mY2);
1645
+ };
1646
+ }
1128
1647
  function createEasingMock() {
1648
+ const easeFn = bezier(.42, 0, 1, 1);
1129
1649
  return {
1130
1650
  linear: vi.fn((t) => t),
1131
- ease: vi.fn((t) => t * t * (3 - 2 * t)),
1651
+ ease: vi.fn((t) => easeFn(t)),
1132
1652
  quad: vi.fn((t) => t * t),
1133
1653
  cubic: vi.fn((t) => t * t * t),
1134
1654
  poly: vi.fn((n) => (t) => Math.pow(t, n)),
@@ -1143,21 +1663,17 @@ function createEasingMock() {
1143
1663
  bounce: vi.fn((t) => {
1144
1664
  if (t < 1 / 2.75) return 7.5625 * t * t;
1145
1665
  if (t < 2 / 2.75) {
1146
- t -= 1.5 / 2.75;
1147
- return 7.5625 * t * t + .75;
1666
+ const t2 = t - 1.5 / 2.75;
1667
+ return 7.5625 * t2 * t2 + .75;
1148
1668
  }
1149
1669
  if (t < 2.5 / 2.75) {
1150
- t -= 2.25 / 2.75;
1151
- return 7.5625 * t * t + .9375;
1670
+ const t2 = t - 2.25 / 2.75;
1671
+ return 7.5625 * t2 * t2 + .9375;
1152
1672
  }
1153
- t -= 2.625 / 2.75;
1154
- return 7.5625 * t * t + .984375;
1155
- }),
1156
- bezier: vi.fn((x1, _y1, x2, _y2) => (t) => {
1157
- const cx = 3 * x1;
1158
- const bx = 3 * (x2 - x1) - cx;
1159
- return (((1 - cx - bx) * t + bx) * t + cx) * t;
1673
+ const t2 = t - 2.625 / 2.75;
1674
+ return 7.5625 * t2 * t2 + .984375;
1160
1675
  }),
1676
+ bezier: vi.fn((x1, y1, x2, y2) => bezier(x1, y1, x2, y2)),
1161
1677
  in: vi.fn((easing) => easing),
1162
1678
  out: vi.fn((easing) => (t) => 1 - easing(1 - t)),
1163
1679
  inOut: vi.fn((easing) => (t) => {
@@ -1288,27 +1804,42 @@ function createUseWindowDimensionsMock() {
1288
1804
  //#endregion
1289
1805
  //#region src/mocks/native/NativeModules.ts
1290
1806
  /**
1291
- * Creates a recursive proxy that returns no-op functions for any property access.
1292
- * This ensures NativeModules.Foo.bar() works without throwing TypeError,
1293
- * and NativeModules.Foo.bar.baz() also works (arbitrary depth).
1294
- *
1295
- * Property accesses are cached so that NativeModules.Foo === NativeModules.Foo
1296
- * holds true, matching real React Native identity semantics.
1807
+ * Creates a callable proxy — used for module methods.
1808
+ * Calling it returns undefined; accessing properties returns another
1809
+ * callable proxy (supporting arbitrary depth like Foo.bar.baz()).
1297
1810
  */
1298
- function createModuleProxy$1() {
1811
+ function createCallableProxy() {
1299
1812
  const cache = /* @__PURE__ */ new Map();
1300
1813
  const noop = () => {};
1301
1814
  return new Proxy(noop, {
1302
1815
  get(_target, prop) {
1303
1816
  if (typeof prop === "symbol") return void 0;
1304
1817
  if (cache.has(prop)) return cache.get(prop);
1305
- const child = createModuleProxy$1();
1818
+ const child = createCallableProxy();
1306
1819
  cache.set(prop, child);
1307
1820
  return child;
1308
1821
  },
1309
1822
  apply() {}
1310
1823
  });
1311
1824
  }
1825
+ /**
1826
+ * Creates an object proxy for a native module.
1827
+ * typeof returns "object" (matching real RN), property access returns
1828
+ * callable proxies so NativeModules.Foo.bar() works without throwing.
1829
+ *
1830
+ * Property accesses are cached so that NativeModules.Foo === NativeModules.Foo
1831
+ * holds true, matching real React Native identity semantics.
1832
+ */
1833
+ function createModuleProxy$1() {
1834
+ const cache = /* @__PURE__ */ new Map();
1835
+ return new Proxy({}, { get(_target, prop) {
1836
+ if (typeof prop === "symbol") return void 0;
1837
+ if (cache.has(prop)) return cache.get(prop);
1838
+ const child = createCallableProxy();
1839
+ cache.set(prop, child);
1840
+ return child;
1841
+ } });
1842
+ }
1312
1843
  function createNativeModulesMock() {
1313
1844
  const cache = /* @__PURE__ */ new Map();
1314
1845
  return new Proxy({}, { get(_target, prop) {
@@ -1440,10 +1971,96 @@ function createAppRegistryMock() {
1440
1971
  cancelHeadlessTask: vi.fn()
1441
1972
  };
1442
1973
  }
1974
+ function hslToRgb(h, s, l) {
1975
+ const sNorm = s / 100;
1976
+ const lNorm = l / 100;
1977
+ const c = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
1978
+ const hPrime = h / 60;
1979
+ const x = c * (1 - Math.abs(hPrime % 2 - 1));
1980
+ let r1 = 0, g1 = 0, b1 = 0;
1981
+ if (hPrime < 1) {
1982
+ r1 = c;
1983
+ g1 = x;
1984
+ } else if (hPrime < 2) {
1985
+ r1 = x;
1986
+ g1 = c;
1987
+ } else if (hPrime < 3) {
1988
+ g1 = c;
1989
+ b1 = x;
1990
+ } else if (hPrime < 4) {
1991
+ g1 = x;
1992
+ b1 = c;
1993
+ } else if (hPrime < 5) {
1994
+ r1 = x;
1995
+ b1 = c;
1996
+ } else {
1997
+ r1 = c;
1998
+ b1 = x;
1999
+ }
2000
+ const m = lNorm - c / 2;
2001
+ return [
2002
+ Math.round((r1 + m) * 255),
2003
+ Math.round((g1 + m) * 255),
2004
+ Math.round((b1 + m) * 255)
2005
+ ];
2006
+ }
1443
2007
  function createProcessColorMock() {
2008
+ const namedColors = {
2009
+ red: 4294901760,
2010
+ green: 4278222848,
2011
+ blue: 4278190335,
2012
+ white: 4294967295,
2013
+ black: 4278190080,
2014
+ transparent: 0,
2015
+ yellow: 4294967040,
2016
+ cyan: 4278255615,
2017
+ magenta: 4294902015,
2018
+ orange: 4294944e3,
2019
+ purple: 4286578816,
2020
+ gray: 4286611584,
2021
+ grey: 4286611584
2022
+ };
1444
2023
  return vi.fn((color) => {
1445
2024
  if (color == null) return null;
1446
2025
  if (typeof color === "number") return color;
2026
+ if (typeof color === "string") {
2027
+ const lower = color.toLowerCase().trim();
2028
+ if (namedColors[lower] != null) return namedColors[lower];
2029
+ const hex6 = lower.match(/^#([0-9a-f]{6})$/);
2030
+ if (hex6) return 4278190080 + parseInt(hex6[1], 16) >>> 0;
2031
+ const hex3 = lower.match(/^#([0-9a-f]{3})$/);
2032
+ if (hex3) {
2033
+ const [r, g, b] = hex3[1].split("");
2034
+ return 4278190080 + parseInt(`${r}${r}${g}${g}${b}${b}`, 16) >>> 0;
2035
+ }
2036
+ const hex8 = lower.match(/^#([0-9a-f]{8})$/);
2037
+ if (hex8) {
2038
+ const rgb = parseInt(hex8[1].slice(0, 6), 16);
2039
+ return (parseInt(hex8[1].slice(6, 8), 16) << 24) + rgb >>> 0;
2040
+ }
2041
+ const rgbMatch = lower.match(/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/);
2042
+ if (rgbMatch) {
2043
+ const [, r, g, b] = rgbMatch;
2044
+ return (255 << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b) >>> 0;
2045
+ }
2046
+ const rgbaMatch = lower.match(/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d.]+)\s*\)$/);
2047
+ if (rgbaMatch) {
2048
+ const [, r, g, b, a] = rgbaMatch;
2049
+ return (Math.round(parseFloat(a) * 255) << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b) >>> 0;
2050
+ }
2051
+ const hslMatch = lower.match(/^hsl\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*\)$/);
2052
+ if (hslMatch) {
2053
+ const [, h, s, l] = hslMatch;
2054
+ const [r, g, b] = hslToRgb(parseFloat(h), parseFloat(s), parseFloat(l));
2055
+ return (255 << 24) + (r << 16) + (g << 8) + b >>> 0;
2056
+ }
2057
+ const hslaMatch = lower.match(/^hsla\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*,\s*([\d.]+)\s*\)$/);
2058
+ if (hslaMatch) {
2059
+ const [, h, s, l, a] = hslaMatch;
2060
+ const [r, g, b] = hslToRgb(parseFloat(h), parseFloat(s), parseFloat(l));
2061
+ return (Math.round(parseFloat(a) * 255) << 24) + (r << 16) + (g << 8) + b >>> 0;
2062
+ }
2063
+ }
1447
2064
  return 4278190080;
1448
2065
  });
1449
2066
  }
@@ -1555,7 +2172,7 @@ function buildReactNativeMock(platform = "ios") {
1555
2172
  Vibration: createVibrationMock(),
1556
2173
  PermissionsAndroid: createPermissionsAndroidMock(),
1557
2174
  Appearance: createAppearanceMock(),
1558
- PixelRatio: createPixelRatioMock(),
2175
+ PixelRatio: void 0,
1559
2176
  LayoutAnimation: createLayoutAnimationMock(),
1560
2177
  Clipboard: createClipboardMock(),
1561
2178
  Share: createShareMock(),
@@ -1645,6 +2262,17 @@ function buildReactNativeMock(platform = "ios") {
1645
2262
  usePressability: vi.fn(() => ({})),
1646
2263
  default: void 0
1647
2264
  };
2265
+ mock.PixelRatio = createPixelRatioMock(() => mock.Dimensions.get("window"));
2266
+ const origSetColorScheme = mock.Appearance.setColorScheme;
2267
+ mock.Appearance.setColorScheme = vi.fn((scheme) => {
2268
+ origSetColorScheme(scheme);
2269
+ mock.useColorScheme._setScheme(scheme);
2270
+ });
2271
+ const origDimensionsSet = mock.Dimensions.set;
2272
+ mock.Dimensions.set = vi.fn((dims) => {
2273
+ origDimensionsSet(dims);
2274
+ if (dims.window) mock.useWindowDimensions._setDimensions(dims.window);
2275
+ });
1648
2276
  mock.default = mock;
1649
2277
  return mock;
1650
2278
  }
@@ -1668,6 +2296,7 @@ function buildReactNativeMock(platform = "ios") {
1668
2296
  const VIRTUAL_RN_PATH = "\0vitest-native:react-native";
1669
2297
  let originalResolveFilename = null;
1670
2298
  let installed = false;
2299
+ const presetRedirects = /* @__PURE__ */ new Map();
1671
2300
  function installCjsBridge(mockObject) {
1672
2301
  if (installed) return;
1673
2302
  try {
@@ -1680,8 +2309,15 @@ function installCjsBridge(mockObject) {
1680
2309
  Module._cache[VIRTUAL_RN_PATH] = syntheticModule;
1681
2310
  originalResolveFilename = Module._resolveFilename;
1682
2311
  Module._resolveFilename = function(request, parent, isMain, options) {
1683
- if (request === "react-native") return VIRTUAL_RN_PATH;
1684
- if (request.startsWith("react-native/")) return VIRTUAL_RN_PATH;
2312
+ if (request === "react-native" || request.startsWith("react-native/")) return VIRTUAL_RN_PATH;
2313
+ const exactMatch = presetRedirects.get(request);
2314
+ if (exactMatch) return exactMatch;
2315
+ const slashIdx = request.indexOf("/", request.startsWith("@") ? request.indexOf("/") + 1 : 0);
2316
+ if (slashIdx !== -1) {
2317
+ const pkg = request.slice(0, slashIdx);
2318
+ const subpathMatch = presetRedirects.get(pkg);
2319
+ if (subpathMatch) return subpathMatch;
2320
+ }
1685
2321
  return originalResolveFilename.call(this, request, parent, isMain, options);
1686
2322
  };
1687
2323
  installed = true;
@@ -1698,6 +2334,8 @@ function uninstallCjsBridge() {
1698
2334
  originalResolveFilename = null;
1699
2335
  }
1700
2336
  delete Module._cache[VIRTUAL_RN_PATH];
2337
+ for (const virtualPath of presetRedirects.values()) delete Module._cache[virtualPath];
2338
+ presetRedirects.clear();
1701
2339
  installed = false;
1702
2340
  } catch (e) {
1703
2341
  if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] CJS bridge uninstall failed: ${e?.message}`);
@@ -1713,11 +2351,7 @@ function installPresetCjsBridge(moduleName, mockObject) {
1713
2351
  syntheticModule.loaded = true;
1714
2352
  syntheticModule.exports = mockObject;
1715
2353
  Module._cache[virtualPath] = syntheticModule;
1716
- const currentResolve = Module._resolveFilename;
1717
- Module._resolveFilename = function(request, parent, isMain, options) {
1718
- if (request === moduleName || request.startsWith(`${moduleName}/`)) return virtualPath;
1719
- return currentResolve.call(this, request, parent, isMain, options);
1720
- };
2354
+ presetRedirects.set(moduleName, virtualPath);
1721
2355
  } catch (e) {
1722
2356
  if (process.env.VITEST_NATIVE_DIAGNOSTICS === "true") console.warn(`[vitest-native] Preset CJS bridge for ${moduleName} failed: ${e?.message}`);
1723
2357
  }
@@ -1802,9 +2436,9 @@ function loadPresetFactory(exportName) {
1802
2436
  return typeof factory === "function" ? factory : null;
1803
2437
  }
1804
2438
  function autoDetectPresets() {
1805
- const detected = [];
1806
2439
  const projectRoot = process.env.VITEST_NATIVE_PROJECT_ROOT || process.cwd();
1807
2440
  const projectReq = createRequire(path.join(projectRoot, "package.json"));
2441
+ const detected = [];
1808
2442
  for (const [pkgName, exportName] of Object.entries(AUTO_DETECT_PRESETS)) try {
1809
2443
  projectReq.resolve(pkgName);
1810
2444
  const factory = loadPresetFactory(exportName);
@@ -1836,8 +2470,8 @@ try {
1836
2470
  if (rntl?.configure) rntl.configure({ hostComponentNames: {
1837
2471
  text: "Text",
1838
2472
  textInput: "TextInput",
1839
- switch: "Switch",
1840
- scrollView: "ScrollView",
2473
+ switch: "RCTSwitch",
2474
+ scrollView: "RCTScrollView",
1841
2475
  modal: "Modal",
1842
2476
  image: "Image",
1843
2477
  button: "Button",