vitest-native 0.3.0 → 0.4.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 +72 -0
- package/README.md +240 -11
- package/dist/chunk-CZWwpsFl.cjs +43 -0
- package/dist/{index-CJqS-y_M.d.cts → index-CJIhukN_.d.mts} +58 -4
- package/dist/{index-h4vpIkQO.d.mts → index-DEB7OFaJ.d.cts} +60 -2
- package/dist/index.cjs +252 -21
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +248 -18
- package/dist/jest-compat/interop.mjs +30 -0
- package/dist/jest-compat/jest-globals.d.mts +3 -0
- package/dist/jest-compat/jest-globals.mjs +9 -0
- package/dist/jest-compat/noop.d.mts +3 -0
- package/dist/jest-compat/noop.mjs +7 -0
- package/dist/jest-compat/setup.d.mts +3 -0
- package/dist/jest-compat/setup.mjs +41 -0
- package/dist/jest-compat.cjs +109 -0
- package/dist/jest-compat.d.cts +38 -0
- package/dist/jest-compat.d.mts +38 -0
- package/dist/jest-compat.mjs +104 -0
- package/dist/matchers.cjs +69 -0
- package/dist/matchers.d.cts +51 -0
- package/dist/matchers.d.mts +51 -0
- package/dist/matchers.mjs +66 -0
- package/dist/native/boundary.mjs +225 -0
- package/dist/native/globals.mjs +112 -0
- package/dist/native/hooks.mjs +85 -0
- package/dist/native/loader.mjs +123 -0
- package/dist/native/match.mjs +9 -0
- package/dist/native/reset.mjs +170 -0
- package/dist/native/resolve.mjs +22 -0
- package/dist/native/runner.mjs +18 -0
- package/dist/native/setup.mjs +134 -0
- package/dist/native/transform.mjs +79 -0
- package/dist/native/worker.mjs +96 -0
- package/dist/pool-B4mWN3N5.cjs +60 -0
- package/dist/pool-oPTZiSXU.mjs +58 -0
- package/dist/{preset-map-DxU6UgYS.cjs → preset-map-C3jxnkiX.cjs} +5 -1
- package/dist/{preset-map-BTpoNH3G.mjs → preset-map-OJm5IWuL.mjs} +5 -1
- package/dist/{presets-B-spxZz7.cjs → presets-2I68Ipyl.cjs} +437 -41
- package/dist/{presets-DvrcfEPz.mjs → presets-DOGXQzYT.mjs} +401 -6
- package/dist/presets.cjs +5 -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 +263 -115
- package/dist/setup.mjs +259 -112
- package/docs/migrating-from-jest.md +123 -0
- package/docs/migrating-from-vitest-react-native.md +109 -0
- package/package.json +65 -9
package/dist/setup.cjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_preset_map = require("./preset-map-
|
|
1
|
+
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
|
+
const require_preset_map = require("./preset-map-C3jxnkiX.cjs");
|
|
3
|
+
const require_presets = require("./presets-2I68Ipyl.cjs");
|
|
3
4
|
const require_serializer = require("./serializer.cjs");
|
|
5
|
+
const require_matchers = require("./matchers.cjs");
|
|
4
6
|
let node_path = require("node:path");
|
|
5
|
-
node_path =
|
|
7
|
+
node_path = require_chunk.__toESM(node_path);
|
|
6
8
|
let node_module = require("node:module");
|
|
7
9
|
let vitest = require("vitest");
|
|
8
10
|
let react = require("react");
|
|
9
|
-
react =
|
|
11
|
+
react = require_chunk.__toESM(react);
|
|
10
12
|
//#region src/mocks/components/View.ts
|
|
11
13
|
function createViewMock() {
|
|
12
14
|
const View = react.default.forwardRef((props, ref) => {
|
|
@@ -216,78 +218,23 @@ function createModalMock() {
|
|
|
216
218
|
return Modal;
|
|
217
219
|
}
|
|
218
220
|
//#endregion
|
|
219
|
-
//#region src/mocks/components/Pressable.ts
|
|
220
|
-
function createPressableMock() {
|
|
221
|
-
const Pressable = react.default.forwardRef((props, ref) => {
|
|
222
|
-
const { disabled, accessibilityState, ...rest } = props;
|
|
223
|
-
const mergedA11yState = disabled || accessibilityState ? {
|
|
224
|
-
...accessibilityState,
|
|
225
|
-
...disabled ? { disabled: true } : {}
|
|
226
|
-
} : void 0;
|
|
227
|
-
return react.default.createElement("Pressable", {
|
|
228
|
-
accessible: true,
|
|
229
|
-
...rest,
|
|
230
|
-
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
231
|
-
ref
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
Pressable.displayName = "Pressable";
|
|
235
|
-
return Pressable;
|
|
236
|
-
}
|
|
237
|
-
//#endregion
|
|
238
221
|
//#region src/mocks/components/TouchableOpacity.ts
|
|
239
222
|
function createTouchableOpacityMock() {
|
|
240
|
-
const TouchableOpacity = react.default.forwardRef((props, ref) =>
|
|
241
|
-
const { disabled, accessibilityState, ...rest } = props;
|
|
242
|
-
const mergedA11yState = disabled || accessibilityState ? {
|
|
243
|
-
...accessibilityState,
|
|
244
|
-
...disabled ? { disabled: true } : {}
|
|
245
|
-
} : void 0;
|
|
246
|
-
return react.default.createElement("TouchableOpacity", {
|
|
247
|
-
accessible: true,
|
|
248
|
-
...rest,
|
|
249
|
-
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
250
|
-
ref
|
|
251
|
-
});
|
|
252
|
-
});
|
|
223
|
+
const TouchableOpacity = react.default.forwardRef((props, ref) => react.default.createElement("TouchableOpacity", require_presets.buildPressableHostProps(props, ref)));
|
|
253
224
|
TouchableOpacity.displayName = "TouchableOpacity";
|
|
254
225
|
return TouchableOpacity;
|
|
255
226
|
}
|
|
256
227
|
//#endregion
|
|
257
228
|
//#region src/mocks/components/TouchableHighlight.ts
|
|
258
229
|
function createTouchableHighlightMock() {
|
|
259
|
-
const TouchableHighlight = react.default.forwardRef((props, ref) =>
|
|
260
|
-
const { disabled, accessibilityState, ...rest } = props;
|
|
261
|
-
const mergedA11yState = disabled || accessibilityState ? {
|
|
262
|
-
...accessibilityState,
|
|
263
|
-
...disabled ? { disabled: true } : {}
|
|
264
|
-
} : void 0;
|
|
265
|
-
return react.default.createElement("TouchableHighlight", {
|
|
266
|
-
accessible: true,
|
|
267
|
-
...rest,
|
|
268
|
-
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
269
|
-
ref
|
|
270
|
-
});
|
|
271
|
-
});
|
|
230
|
+
const TouchableHighlight = react.default.forwardRef((props, ref) => react.default.createElement("TouchableHighlight", require_presets.buildPressableHostProps(props, ref)));
|
|
272
231
|
TouchableHighlight.displayName = "TouchableHighlight";
|
|
273
232
|
return TouchableHighlight;
|
|
274
233
|
}
|
|
275
234
|
//#endregion
|
|
276
235
|
//#region src/mocks/components/TouchableWithoutFeedback.ts
|
|
277
236
|
function createTouchableWithoutFeedbackMock() {
|
|
278
|
-
const TouchableWithoutFeedback = react.default.forwardRef((props, ref) =>
|
|
279
|
-
const { disabled, accessibilityState, ...rest } = props;
|
|
280
|
-
const mergedA11yState = disabled || accessibilityState ? {
|
|
281
|
-
...accessibilityState,
|
|
282
|
-
...disabled ? { disabled: true } : {}
|
|
283
|
-
} : void 0;
|
|
284
|
-
return react.default.createElement("TouchableWithoutFeedback", {
|
|
285
|
-
accessible: true,
|
|
286
|
-
...rest,
|
|
287
|
-
...mergedA11yState ? { accessibilityState: mergedA11yState } : {},
|
|
288
|
-
ref
|
|
289
|
-
});
|
|
290
|
-
});
|
|
237
|
+
const TouchableWithoutFeedback = react.default.forwardRef((props, ref) => react.default.createElement("TouchableWithoutFeedback", require_presets.buildPressableHostProps(props, ref)));
|
|
291
238
|
TouchableWithoutFeedback.displayName = "TouchableWithoutFeedback";
|
|
292
239
|
return TouchableWithoutFeedback;
|
|
293
240
|
}
|
|
@@ -300,6 +247,12 @@ function createTouchableNativeFeedbackMock() {
|
|
|
300
247
|
...accessibilityState,
|
|
301
248
|
...disabled ? { disabled: true } : {}
|
|
302
249
|
} : void 0;
|
|
250
|
+
if (disabled) {
|
|
251
|
+
delete rest.onPress;
|
|
252
|
+
delete rest.onPressIn;
|
|
253
|
+
delete rest.onPressOut;
|
|
254
|
+
delete rest.onLongPress;
|
|
255
|
+
}
|
|
303
256
|
return react.default.createElement("TouchableNativeFeedback", {
|
|
304
257
|
accessible: true,
|
|
305
258
|
...rest,
|
|
@@ -326,20 +279,16 @@ function createActivityIndicatorMock() {
|
|
|
326
279
|
//#region src/mocks/components/Button.ts
|
|
327
280
|
function createButtonMock() {
|
|
328
281
|
function Button(props) {
|
|
329
|
-
const { title, onPress, disabled, color, accessibilityLabel, accessibilityState,
|
|
330
|
-
|
|
282
|
+
const { title, onPress, disabled, color, accessibilityLabel, accessibilityState, ...rest } = props;
|
|
283
|
+
const hostProps = require_presets.buildPressableHostProps({
|
|
331
284
|
...rest,
|
|
332
|
-
|
|
333
|
-
|
|
285
|
+
onPress,
|
|
286
|
+
disabled,
|
|
287
|
+
accessibilityState,
|
|
334
288
|
accessibilityLabel: accessibilityLabel || title,
|
|
335
|
-
accessibilityRole: "button"
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
disabled: true
|
|
339
|
-
} : accessibilityState,
|
|
340
|
-
accessible: true,
|
|
341
|
-
disabled
|
|
342
|
-
}, react.default.createElement("Text", {
|
|
289
|
+
accessibilityRole: "button"
|
|
290
|
+
}, void 0);
|
|
291
|
+
return react.default.createElement("View", hostProps, react.default.createElement("Text", {
|
|
343
292
|
style: color ? { color } : void 0,
|
|
344
293
|
disabled
|
|
345
294
|
}, title));
|
|
@@ -352,6 +301,7 @@ function createButtonMock() {
|
|
|
352
301
|
function createSwitchMock() {
|
|
353
302
|
const Switch = react.default.forwardRef((props, ref) => {
|
|
354
303
|
return react.default.createElement("RCTSwitch", {
|
|
304
|
+
accessibilityRole: "switch",
|
|
355
305
|
...props,
|
|
356
306
|
ref
|
|
357
307
|
});
|
|
@@ -579,8 +529,8 @@ function flattenImpl(style) {
|
|
|
579
529
|
}
|
|
580
530
|
return hasAny ? result : void 0;
|
|
581
531
|
}
|
|
582
|
-
function createStyleSheetMock() {
|
|
583
|
-
|
|
532
|
+
function createStyleSheetMock(getScale = () => 3) {
|
|
533
|
+
const sheet = {
|
|
584
534
|
create: vitest.vi.fn((styles) => {
|
|
585
535
|
return styles;
|
|
586
536
|
}),
|
|
@@ -600,50 +550,228 @@ function createStyleSheetMock() {
|
|
|
600
550
|
top: 0,
|
|
601
551
|
bottom: 0
|
|
602
552
|
},
|
|
603
|
-
hairlineWidth: .5,
|
|
604
553
|
setStyleAttributePreprocessor: vitest.vi.fn()
|
|
605
554
|
};
|
|
555
|
+
Object.defineProperty(sheet, "hairlineWidth", {
|
|
556
|
+
enumerable: true,
|
|
557
|
+
configurable: true,
|
|
558
|
+
get() {
|
|
559
|
+
const ratio = getScale();
|
|
560
|
+
const width = Math.round(.4 * ratio) / ratio;
|
|
561
|
+
return width === 0 ? 1 / ratio : width;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
return sheet;
|
|
606
565
|
}
|
|
607
566
|
//#endregion
|
|
608
567
|
//#region src/mocks/apis/Animated.ts
|
|
609
|
-
|
|
610
|
-
|
|
568
|
+
const IDENTITY_EASING = (t) => t;
|
|
569
|
+
function interpolateSegment(input, inputMin, inputMax, outputMin, outputMax, easing, extrapolateLeft, extrapolateRight) {
|
|
570
|
+
let result = input;
|
|
571
|
+
if (result < inputMin) {
|
|
572
|
+
if (extrapolateLeft === "identity") return result;
|
|
573
|
+
else if (extrapolateLeft === "clamp") result = inputMin;
|
|
574
|
+
}
|
|
575
|
+
if (result > inputMax) {
|
|
576
|
+
if (extrapolateRight === "identity") return result;
|
|
577
|
+
else if (extrapolateRight === "clamp") result = inputMax;
|
|
578
|
+
}
|
|
579
|
+
if (outputMin === outputMax) return outputMin;
|
|
580
|
+
if (inputMin === inputMax) return input <= inputMin ? outputMin : outputMax;
|
|
581
|
+
if (inputMin === -Infinity) result = -result;
|
|
582
|
+
else if (inputMax === Infinity) result = result - inputMin;
|
|
583
|
+
else result = (result - inputMin) / (inputMax - inputMin);
|
|
584
|
+
result = easing(result);
|
|
585
|
+
if (outputMin === -Infinity) result = -result;
|
|
586
|
+
else if (outputMax === Infinity) result = result + outputMin;
|
|
587
|
+
else result = result * (outputMax - outputMin) + outputMin;
|
|
588
|
+
return result;
|
|
611
589
|
}
|
|
612
|
-
function
|
|
613
|
-
let i
|
|
614
|
-
for (; i < inputRange.length -
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
const
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
590
|
+
function findRangeIndex(input, inputRange) {
|
|
591
|
+
let i;
|
|
592
|
+
for (i = 1; i < inputRange.length - 1; ++i) if (inputRange[i] >= input) break;
|
|
593
|
+
return i - 1;
|
|
594
|
+
}
|
|
595
|
+
function interpolateNumeric(value, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing) {
|
|
596
|
+
const i = findRangeIndex(value, inputRange);
|
|
597
|
+
return interpolateSegment(value, inputRange[i], inputRange[i + 1], outputRange[i], outputRange[i + 1], easing, extrapolateLeft ?? extrapolate, extrapolateRight ?? extrapolate);
|
|
598
|
+
}
|
|
599
|
+
const NAMED_COLORS = {
|
|
600
|
+
red: [
|
|
601
|
+
255,
|
|
602
|
+
0,
|
|
603
|
+
0,
|
|
604
|
+
1
|
|
605
|
+
],
|
|
606
|
+
green: [
|
|
607
|
+
0,
|
|
608
|
+
128,
|
|
609
|
+
0,
|
|
610
|
+
1
|
|
611
|
+
],
|
|
612
|
+
blue: [
|
|
613
|
+
0,
|
|
614
|
+
0,
|
|
615
|
+
255,
|
|
616
|
+
1
|
|
617
|
+
],
|
|
618
|
+
white: [
|
|
619
|
+
255,
|
|
620
|
+
255,
|
|
621
|
+
255,
|
|
622
|
+
1
|
|
623
|
+
],
|
|
624
|
+
black: [
|
|
625
|
+
0,
|
|
626
|
+
0,
|
|
627
|
+
0,
|
|
628
|
+
1
|
|
629
|
+
],
|
|
630
|
+
transparent: [
|
|
631
|
+
0,
|
|
632
|
+
0,
|
|
633
|
+
0,
|
|
634
|
+
0
|
|
635
|
+
],
|
|
636
|
+
yellow: [
|
|
637
|
+
255,
|
|
638
|
+
255,
|
|
639
|
+
0,
|
|
640
|
+
1
|
|
641
|
+
],
|
|
642
|
+
cyan: [
|
|
643
|
+
0,
|
|
644
|
+
255,
|
|
645
|
+
255,
|
|
646
|
+
1
|
|
647
|
+
],
|
|
648
|
+
magenta: [
|
|
649
|
+
255,
|
|
650
|
+
0,
|
|
651
|
+
255,
|
|
652
|
+
1
|
|
653
|
+
],
|
|
654
|
+
orange: [
|
|
655
|
+
255,
|
|
656
|
+
165,
|
|
657
|
+
0,
|
|
658
|
+
1
|
|
659
|
+
],
|
|
660
|
+
purple: [
|
|
661
|
+
128,
|
|
662
|
+
0,
|
|
663
|
+
128,
|
|
664
|
+
1
|
|
665
|
+
],
|
|
666
|
+
gray: [
|
|
667
|
+
128,
|
|
668
|
+
128,
|
|
669
|
+
128,
|
|
670
|
+
1
|
|
671
|
+
],
|
|
672
|
+
grey: [
|
|
673
|
+
128,
|
|
674
|
+
128,
|
|
675
|
+
128,
|
|
676
|
+
1
|
|
677
|
+
]
|
|
678
|
+
};
|
|
679
|
+
function colorToRgba(input) {
|
|
680
|
+
const s = input.toLowerCase().trim();
|
|
681
|
+
if (NAMED_COLORS[s]) return [...NAMED_COLORS[s]];
|
|
682
|
+
let m;
|
|
683
|
+
if (m = s.match(/^#([0-9a-f]{3})$/)) {
|
|
684
|
+
const [r, g, b] = m[1].split("");
|
|
685
|
+
return [
|
|
686
|
+
parseInt(r + r, 16),
|
|
687
|
+
parseInt(g + g, 16),
|
|
688
|
+
parseInt(b + b, 16),
|
|
689
|
+
1
|
|
690
|
+
];
|
|
632
691
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
692
|
+
if (m = s.match(/^#([0-9a-f]{6})$/)) {
|
|
693
|
+
const n = m[1];
|
|
694
|
+
return [
|
|
695
|
+
parseInt(n.slice(0, 2), 16),
|
|
696
|
+
parseInt(n.slice(2, 4), 16),
|
|
697
|
+
parseInt(n.slice(4, 6), 16),
|
|
698
|
+
1
|
|
699
|
+
];
|
|
641
700
|
}
|
|
642
|
-
if (
|
|
643
|
-
|
|
644
|
-
|
|
701
|
+
if (m = s.match(/^#([0-9a-f]{8})$/)) {
|
|
702
|
+
const n = m[1];
|
|
703
|
+
return [
|
|
704
|
+
parseInt(n.slice(0, 2), 16),
|
|
705
|
+
parseInt(n.slice(2, 4), 16),
|
|
706
|
+
parseInt(n.slice(4, 6), 16),
|
|
707
|
+
parseInt(n.slice(6, 8), 16) / 255
|
|
708
|
+
];
|
|
645
709
|
}
|
|
646
|
-
return
|
|
710
|
+
if (m = s.match(/^rgb\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/)) return [
|
|
711
|
+
+m[1],
|
|
712
|
+
+m[2],
|
|
713
|
+
+m[3],
|
|
714
|
+
1
|
|
715
|
+
];
|
|
716
|
+
if (m = s.match(/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/)) return [
|
|
717
|
+
+m[1],
|
|
718
|
+
+m[2],
|
|
719
|
+
+m[3],
|
|
720
|
+
+m[4]
|
|
721
|
+
];
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
const NUMERIC_COMPONENT_RE = /[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
|
|
725
|
+
function mapStringToComponents(input) {
|
|
726
|
+
const rgba = colorToRgba(input);
|
|
727
|
+
if (rgba) return {
|
|
728
|
+
isColor: true,
|
|
729
|
+
components: rgba
|
|
730
|
+
};
|
|
731
|
+
const components = [];
|
|
732
|
+
let lastMatchEnd = 0;
|
|
733
|
+
let match;
|
|
734
|
+
NUMERIC_COMPONENT_RE.lastIndex = 0;
|
|
735
|
+
while ((match = NUMERIC_COMPONENT_RE.exec(input)) != null) {
|
|
736
|
+
if (match.index > lastMatchEnd) components.push(input.substring(lastMatchEnd, match.index));
|
|
737
|
+
components.push(parseFloat(match[0]));
|
|
738
|
+
lastMatchEnd = match.index + match[0].length;
|
|
739
|
+
}
|
|
740
|
+
if (components.length === 0) throw new Error("outputRange must contain color or value with numeric component");
|
|
741
|
+
if (lastMatchEnd < input.length) components.push(input.substring(lastMatchEnd, input.length));
|
|
742
|
+
return {
|
|
743
|
+
isColor: false,
|
|
744
|
+
components
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
function prepareStringInterpolation(outputRange) {
|
|
748
|
+
const mapped = outputRange.map(mapStringToComponents);
|
|
749
|
+
const isColor = mapped[0].isColor;
|
|
750
|
+
if (!mapped.every((o) => o.isColor === isColor)) throw new Error("All elements of output range should either be a color or a string with numeric components");
|
|
751
|
+
const first = mapped[0].components;
|
|
752
|
+
if (!mapped.every((o) => o.components.length === first.length)) throw new Error("All elements of output range should have the same number of components");
|
|
753
|
+
if (!mapped.every((o) => o.components.every((c, i) => typeof c === "number" || c === first[i]))) throw new Error("All elements of output range should have the same non-numeric components");
|
|
754
|
+
const numericComponents = mapped.map((o) => isColor ? o.components : o.components.filter((c) => typeof c === "number"));
|
|
755
|
+
return {
|
|
756
|
+
isColor,
|
|
757
|
+
template: first,
|
|
758
|
+
perSlotRanges: numericComponents[0].map((_, i) => numericComponents.map((c) => c[i]))
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
function interpolateString(prepared, value, inputRange, extrapolate, extrapolateLeft, extrapolateRight, easing) {
|
|
762
|
+
const slots = prepared.perSlotRanges.map((range) => interpolateNumeric(value, inputRange, range, extrapolate, extrapolateLeft, extrapolateRight, easing));
|
|
763
|
+
if (prepared.isColor) {
|
|
764
|
+
const r = slots.map((v, i) => i < 3 ? Math.round(v) : Math.round(v * 1e3) / 1e3);
|
|
765
|
+
return `rgba(${r[0]}, ${r[1]}, ${r[2]}, ${r[3]})`;
|
|
766
|
+
}
|
|
767
|
+
let i = 0;
|
|
768
|
+
return prepared.template.map((c) => typeof c === "number" ? slots[i++] : c).join("");
|
|
769
|
+
}
|
|
770
|
+
function checkValidRanges(inputRange, outputRange) {
|
|
771
|
+
if (inputRange.length === 2 && inputRange[0] === -Infinity && inputRange[1] === Infinity) throw new Error("inputRange cannot be [-Infinity, Infinity]");
|
|
772
|
+
if (inputRange.length < 2) throw new Error("inputRange must have at least 2 elements");
|
|
773
|
+
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));
|
|
774
|
+
if (inputRange.length !== outputRange.length) throw new Error("inputRange (" + inputRange.length + ") and outputRange (" + outputRange.length + ") must have the same length");
|
|
647
775
|
}
|
|
648
776
|
var AnimatedValue = class AnimatedValue {
|
|
649
777
|
_value;
|
|
@@ -672,9 +800,27 @@ var AnimatedValue = class AnimatedValue {
|
|
|
672
800
|
this._listeners.clear();
|
|
673
801
|
}
|
|
674
802
|
interpolate(config) {
|
|
675
|
-
const { inputRange, outputRange, extrapolate = "extend", extrapolateLeft, extrapolateRight, easing } = config || {};
|
|
803
|
+
const { inputRange, outputRange, extrapolate = "extend", extrapolateLeft, extrapolateRight, easing = IDENTITY_EASING } = config || {};
|
|
676
804
|
if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(this._value);
|
|
677
|
-
|
|
805
|
+
checkValidRanges(inputRange, outputRange);
|
|
806
|
+
if (typeof outputRange[0] === "string") {
|
|
807
|
+
const prepared = prepareStringInterpolation(outputRange);
|
|
808
|
+
const compute = () => interpolateString(prepared, this._value, inputRange, extrapolate, extrapolateLeft, extrapolateRight, easing);
|
|
809
|
+
return {
|
|
810
|
+
getValue: compute,
|
|
811
|
+
__getValue: compute,
|
|
812
|
+
toJSON: compute,
|
|
813
|
+
interpolate: () => {
|
|
814
|
+
throw new Error("Cannot chain an interpolation off a string-valued interpolation");
|
|
815
|
+
},
|
|
816
|
+
addListener: () => "0",
|
|
817
|
+
removeListener: () => {},
|
|
818
|
+
removeAllListeners: () => {},
|
|
819
|
+
stopAnimation: (cb) => cb?.(compute()),
|
|
820
|
+
resetAnimation: (cb) => cb?.(compute())
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
return new AnimatedValue(interpolateNumeric(this._value, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing));
|
|
678
824
|
}
|
|
679
825
|
stopAnimation(callback) {
|
|
680
826
|
callback?.(this._value);
|
|
@@ -2145,7 +2291,7 @@ function buildReactNativeMock(platform = "ios") {
|
|
|
2145
2291
|
FlatList: createFlatListMock(),
|
|
2146
2292
|
SectionList: createSectionListMock(),
|
|
2147
2293
|
Modal: createModalMock(),
|
|
2148
|
-
Pressable: createPressableMock(),
|
|
2294
|
+
Pressable: require_presets.createPressableMock(),
|
|
2149
2295
|
TouchableOpacity: createTouchableOpacityMock(),
|
|
2150
2296
|
TouchableHighlight: createTouchableHighlightMock(),
|
|
2151
2297
|
TouchableWithoutFeedback: createTouchableWithoutFeedbackMock(),
|
|
@@ -2163,7 +2309,7 @@ function buildReactNativeMock(platform = "ios") {
|
|
|
2163
2309
|
DrawerLayoutAndroid: createDrawerLayoutAndroidMock(),
|
|
2164
2310
|
Platform: createPlatformMock(platform),
|
|
2165
2311
|
Dimensions: createDimensionsMock(),
|
|
2166
|
-
StyleSheet: createStyleSheetMock(),
|
|
2312
|
+
StyleSheet: createStyleSheetMock(() => mock.Dimensions.get("window").scale),
|
|
2167
2313
|
Animated: createAnimatedMock(),
|
|
2168
2314
|
Alert: createAlertMock(),
|
|
2169
2315
|
Linking: createLinkingMock(),
|
|
@@ -2496,6 +2642,8 @@ try {
|
|
|
2496
2642
|
} catch (e) {
|
|
2497
2643
|
if (diagnostics) console.log(`[vitest-native] Could not load RNTL matchers: ${e?.message}`);
|
|
2498
2644
|
}
|
|
2645
|
+
vitest.expect.extend(require_matchers.animatedMatchers);
|
|
2646
|
+
if (diagnostics) console.log(`[vitest-native] Registered ${Object.keys(require_matchers.animatedMatchers).length} animated matchers: ${Object.keys(require_matchers.animatedMatchers).join(", ")}`);
|
|
2499
2647
|
vitest.expect.addSnapshotSerializer(require_serializer.serializer);
|
|
2500
2648
|
(0, vitest.afterAll)(() => {
|
|
2501
2649
|
uninstallCjsBridge();
|