vitest-native 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +731 -0
- package/README.md +32 -1
- package/dist/cli.cjs +163 -27
- package/dist/cli.mjs +162 -26
- package/dist/{ecosystem-EFtHnKS9.mjs → ecosystem-CO5vqExO.mjs} +77 -15
- package/dist/{ecosystem-BIWaVwYL.cjs → ecosystem-IuZ-Gv0R.cjs} +78 -16
- package/dist/errors-Dm5yLNTF.mjs +64 -0
- package/dist/errors-flXDIeWk.cjs +75 -0
- package/dist/errors.d.mts +46 -0
- package/dist/errors.mjs +78 -0
- package/dist/helpers.cjs +6 -23
- package/dist/helpers.d.cts +0 -6
- package/dist/helpers.d.mts +0 -6
- package/dist/helpers.mjs +6 -23
- package/dist/{index-CEgRDdhd.d.cts → index-BJL4cQ-l.d.cts} +9 -4
- package/dist/{index-j-0tueBr.d.mts → index-CvCU0cLl.d.mts} +9 -4
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +245 -59
- package/dist/jest-compat/interop.mjs +15 -0
- package/dist/jest-compat/setup.mjs +102 -7
- package/dist/matchers.cjs +16 -7
- package/dist/matchers.mjs +16 -7
- package/dist/native/hooks.mjs +75 -1
- package/dist/native/loader.mjs +26 -6
- package/dist/native/module-reset.mjs +63 -0
- package/dist/native/registry.mjs +80 -11
- package/dist/native/resolve.d.mts +22 -0
- package/dist/native/resolve.mjs +21 -13
- package/dist/native/runner.mjs +21 -0
- package/dist/native/setup.mjs +4 -2
- package/dist/native/transform.mjs +108 -3
- package/dist/native/worker.mjs +59 -16
- package/dist/{pool-CJmjRgsB.mjs → pool-Bcxp4Qrg.mjs} +2 -1
- package/dist/{pool-DzsEo9vv.cjs → pool-CFND7plG.cjs} +2 -1
- package/dist/{preset-map-CNsZKfvu.mjs → preset-map-BpDG_D5m.mjs} +0 -1
- package/dist/{preset-map-CG4FMtsl.cjs → preset-map-DxilQ4pI.cjs} +0 -1
- package/dist/{presets-C4faM3ds.cjs → presets-BGTqVH6C.cjs} +94 -50
- package/dist/{presets-CuDrNA_W.mjs → presets-CK85x8ey.mjs} +94 -50
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rntl-matchers.d.ts +35 -0
- package/dist/serializer.cjs +33 -3
- package/dist/serializer.mjs +33 -3
- package/dist/setup.mjs +234 -71
- package/docs/release-readiness.md +22 -5
- package/docs/versioning.md +133 -0
- package/package.json +25 -35
- package/dist/index.cjs +0 -788
- package/dist/index.d.cts +0 -14
- package/dist/presets.cjs +0 -18
- package/dist/presets.d.cts +0 -2
- package/dist/setup.cjs +0 -2702
- package/dist/setup.d.cts +0 -1
package/dist/setup.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __require } from "./chunk-CjcI7cDX.mjs";
|
|
2
|
-
import { t as AUTO_DETECT_PRESETS } from "./preset-map-
|
|
3
|
-
import { D as buildPressableHostProps, E as createPressableMock, c as createTouchableOpacityMock, d as createFlatListMock, f as createScrollViewMock, i as createViewMock, l as createVirtualizedListMock, o as createTouchableWithoutFeedbackMock, p as createTextInputMock, s as createTouchableHighlightMock, t as presets_exports, u as createSectionListMock } from "./presets-
|
|
2
|
+
import { t as AUTO_DETECT_PRESETS } from "./preset-map-BpDG_D5m.mjs";
|
|
3
|
+
import { D as buildPressableHostProps, E as createPressableMock, c as createTouchableOpacityMock, d as createFlatListMock, f as createScrollViewMock, i as createViewMock, l as createVirtualizedListMock, o as createTouchableWithoutFeedbackMock, p as createTextInputMock, s as createTouchableHighlightMock, t as presets_exports, u as createSectionListMock } from "./presets-CK85x8ey.mjs";
|
|
4
4
|
import { serializer } from "./serializer.mjs";
|
|
5
5
|
import { animatedMatchers } from "./matchers.mjs";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
@@ -565,13 +565,32 @@ function checkValidRanges(inputRange, outputRange) {
|
|
|
565
565
|
for (let i = 1; i < inputRange.length; ++i) if (!(inputRange[i] >= inputRange[i - 1])) throw new Error("inputRange must be monotonically non-decreasing " + String(inputRange));
|
|
566
566
|
if (inputRange.length !== outputRange.length) throw new Error("inputRange (" + inputRange.length + ") and outputRange (" + outputRange.length + ") must have the same length");
|
|
567
567
|
}
|
|
568
|
+
let _warnedGetValue = false;
|
|
569
|
+
function warnGetValueOnce() {
|
|
570
|
+
if (_warnedGetValue) return;
|
|
571
|
+
_warnedGetValue = true;
|
|
572
|
+
console.warn("[vitest-native] Animated node .getValue() is not a React Native API — real React Native exposes only __getValue(). This call works under engine:'mock' and throws under engine:'native'. Use __getValue() so the suite runs on both.");
|
|
573
|
+
}
|
|
568
574
|
var AnimatedNode = class {
|
|
569
575
|
_listeners = /* @__PURE__ */ new Map();
|
|
570
576
|
_children = /* @__PURE__ */ new Set();
|
|
571
577
|
_listenerIdCounter = 0;
|
|
578
|
+
/**
|
|
579
|
+
* NOT a React Native API — real React Native exposes only `__getValue()`.
|
|
580
|
+
*
|
|
581
|
+
* Kept because suites already use it, but it is a portability trap: the same call
|
|
582
|
+
* throws under `engine: 'native'`, where React Native itself is running. Warned once
|
|
583
|
+
* per process so the message is a signpost rather than noise, and recorded in
|
|
584
|
+
* crosscheck/known-differences.json.
|
|
585
|
+
*/
|
|
572
586
|
getValue() {
|
|
587
|
+
warnGetValueOnce();
|
|
573
588
|
return this.__getValue();
|
|
574
589
|
}
|
|
590
|
+
/** Matches React Native's AnimatedNode.hasListeners(). */
|
|
591
|
+
hasListeners() {
|
|
592
|
+
return this._listeners.size > 0;
|
|
593
|
+
}
|
|
575
594
|
_attachToParents() {}
|
|
576
595
|
_detachFromParents() {}
|
|
577
596
|
_consumerCount() {
|
|
@@ -612,12 +631,6 @@ var AnimatedNode = class {
|
|
|
612
631
|
if (!inputRange || !outputRange || inputRange.length < 2 || outputRange.length < 2) return new AnimatedValue(Number(this.__getValue()) || 0);
|
|
613
632
|
return new AnimatedInterpolation(this, config);
|
|
614
633
|
}
|
|
615
|
-
stopAnimation(callback) {
|
|
616
|
-
callback?.(this.__getValue());
|
|
617
|
-
}
|
|
618
|
-
resetAnimation(callback) {
|
|
619
|
-
callback?.(this.__getValue());
|
|
620
|
-
}
|
|
621
634
|
toJSON() {
|
|
622
635
|
return this.__getValue();
|
|
623
636
|
}
|
|
@@ -625,6 +638,8 @@ var AnimatedNode = class {
|
|
|
625
638
|
var AnimatedValue = class extends AnimatedNode {
|
|
626
639
|
_value;
|
|
627
640
|
_offset = 0;
|
|
641
|
+
_runningAnimation = null;
|
|
642
|
+
_trackingNode = null;
|
|
628
643
|
_tracking = null;
|
|
629
644
|
constructor(value = 0) {
|
|
630
645
|
super();
|
|
@@ -648,6 +663,59 @@ var AnimatedValue = class extends AnimatedNode {
|
|
|
648
663
|
this._offset += this._value;
|
|
649
664
|
this._value = 0;
|
|
650
665
|
}
|
|
666
|
+
/**
|
|
667
|
+
* Drive this value from an animation object, as React Native's
|
|
668
|
+
* AnimatedValue.animate() does: stop whatever is running, then start the new one,
|
|
669
|
+
* feeding each frame back through setValue and reporting completion.
|
|
670
|
+
*
|
|
671
|
+
* KNOWN DIVERGENCE: this mock's own timing/spring/decay do NOT route through here.
|
|
672
|
+
* They apply their target value synchronously (see createAnimation), whereas real
|
|
673
|
+
* React Native's timing() calls value.animate(). So a suite spying on `animate` sees
|
|
674
|
+
* nothing under engine:'mock' and a call under engine:'native'. Wiring them through
|
|
675
|
+
* would mean reworking the synchronous-completion model a lot of tests depend on, so
|
|
676
|
+
* the divergence is recorded in crosscheck/known-differences.json instead. Pinned by
|
|
677
|
+
* a test, so changing it is a decision rather than an accident.
|
|
678
|
+
*
|
|
679
|
+
* React Native passes the previous animation and the node itself as the last two
|
|
680
|
+
* arguments; both are forwarded so a caller supplying a real Animation sees the same
|
|
681
|
+
* call shape.
|
|
682
|
+
*/
|
|
683
|
+
animate(animation, callback) {
|
|
684
|
+
const previous = this._runningAnimation;
|
|
685
|
+
this._runningAnimation?.stop?.();
|
|
686
|
+
this._runningAnimation = animation;
|
|
687
|
+
animation?.start?.(this.__getValue(), (value) => this.setValue(value), (result) => {
|
|
688
|
+
this._runningAnimation = null;
|
|
689
|
+
callback?.(result);
|
|
690
|
+
}, previous, this);
|
|
691
|
+
}
|
|
692
|
+
stopAnimation(callback) {
|
|
693
|
+
this._runningAnimation?.stop?.();
|
|
694
|
+
this._runningAnimation = null;
|
|
695
|
+
callback?.(this.__getValue());
|
|
696
|
+
}
|
|
697
|
+
resetAnimation(callback) {
|
|
698
|
+
this.stopAnimation(callback);
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Matches React Native: detach the current tracking node, if any. Also clears the
|
|
702
|
+
* mock's own toValue-follows-value link, so a caller stopping tracking gets what the
|
|
703
|
+
* name promises regardless of which mechanism set it up.
|
|
704
|
+
*/
|
|
705
|
+
stopTracking() {
|
|
706
|
+
this._trackingNode?.__detach?.();
|
|
707
|
+
this._trackingNode = null;
|
|
708
|
+
stopTrackingLink(this);
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Matches React Native: replace any existing tracking and kick the new one once so it
|
|
712
|
+
* takes effect immediately rather than on the next frame.
|
|
713
|
+
*/
|
|
714
|
+
track(tracking) {
|
|
715
|
+
this.stopTracking();
|
|
716
|
+
this._trackingNode = tracking;
|
|
717
|
+
this._trackingNode?.update?.();
|
|
718
|
+
}
|
|
651
719
|
};
|
|
652
720
|
var AnimatedInterpolation = class extends AnimatedNode {
|
|
653
721
|
_parent;
|
|
@@ -706,6 +774,32 @@ function operandValue(v) {
|
|
|
706
774
|
}
|
|
707
775
|
return typeof v === "number" ? v : 0;
|
|
708
776
|
}
|
|
777
|
+
/**
|
|
778
|
+
* React Native exposes its AnimatedEvent class as `Animated.Event`, in its own words
|
|
779
|
+
* "so it can be used as a type for type checkers". That is what this covers: a named
|
|
780
|
+
* class consumers can reference and instanceof against.
|
|
781
|
+
*
|
|
782
|
+
* `Animated.event()` in this mock returns a plain spy function rather than an instance
|
|
783
|
+
* of this class, because suites assert on it with vi.fn matchers. So
|
|
784
|
+
* `Animated.event(...) instanceof Animated.Event` is false here and true under real
|
|
785
|
+
* React Native — a divergence the cross-check records rather than papers over.
|
|
786
|
+
*/
|
|
787
|
+
var AnimatedEvent = class {
|
|
788
|
+
_argMapping;
|
|
789
|
+
_listeners = [];
|
|
790
|
+
constructor(argMapping = [], config) {
|
|
791
|
+
this._argMapping = argMapping;
|
|
792
|
+
if (config?.listener) this._listeners.push(config.listener);
|
|
793
|
+
}
|
|
794
|
+
__addListener(callback) {
|
|
795
|
+
this._listeners.push(callback);
|
|
796
|
+
}
|
|
797
|
+
__removeListener(callback) {
|
|
798
|
+
this._listeners = this._listeners.filter((l) => l !== callback);
|
|
799
|
+
}
|
|
800
|
+
__attach() {}
|
|
801
|
+
__detach() {}
|
|
802
|
+
};
|
|
709
803
|
var AnimatedValueXY = class {
|
|
710
804
|
x;
|
|
711
805
|
y;
|
|
@@ -760,6 +854,20 @@ var AnimatedValueXY = class {
|
|
|
760
854
|
this.x.removeListener(id.x);
|
|
761
855
|
this.y.removeListener(id.y);
|
|
762
856
|
}
|
|
857
|
+
/**
|
|
858
|
+
* ValueXY composes two AnimatedValues rather than extending AnimatedNode, so it does
|
|
859
|
+
* not inherit these; React Native's does expose them.
|
|
860
|
+
*/
|
|
861
|
+
hasListeners() {
|
|
862
|
+
return this.x.hasListeners() || this.y.hasListeners();
|
|
863
|
+
}
|
|
864
|
+
/** React Native inherits this from AnimatedNode, where it returns __getValue(). */
|
|
865
|
+
toJSON() {
|
|
866
|
+
return {
|
|
867
|
+
x: this.x.__getValue(),
|
|
868
|
+
y: this.y.__getValue()
|
|
869
|
+
};
|
|
870
|
+
}
|
|
763
871
|
removeAllListeners() {
|
|
764
872
|
this.x.removeAllListeners();
|
|
765
873
|
this.y.removeAllListeners();
|
|
@@ -867,6 +975,12 @@ var AnimatedColor = class extends AnimatedNode {
|
|
|
867
975
|
g;
|
|
868
976
|
b;
|
|
869
977
|
a;
|
|
978
|
+
stopAnimation(callback) {
|
|
979
|
+
callback?.(this.__getValue());
|
|
980
|
+
}
|
|
981
|
+
resetAnimation(callback) {
|
|
982
|
+
this.stopAnimation(callback);
|
|
983
|
+
}
|
|
870
984
|
constructor(color) {
|
|
871
985
|
super();
|
|
872
986
|
if (typeof color === "string") {
|
|
@@ -994,14 +1108,14 @@ function createAnimatedWrapper(displayName) {
|
|
|
994
1108
|
Component.displayName = displayName;
|
|
995
1109
|
return Component;
|
|
996
1110
|
}
|
|
997
|
-
function
|
|
1111
|
+
function stopTrackingLink(value) {
|
|
998
1112
|
if (value._tracking) {
|
|
999
1113
|
value._tracking.source.__removeChild(value._tracking.child);
|
|
1000
1114
|
value._tracking = null;
|
|
1001
1115
|
}
|
|
1002
1116
|
}
|
|
1003
1117
|
function startTracking(value, toValue) {
|
|
1004
|
-
|
|
1118
|
+
stopTrackingLink(value);
|
|
1005
1119
|
if (toValue instanceof AnimatedValue) {
|
|
1006
1120
|
value.setValue(toValue.getValue());
|
|
1007
1121
|
const child = () => value.setValue(toValue.__getValue());
|
|
@@ -1034,6 +1148,15 @@ function createAnimatedMock() {
|
|
|
1034
1148
|
return {
|
|
1035
1149
|
Value: AnimatedValue,
|
|
1036
1150
|
ValueXY: AnimatedValueXY,
|
|
1151
|
+
Node: AnimatedNode,
|
|
1152
|
+
Interpolation: AnimatedInterpolation,
|
|
1153
|
+
Event: AnimatedEvent,
|
|
1154
|
+
/**
|
|
1155
|
+
* React Native attaches a native event handler to a view and hands back a detach
|
|
1156
|
+
* function. There is no native side here, so this records nothing and returns the
|
|
1157
|
+
* same shape — enough for a caller to attach and detach without throwing.
|
|
1158
|
+
*/
|
|
1159
|
+
attachNativeEvent: vi.fn((_viewRef, _eventName, _argMapping) => ({ detach() {} })),
|
|
1037
1160
|
Color: AnimatedColor,
|
|
1038
1161
|
timing: vi.fn((value, config) => {
|
|
1039
1162
|
return createAnimation(() => {
|
|
@@ -1278,10 +1401,19 @@ function createLinkingMock() {
|
|
|
1278
1401
|
}
|
|
1279
1402
|
//#endregion
|
|
1280
1403
|
//#region src/mocks/apis/AppState.ts
|
|
1404
|
+
/**
|
|
1405
|
+
* Resting app state, written once — see Keyboard.ts for why not twice.
|
|
1406
|
+
*
|
|
1407
|
+
* "active" (a foregrounded app) is the mock's choice, not something real React
|
|
1408
|
+
* Native reports under Node: there it reads from a native module that only exists on
|
|
1409
|
+
* a device, so it is undefined, as it also is under Jest with React Native's own
|
|
1410
|
+
* preset. Recorded in crosscheck/known-differences.json.
|
|
1411
|
+
*/
|
|
1412
|
+
const RESTING_STATE = "active";
|
|
1281
1413
|
function createAppStateMock() {
|
|
1282
1414
|
const listeners = /* @__PURE__ */ new Map();
|
|
1283
1415
|
const mock = {
|
|
1284
|
-
currentState:
|
|
1416
|
+
currentState: RESTING_STATE,
|
|
1285
1417
|
isAvailable: true,
|
|
1286
1418
|
addEventListener: vi.fn((type, handler) => {
|
|
1287
1419
|
if (!listeners.has(type)) listeners.set(type, /* @__PURE__ */ new Set());
|
|
@@ -1293,7 +1425,7 @@ function createAppStateMock() {
|
|
|
1293
1425
|
listeners.get("change")?.forEach((fn) => fn(state));
|
|
1294
1426
|
},
|
|
1295
1427
|
_reset: () => {
|
|
1296
|
-
mock.currentState =
|
|
1428
|
+
mock.currentState = RESTING_STATE;
|
|
1297
1429
|
listeners.clear();
|
|
1298
1430
|
}
|
|
1299
1431
|
};
|
|
@@ -1301,15 +1433,28 @@ function createAppStateMock() {
|
|
|
1301
1433
|
}
|
|
1302
1434
|
//#endregion
|
|
1303
1435
|
//#region src/mocks/apis/Keyboard.ts
|
|
1436
|
+
/**
|
|
1437
|
+
* The keyboard's resting state, written once.
|
|
1438
|
+
*
|
|
1439
|
+
* It used to be repeated at construction and in dismiss/_hide/_reset, which is the
|
|
1440
|
+
* shape that lets a wrong initial value pass every gate: suites call `_reset()`
|
|
1441
|
+
* before asserting, so they observe the reset path and never the value the mock is
|
|
1442
|
+
* actually built with. Changing the construction-time values alone was caught by
|
|
1443
|
+
* neither the mock suite nor the cross-check. One constant, so the two cannot drift.
|
|
1444
|
+
*/
|
|
1445
|
+
const RESTING$1 = {
|
|
1446
|
+
visible: false,
|
|
1447
|
+
keyboardHeight: 0
|
|
1448
|
+
};
|
|
1304
1449
|
function createKeyboardMock() {
|
|
1305
|
-
let visible =
|
|
1306
|
-
|
|
1450
|
+
let { visible, keyboardHeight } = RESTING$1;
|
|
1451
|
+
const rest = () => {
|
|
1452
|
+
visible = RESTING$1.visible;
|
|
1453
|
+
keyboardHeight = RESTING$1.keyboardHeight;
|
|
1454
|
+
};
|
|
1307
1455
|
const listeners = /* @__PURE__ */ new Map();
|
|
1308
1456
|
return {
|
|
1309
|
-
dismiss: vi.fn(
|
|
1310
|
-
visible = false;
|
|
1311
|
-
keyboardHeight = 0;
|
|
1312
|
-
}),
|
|
1457
|
+
dismiss: vi.fn(rest),
|
|
1313
1458
|
addListener: vi.fn((event, handler) => {
|
|
1314
1459
|
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
1315
1460
|
listeners.get(event).add(handler);
|
|
@@ -1341,13 +1486,11 @@ function createKeyboardMock() {
|
|
|
1341
1486
|
} }));
|
|
1342
1487
|
},
|
|
1343
1488
|
_hide: () => {
|
|
1344
|
-
|
|
1345
|
-
keyboardHeight = 0;
|
|
1489
|
+
rest();
|
|
1346
1490
|
listeners.get("keyboardDidHide")?.forEach((fn) => fn({}));
|
|
1347
1491
|
},
|
|
1348
1492
|
_reset: () => {
|
|
1349
|
-
|
|
1350
|
-
keyboardHeight = 0;
|
|
1493
|
+
rest();
|
|
1351
1494
|
listeners.clear();
|
|
1352
1495
|
}
|
|
1353
1496
|
};
|
|
@@ -1437,8 +1580,10 @@ function createPermissionsAndroidMock() {
|
|
|
1437
1580
|
}
|
|
1438
1581
|
//#endregion
|
|
1439
1582
|
//#region src/mocks/apis/Appearance.ts
|
|
1583
|
+
/** Resting colour scheme, written once — see Keyboard.ts for why not twice. */
|
|
1584
|
+
const RESTING_SCHEME = "light";
|
|
1440
1585
|
function createAppearanceMock() {
|
|
1441
|
-
let colorScheme =
|
|
1586
|
+
let colorScheme = RESTING_SCHEME;
|
|
1442
1587
|
const listeners = /* @__PURE__ */ new Set();
|
|
1443
1588
|
return {
|
|
1444
1589
|
getColorScheme: vi.fn(() => colorScheme),
|
|
@@ -1453,7 +1598,7 @@ function createAppearanceMock() {
|
|
|
1453
1598
|
} };
|
|
1454
1599
|
}),
|
|
1455
1600
|
_reset: () => {
|
|
1456
|
-
colorScheme =
|
|
1601
|
+
colorScheme = RESTING_SCHEME;
|
|
1457
1602
|
listeners.clear();
|
|
1458
1603
|
}
|
|
1459
1604
|
};
|
|
@@ -1476,8 +1621,50 @@ function createPixelRatioMock(getDimensions) {
|
|
|
1476
1621
|
//#endregion
|
|
1477
1622
|
//#region src/mocks/apis/LayoutAnimation.ts
|
|
1478
1623
|
function createLayoutAnimationMock() {
|
|
1624
|
+
const configureNext = vi.fn();
|
|
1625
|
+
const presets = {
|
|
1626
|
+
easeInEaseOut: {
|
|
1627
|
+
duration: 300,
|
|
1628
|
+
create: {
|
|
1629
|
+
type: "easeInEaseOut",
|
|
1630
|
+
property: "opacity"
|
|
1631
|
+
},
|
|
1632
|
+
update: { type: "easeInEaseOut" },
|
|
1633
|
+
delete: {
|
|
1634
|
+
type: "easeInEaseOut",
|
|
1635
|
+
property: "opacity"
|
|
1636
|
+
}
|
|
1637
|
+
},
|
|
1638
|
+
linear: {
|
|
1639
|
+
duration: 500,
|
|
1640
|
+
create: {
|
|
1641
|
+
type: "linear",
|
|
1642
|
+
property: "opacity"
|
|
1643
|
+
},
|
|
1644
|
+
update: { type: "linear" },
|
|
1645
|
+
delete: {
|
|
1646
|
+
type: "linear",
|
|
1647
|
+
property: "opacity"
|
|
1648
|
+
}
|
|
1649
|
+
},
|
|
1650
|
+
spring: {
|
|
1651
|
+
duration: 700,
|
|
1652
|
+
create: {
|
|
1653
|
+
type: "linear",
|
|
1654
|
+
property: "opacity"
|
|
1655
|
+
},
|
|
1656
|
+
update: {
|
|
1657
|
+
type: "spring",
|
|
1658
|
+
springDamping: .4
|
|
1659
|
+
},
|
|
1660
|
+
delete: {
|
|
1661
|
+
type: "linear",
|
|
1662
|
+
property: "opacity"
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1479
1666
|
return {
|
|
1480
|
-
configureNext
|
|
1667
|
+
configureNext,
|
|
1481
1668
|
create: vi.fn(() => ({
|
|
1482
1669
|
duration: 300,
|
|
1483
1670
|
create: {
|
|
@@ -1503,47 +1690,14 @@ function createLayoutAnimationMock() {
|
|
|
1503
1690
|
scaleY: "scaleY",
|
|
1504
1691
|
scaleXY: "scaleXY"
|
|
1505
1692
|
},
|
|
1506
|
-
Presets:
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
delete: {
|
|
1515
|
-
type: "easeInEaseOut",
|
|
1516
|
-
property: "opacity"
|
|
1517
|
-
}
|
|
1518
|
-
},
|
|
1519
|
-
linear: {
|
|
1520
|
-
duration: 500,
|
|
1521
|
-
create: {
|
|
1522
|
-
type: "linear",
|
|
1523
|
-
property: "opacity"
|
|
1524
|
-
},
|
|
1525
|
-
update: { type: "linear" },
|
|
1526
|
-
delete: {
|
|
1527
|
-
type: "linear",
|
|
1528
|
-
property: "opacity"
|
|
1529
|
-
}
|
|
1530
|
-
},
|
|
1531
|
-
spring: {
|
|
1532
|
-
duration: 700,
|
|
1533
|
-
create: {
|
|
1534
|
-
type: "linear",
|
|
1535
|
-
property: "opacity"
|
|
1536
|
-
},
|
|
1537
|
-
update: {
|
|
1538
|
-
type: "spring",
|
|
1539
|
-
springDamping: .4
|
|
1540
|
-
},
|
|
1541
|
-
delete: {
|
|
1542
|
-
type: "linear",
|
|
1543
|
-
property: "opacity"
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1693
|
+
Presets: presets,
|
|
1694
|
+
easeInEaseOut: (onAnimationDidEnd) => configureNext(presets.easeInEaseOut, onAnimationDidEnd),
|
|
1695
|
+
linear: (onAnimationDidEnd) => configureNext(presets.linear, onAnimationDidEnd),
|
|
1696
|
+
spring: (onAnimationDidEnd) => configureNext(presets.spring, onAnimationDidEnd),
|
|
1697
|
+
checkConfig: vi.fn(() => {
|
|
1698
|
+
console.error("LayoutAnimation.checkConfig(...) has been disabled.");
|
|
1699
|
+
}),
|
|
1700
|
+
setEnabled: vi.fn()
|
|
1547
1701
|
};
|
|
1548
1702
|
}
|
|
1549
1703
|
//#endregion
|
|
@@ -1766,10 +1920,14 @@ function createEasingMock() {
|
|
|
1766
1920
|
}
|
|
1767
1921
|
//#endregion
|
|
1768
1922
|
//#region src/mocks/apis/I18nManager.ts
|
|
1923
|
+
/** Resting layout direction, written once — see Keyboard.ts for why not twice. */
|
|
1924
|
+
const RESTING = {
|
|
1925
|
+
isRTL: false,
|
|
1926
|
+
doLeftAndRightSwapInRTL: true
|
|
1927
|
+
};
|
|
1769
1928
|
function createI18nManagerMock() {
|
|
1770
1929
|
const mock = {
|
|
1771
|
-
|
|
1772
|
-
doLeftAndRightSwapInRTL: true,
|
|
1930
|
+
...RESTING,
|
|
1773
1931
|
allowRTL: vi.fn((_allow) => {}),
|
|
1774
1932
|
forceRTL: vi.fn((force) => {
|
|
1775
1933
|
mock.isRTL = force;
|
|
@@ -1782,8 +1940,7 @@ function createI18nManagerMock() {
|
|
|
1782
1940
|
doLeftAndRightSwapInRTL: mock.doLeftAndRightSwapInRTL
|
|
1783
1941
|
})),
|
|
1784
1942
|
_reset: () => {
|
|
1785
|
-
mock
|
|
1786
|
-
mock.doLeftAndRightSwapInRTL = true;
|
|
1943
|
+
Object.assign(mock, RESTING);
|
|
1787
1944
|
}
|
|
1788
1945
|
};
|
|
1789
1946
|
return mock;
|
|
@@ -2556,6 +2713,12 @@ if (process.env.VITEST_NATIVE_MOCKS) try {
|
|
|
2556
2713
|
if (diagnostics) console.warn(`[vitest-native] Failed to parse VITEST_NATIVE_MOCKS: ${e?.message}`);
|
|
2557
2714
|
}
|
|
2558
2715
|
let explicitPresetNames = null;
|
|
2716
|
+
let disabledPresetNames = [];
|
|
2717
|
+
if (process.env.VITEST_NATIVE_PRESET_DISABLED) try {
|
|
2718
|
+
disabledPresetNames = JSON.parse(process.env.VITEST_NATIVE_PRESET_DISABLED);
|
|
2719
|
+
} catch {
|
|
2720
|
+
disabledPresetNames = [];
|
|
2721
|
+
}
|
|
2559
2722
|
if (process.env.VITEST_NATIVE_PRESET_NAMES) try {
|
|
2560
2723
|
explicitPresetNames = JSON.parse(process.env.VITEST_NATIVE_PRESET_NAMES);
|
|
2561
2724
|
} catch (e) {
|
|
@@ -2636,7 +2799,7 @@ function loadExplicitPresets(names) {
|
|
|
2636
2799
|
}
|
|
2637
2800
|
return loaded;
|
|
2638
2801
|
}
|
|
2639
|
-
const presets = explicitPresetNames ? loadExplicitPresets(explicitPresetNames) : autoDetectPresets();
|
|
2802
|
+
const presets = explicitPresetNames ? loadExplicitPresets(explicitPresetNames) : autoDetectPresets().filter((p) => !disabledPresetNames.includes(p.name));
|
|
2640
2803
|
g.__vitest_native_preset_mocks = g.__vitest_native_preset_mocks || {};
|
|
2641
2804
|
for (const preset of presets) for (const [modName, presetModule] of Object.entries(preset.modules)) {
|
|
2642
2805
|
const presetMock = presetModule.factory();
|
|
@@ -4,12 +4,16 @@ This document defines what `vitest-native` means by release-supported. It is del
|
|
|
4
4
|
than "the repository tests pass": published artifacts are installed into representative consumer
|
|
5
5
|
projects, experimental surfaces are labeled, and upstream compatibility is bounded.
|
|
6
6
|
|
|
7
|
+
It covers what is **tested** before a release ships. [`versioning.md`](./versioning.md) covers what
|
|
8
|
+
is **promised** about the surface those tests cover — which exports and options are protected by
|
|
9
|
+
semver, which are experimental, and how the peer ranges below are allowed to move.
|
|
10
|
+
|
|
7
11
|
## Stability labels
|
|
8
12
|
|
|
9
13
|
| Surface | Status | Release promise |
|
|
10
14
|
| --- | --- | --- |
|
|
11
15
|
| Mock engine | Release-supported | Documented behavior and exports are gated on every pull request and release. |
|
|
12
|
-
| Native engine | Release-supported beta | Real RN behavior, iOS/Android resolution, presets, helpers, assets, matchers, and isolation are blocking gates.
|
|
16
|
+
| Native engine | Release-supported beta | Real RN behavior, iOS/Android resolution, presets, helpers, assets, matchers, and isolation are blocking gates. Until 1.0 the [versioning contract](./versioning.md) is honoured best-effort, and a breaking change is called out in release notes. |
|
|
13
17
|
| Hot runtime | Experimental | Correctness is gated, but it depends on Vitest's experimental custom-pool API and can require adaptation between Vitest releases. |
|
|
14
18
|
| Current RN edge | Canary | Tested weekly and in a pinned packed consumer once adopted; an edge failure opens a compatibility issue. |
|
|
15
19
|
|
|
@@ -41,10 +45,23 @@ versions are rejected rather than allowed to fail later inside private runner in
|
|
|
41
45
|
9. Package export and declaration analysis with `@arethetypeswrong/cli`.
|
|
42
46
|
10. Staged npm publishing with provenance; the version remains unavailable until maintainer approval.
|
|
43
47
|
|
|
44
|
-
The ATTW gate ignores legacy Node 10 resolution because the package requires Node 20+.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
The ATTW gate ignores legacy Node 10 resolution because the package requires Node 20.19+.
|
|
49
|
+
|
|
50
|
+
Seven of the eleven `exports` subpaths are ESM-only by design — `.`, `./setup`, `./presets`, the
|
|
51
|
+
three `jest-compat` runtime shims, and the types-only `./rntl-matchers`. Each of the runtime ones
|
|
52
|
+
depends on Vitest, which throws when it is reached through `require()`, so shipping a transpiled
|
|
53
|
+
CommonJS build for them produced files that could not be loaded at all. They now declare a single
|
|
54
|
+
ESM target for both conditions: a CommonJS consumer still reaches them, through Node's `require(esm)`
|
|
55
|
+
support. That is why `engines` pins Node >= 20.19 rather than >= 20.
|
|
56
|
+
|
|
57
|
+
The remaining four subpaths ship a real CommonJS build and are checked with `cjs-resolves-to-esm`
|
|
58
|
+
enforced, so a dual entry cannot quietly lose its `.cjs`. Which subpaths are intentionally ESM-only
|
|
59
|
+
is declared in `scripts/check-exports.mjs` and checked against the manifest in both directions;
|
|
60
|
+
deriving that split from the manifest instead was verified not to work, because dropping a `.cjs`
|
|
61
|
+
simply moved the entry into the excused bucket.
|
|
62
|
+
|
|
63
|
+
Resolution is not execution: `tests/package-exports.test.ts` additionally loads every declared
|
|
64
|
+
target, and resolves and loads every subpath by specifier under both `require` and `import`.
|
|
48
65
|
|
|
49
66
|
## Release decision
|
|
50
67
|
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Versioning and stability
|
|
2
|
+
|
|
3
|
+
This document is the semver contract: what a major, minor, or patch release is allowed to change.
|
|
4
|
+
|
|
5
|
+
[`release-readiness.md`](./release-readiness.md) is the companion document. It defines what is
|
|
6
|
+
*tested* before a release ships. This one defines what is *promised* about the surface those tests
|
|
7
|
+
cover.
|
|
8
|
+
|
|
9
|
+
Until 1.0, the contract below describes intent and is honoured on a best-effort basis; breaking
|
|
10
|
+
changes are called out in release notes. **At 1.0 it becomes binding**, and everything in
|
|
11
|
+
[Covered surface](#covered-surface) is protected by semver.
|
|
12
|
+
|
|
13
|
+
## Covered surface
|
|
14
|
+
|
|
15
|
+
These are the things a major release may break, a minor may only extend, and a patch may not change
|
|
16
|
+
at all. Anything not listed here is not covered — see [Outside the contract](#outside-the-contract).
|
|
17
|
+
|
|
18
|
+
### Entry points
|
|
19
|
+
|
|
20
|
+
Only the subpaths declared in `exports` are public. Nothing under `dist/` is importable directly,
|
|
21
|
+
and deep paths are not supported even when they happen to resolve.
|
|
22
|
+
|
|
23
|
+
| Subpath | Covered exports |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `vitest-native` | `reactNative`, `presets`, `disabledPresetNames` |
|
|
26
|
+
| `vitest-native/helpers` | `setPlatform`, `setDimensions`, `setColorScheme`, `setInsets`, `mockNativeModule`, `resetAllMocks` |
|
|
27
|
+
| `vitest-native/presets` | the 16 preset factories, by name |
|
|
28
|
+
| `vitest-native/matchers` | `toHaveAnimatedStyle`, `toHaveAnimatedProps`, `animatedMatchers` |
|
|
29
|
+
| `vitest-native/serializer` | `serializer` |
|
|
30
|
+
| `vitest-native/jest-compat` | `jestMockTransform`, `jestCompatAliases`, `jestCompatSetup` |
|
|
31
|
+
| `vitest-native/jest-compat/setup`, `/jest-globals`, `/extend-expect-noop` | loadable as setup-file and alias targets |
|
|
32
|
+
| `vitest-native/rntl-matchers` | the RNTL matcher type augmentation |
|
|
33
|
+
|
|
34
|
+
The module format of an entry point is part of the contract: an entry that is loadable from
|
|
35
|
+
CommonJS stays loadable from CommonJS. Which entries those are is enforced by `check:exports`, and
|
|
36
|
+
every subpath is loaded by specifier under both `require` and `import` in
|
|
37
|
+
`tests/package-exports.test.ts`.
|
|
38
|
+
|
|
39
|
+
### Plugin options
|
|
40
|
+
|
|
41
|
+
The keys accepted by the plugin function are `engine`, `platform`, `presets`, `mocks`,
|
|
42
|
+
`diagnostics`, `assetExts`, `transform`, `hotRuntime`. Their accepted types and their defaults are
|
|
43
|
+
covered. An unknown key is rejected at configuration time, so adding a key is a minor and removing
|
|
44
|
+
or renaming one is a major.
|
|
45
|
+
|
|
46
|
+
`hotRuntime` is the exception — see [Experimental](#experimental).
|
|
47
|
+
|
|
48
|
+
### Preset authoring
|
|
49
|
+
|
|
50
|
+
The `Preset` and `PresetModule` types are a public extension point: third-party presets can be
|
|
51
|
+
written and passed to `presets: [...]`. Covered: the shape `{ name, modules, config? }`, that
|
|
52
|
+
`PresetModule.exports` is read at config time, and that `PresetModule.factory` is called only
|
|
53
|
+
inside a Vitest worker.
|
|
54
|
+
|
|
55
|
+
`factory` may gain optional parameters in a minor, since that does not break an existing
|
|
56
|
+
zero-argument factory. Its return type and call site will not change without a major.
|
|
57
|
+
|
|
58
|
+
### Error codes
|
|
59
|
+
|
|
60
|
+
Thrown errors carry a stable `code`. The `code` values and the error classes are covered; the
|
|
61
|
+
human-readable `message` text is not.
|
|
62
|
+
|
|
63
|
+
### CLI
|
|
64
|
+
|
|
65
|
+
The command names `doctor`, `init`, and `migrate`, their documented flags, and their exit codes.
|
|
66
|
+
The wording and layout of what they print is not covered.
|
|
67
|
+
|
|
68
|
+
## Outside the contract
|
|
69
|
+
|
|
70
|
+
Changing any of these is a patch or minor, and never requires a major.
|
|
71
|
+
|
|
72
|
+
- **The wording of any message** — diagnostics, warnings, `doctor`/`init`/`migrate` output, and
|
|
73
|
+
error `message` strings. Assert on error `code`, not on text.
|
|
74
|
+
- **What a preset mocks.** Presets track upstream libraries. When `react-native-reanimated` adds an
|
|
75
|
+
export, the preset gains it in a minor; when upstream removes one, the preset drops it in a minor.
|
|
76
|
+
The preset's *existence and name* are covered; its mocked surface follows upstream.
|
|
77
|
+
- **Mock-engine fidelity details.** The mock engine's job is to match real React Native. A change
|
|
78
|
+
that moves it *closer* to real RN is a fix, even if a test was relying on the divergence. The
|
|
79
|
+
cross-check corpus and `crosscheck/known-differences.json` record where the two intentionally
|
|
80
|
+
differ.
|
|
81
|
+
- **Anything reachable only by deep import** into `dist/`.
|
|
82
|
+
- **Internal cache layout** under `node_modules/.cache/vitest-native`.
|
|
83
|
+
|
|
84
|
+
## Experimental
|
|
85
|
+
|
|
86
|
+
Experimental surfaces are excluded from the contract at every version, including after 1.0. They
|
|
87
|
+
are documented, tested, and gated in CI — they are simply not stable, and they say so.
|
|
88
|
+
|
|
89
|
+
| Surface | Why |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `hotRuntime` and its options | Built on Vitest's experimental custom-pool API, which can change between Vitest minors. Off by default. |
|
|
92
|
+
|
|
93
|
+
A surface leaves this list by being promoted in a minor, and can change or be removed in a minor
|
|
94
|
+
while it is on it.
|
|
95
|
+
|
|
96
|
+
## Upstream support ranges
|
|
97
|
+
|
|
98
|
+
`vitest-native` sits between several fast-moving projects — Node, Vite, Vitest, React, React
|
|
99
|
+
Native, and React Native Testing Library. Treating every peer-range change as a major would make
|
|
100
|
+
the package unable to keep up, which is the main way a tool like this dies. So peer ranges are
|
|
101
|
+
handled explicitly:
|
|
102
|
+
|
|
103
|
+
- **Adding support** for a new upstream version is a **minor**.
|
|
104
|
+
- **Dropping a version that upstream has already end-of-lifed** is a **minor**, announced in the
|
|
105
|
+
release notes. The package does not promise to outlive its own dependencies.
|
|
106
|
+
- **Dropping a version upstream still supports** is a **major**.
|
|
107
|
+
- **Raising the Node floor** is a **minor** when the versions dropped are end-of-life, and a
|
|
108
|
+
**major** otherwise.
|
|
109
|
+
|
|
110
|
+
The currently supported ranges are in [Requirements](../README.md#requirements) and the blocking
|
|
111
|
+
matrix in [`release-readiness.md`](./release-readiness.md#blocking-compatibility-matrix). Those are
|
|
112
|
+
the authoritative lists; this document only says how they may move.
|
|
113
|
+
|
|
114
|
+
## Deprecation
|
|
115
|
+
|
|
116
|
+
1. A deprecated surface keeps working and gains a runtime warning naming the replacement, plus a
|
|
117
|
+
note in the docs and release notes. This happens in a **minor**.
|
|
118
|
+
2. It is removed no earlier than the **next major**.
|
|
119
|
+
|
|
120
|
+
Something can only be removed without this cycle if it never worked — an entry point that always
|
|
121
|
+
threw, for example, is a bug being fixed, not an API being removed.
|
|
122
|
+
|
|
123
|
+
## What 1.0 means
|
|
124
|
+
|
|
125
|
+
1.0 is not a statement that the code has stopped changing. It is a statement that:
|
|
126
|
+
|
|
127
|
+
- the surface above is enumerated, deliberate, and protected by semver;
|
|
128
|
+
- the parts that are not stable are labelled, rather than silently included;
|
|
129
|
+
- the tests and gates in [`release-readiness.md`](./release-readiness.md) are what stand behind the
|
|
130
|
+
promise, and each one checks the thing it claims to check.
|
|
131
|
+
|
|
132
|
+
Reaching it does not require new features. It requires the surface to be exactly what this document
|
|
133
|
+
says it is.
|