vitest-native 0.13.0 → 0.14.0-rc.2
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 +339 -0
- package/README.md +138 -48
- package/dist/cli.cjs +70 -5
- package/dist/cli.d.cts +2 -3
- package/dist/cli.d.mts +2 -3
- package/dist/cli.mjs +70 -5
- package/dist/{ecosystem-Duw40-mO.mjs → ecosystem-DFbU_MPe.mjs} +389 -18
- package/dist/{ecosystem-CEIF_-jq.cjs → ecosystem-DI1AhK_k.cjs} +408 -25
- package/dist/errors.d.mts +12 -0
- package/dist/helpers.cjs +6 -3
- package/dist/helpers.d.cts +8 -9
- package/dist/helpers.d.mts +8 -9
- package/dist/helpers.mjs +6 -3
- package/dist/{index-CPGq6p95.d.cts → index-BxzW2D7K.d.cts} +33 -9
- package/dist/{index-CmETArCM.d.mts → index-CEbwa4QU.d.mts} +33 -9
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +537 -118
- package/dist/jest-compat/aliases.d.mts +5 -0
- package/dist/jest-compat/aliases.mjs +65 -0
- package/dist/jest-compat/caller.mjs +53 -0
- package/dist/jest-compat/setup.mjs +72 -36
- package/dist/jest-compat.cjs +1 -3
- package/dist/jest-compat.d.cts +4 -5
- package/dist/jest-compat.d.mts +4 -5
- package/dist/jest-compat.mjs +1 -1
- package/dist/matchers.d.cts +9 -9
- package/dist/matchers.d.mts +9 -9
- package/dist/memory-6EPHrJA1.cjs +144 -0
- package/dist/memory-FYbP0_gg.mjs +126 -0
- package/dist/native/boundary.mjs +13 -2
- package/dist/native/bounded-process.mjs +165 -0
- package/dist/native/export-condition-recovery-preload.mjs +5 -0
- package/dist/native/export-condition-recovery.mjs +195 -0
- package/dist/native/globals.mjs +133 -5
- package/dist/native/hooks.mjs +131 -71
- package/dist/native/loader.mjs +41 -28
- package/dist/native/match.d.mts +3 -0
- package/dist/native/match.mjs +38 -2
- package/dist/native/metro-profile-compiler.mjs +234 -0
- package/dist/native/metro-profile.mjs +115 -0
- package/dist/native/module-reset.mjs +111 -6
- package/dist/native/ownership.d.mts +105 -0
- package/dist/native/ownership.mjs +474 -0
- package/dist/native/registry-compiler.mjs +43 -0
- package/dist/native/registry-process.mjs +124 -0
- package/dist/native/registry.mjs +139 -32
- package/dist/native/reset.mjs +305 -135
- package/dist/native/resolve.d.mts +20 -3
- package/dist/native/resolve.mjs +32 -12
- package/dist/native/rntl-hooks.mjs +76 -0
- package/dist/native/setup.mjs +81 -32
- package/dist/native/state-manifest.d.mts +22 -0
- package/dist/native/state-manifest.mjs +136 -0
- package/dist/native/transform.mjs +29 -8
- package/dist/native/worker.mjs +52 -4
- package/dist/pool-B4yesGhI.cjs +121 -0
- package/dist/pool-DjpOjOf3.mjs +119 -0
- package/dist/{presets-CoNf4ByH.cjs → presets-BYHmi7-W.cjs} +117 -18
- package/dist/{presets-DGProTaA.mjs → presets-DC-eM5IA.mjs} +117 -18
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rntl-matchers.d.ts +58 -12
- package/dist/serializer.cjs +4 -2
- package/dist/serializer.d.cts +3 -4
- package/dist/serializer.d.mts +3 -4
- package/dist/serializer.mjs +4 -2
- package/dist/setup.mjs +61 -50
- package/dist/worker-vitest-BGPo0ek6.mjs +49 -0
- package/dist/worker-vitest-BfiQB8ND.cjs +62 -0
- package/docs/hot-default-design.md +175 -88
- package/docs/migrating-from-jest.md +12 -5
- package/docs/migrating-from-vitest-react-native.md +4 -4
- package/docs/release-readiness.md +39 -13
- package/docs/versioning.md +19 -18
- package/package.json +42 -31
- package/dist/pool-BU-1ecIF.cjs +0 -122
- package/dist/pool-Bcxn9a3I.mjs +0 -118
package/dist/serializer.cjs
CHANGED
|
@@ -111,8 +111,10 @@ const serializer = {
|
|
|
111
111
|
let children = [];
|
|
112
112
|
if (Array.isArray(val.children)) children = val.children.filter((c) => c != null);
|
|
113
113
|
else if (val.children != null) children = [val.children];
|
|
114
|
-
else if (props.children != null)
|
|
115
|
-
|
|
114
|
+
else if (props.children != null) {
|
|
115
|
+
if (Array.isArray(props.children)) children = props.children.filter((c) => c != null);
|
|
116
|
+
else children = [props.children];
|
|
117
|
+
}
|
|
116
118
|
let result = `${indentation}<${typeName}`;
|
|
117
119
|
if (propKeys.length > 0) for (const key of propKeys.sort()) {
|
|
118
120
|
const value = props[key];
|
package/dist/serializer.d.cts
CHANGED
|
@@ -7,10 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Usage: expect.addSnapshotSerializer(serializer)
|
|
9
9
|
*/
|
|
10
|
-
interface SnapshotSerializer {
|
|
10
|
+
export interface SnapshotSerializer {
|
|
11
11
|
serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
|
|
12
12
|
test(val: any): boolean;
|
|
13
13
|
}
|
|
14
|
-
declare const serializer: SnapshotSerializer;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { SnapshotSerializer, serializer };
|
|
14
|
+
export declare const serializer: SnapshotSerializer;
|
|
15
|
+
//#endregion
|
package/dist/serializer.d.mts
CHANGED
|
@@ -7,10 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Usage: expect.addSnapshotSerializer(serializer)
|
|
9
9
|
*/
|
|
10
|
-
interface SnapshotSerializer {
|
|
10
|
+
export interface SnapshotSerializer {
|
|
11
11
|
serialize(val: any, config: any, indentation: string, depth: number, refs: any[], printer: Function): string;
|
|
12
12
|
test(val: any): boolean;
|
|
13
13
|
}
|
|
14
|
-
declare const serializer: SnapshotSerializer;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { SnapshotSerializer, serializer };
|
|
14
|
+
export declare const serializer: SnapshotSerializer;
|
|
15
|
+
//#endregion
|
package/dist/serializer.mjs
CHANGED
|
@@ -110,8 +110,10 @@ const serializer = {
|
|
|
110
110
|
let children = [];
|
|
111
111
|
if (Array.isArray(val.children)) children = val.children.filter((c) => c != null);
|
|
112
112
|
else if (val.children != null) children = [val.children];
|
|
113
|
-
else if (props.children != null)
|
|
114
|
-
|
|
113
|
+
else if (props.children != null) {
|
|
114
|
+
if (Array.isArray(props.children)) children = props.children.filter((c) => c != null);
|
|
115
|
+
else children = [props.children];
|
|
116
|
+
}
|
|
115
117
|
let result = `${indentation}<${typeName}`;
|
|
116
118
|
if (propKeys.length > 0) for (const key of propKeys.sort()) {
|
|
117
119
|
const value = props[key];
|
package/dist/setup.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __require } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
2
|
import { t as AUTO_DETECT_PRESETS } from "./preset-map-DuX0ocdn.mjs";
|
|
3
|
-
import { D as createPressableMock, O as buildPressableHostProps, 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-
|
|
3
|
+
import { D as createPressableMock, O as buildPressableHostProps, 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-DC-eM5IA.mjs";
|
|
4
4
|
import { serializer } from "./serializer.mjs";
|
|
5
5
|
import { animatedMatchers } from "./matchers.mjs";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
@@ -153,19 +153,30 @@ function createRefreshControlMock() {
|
|
|
153
153
|
return RefreshControl;
|
|
154
154
|
}
|
|
155
155
|
//#endregion
|
|
156
|
+
//#region src/mocks/mock-fn.ts
|
|
157
|
+
/**
|
|
158
|
+
* `vi.fn()` with no implementation, typed so declaration emit can name it. A bare
|
|
159
|
+
* `vi.fn()` infers `Mock<Procedure>`, and Vitest does not export `Procedure`, so
|
|
160
|
+
* TypeScript 7 refuses to emit the inferred type of any factory that returns one
|
|
161
|
+
* (TS2883). `vi.fn(impl)` infers from the implementation and needs no help.
|
|
162
|
+
*/
|
|
163
|
+
function mockFn() {
|
|
164
|
+
return vi.fn();
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
156
167
|
//#region src/mocks/components/StatusBar.ts
|
|
157
168
|
function createStatusBarMock() {
|
|
158
169
|
function StatusBar(props) {
|
|
159
170
|
return React.createElement("StatusBar", props);
|
|
160
171
|
}
|
|
161
172
|
StatusBar.displayName = "StatusBar";
|
|
162
|
-
StatusBar.setBarStyle =
|
|
163
|
-
StatusBar.setBackgroundColor =
|
|
164
|
-
StatusBar.setHidden =
|
|
165
|
-
StatusBar.setNetworkActivityIndicatorVisible =
|
|
166
|
-
StatusBar.setTranslucent =
|
|
173
|
+
StatusBar.setBarStyle = mockFn();
|
|
174
|
+
StatusBar.setBackgroundColor = mockFn();
|
|
175
|
+
StatusBar.setHidden = mockFn();
|
|
176
|
+
StatusBar.setNetworkActivityIndicatorVisible = mockFn();
|
|
177
|
+
StatusBar.setTranslucent = mockFn();
|
|
167
178
|
StatusBar.pushStackEntry = vi.fn(() => ({}));
|
|
168
|
-
StatusBar.popStackEntry =
|
|
179
|
+
StatusBar.popStackEntry = mockFn();
|
|
169
180
|
StatusBar.replaceStackEntry = vi.fn(() => ({}));
|
|
170
181
|
StatusBar.currentHeight = 44;
|
|
171
182
|
return StatusBar;
|
|
@@ -341,7 +352,7 @@ function createStyleSheetMock(getScale = () => 3) {
|
|
|
341
352
|
top: 0,
|
|
342
353
|
bottom: 0
|
|
343
354
|
},
|
|
344
|
-
setStyleAttributePreprocessor:
|
|
355
|
+
setStyleAttributePreprocessor: mockFn()
|
|
345
356
|
};
|
|
346
357
|
Object.defineProperty(sheet, "hairlineWidth", {
|
|
347
358
|
enumerable: true,
|
|
@@ -379,8 +390,8 @@ function interpolateSegment(input, inputMin, inputMax, outputMin, outputMax, eas
|
|
|
379
390
|
return result;
|
|
380
391
|
}
|
|
381
392
|
function findRangeIndex(input, inputRange) {
|
|
382
|
-
let i;
|
|
383
|
-
for (
|
|
393
|
+
let i = 1;
|
|
394
|
+
for (; i < inputRange.length - 1; ++i) if (inputRange[i] >= input) break;
|
|
384
395
|
return i - 1;
|
|
385
396
|
}
|
|
386
397
|
function interpolateNumeric(value, inputRange, outputRange, extrapolate, extrapolateLeft, extrapolateRight, easing) {
|
|
@@ -1041,7 +1052,7 @@ function createAnimation(onStart) {
|
|
|
1041
1052
|
stop: vi.fn((callback) => {
|
|
1042
1053
|
callback?.({ finished: false });
|
|
1043
1054
|
}),
|
|
1044
|
-
reset:
|
|
1055
|
+
reset: mockFn()
|
|
1045
1056
|
};
|
|
1046
1057
|
}
|
|
1047
1058
|
function resolveAnimatedLeaf(v) {
|
|
@@ -1351,7 +1362,7 @@ function createAnimatedMock() {
|
|
|
1351
1362
|
listener(...args);
|
|
1352
1363
|
};
|
|
1353
1364
|
}),
|
|
1354
|
-
unforkEvent:
|
|
1365
|
+
unforkEvent: mockFn(),
|
|
1355
1366
|
createAnimatedComponent: vi.fn((component) => {
|
|
1356
1367
|
const Wrapper = React.forwardRef((props, ref) => {
|
|
1357
1368
|
useAnimatedStyleSubscription(props?.style);
|
|
@@ -1383,8 +1394,8 @@ function createAnimatedMock() {
|
|
|
1383
1394
|
//#region src/mocks/apis/Alert.ts
|
|
1384
1395
|
function createAlertMock() {
|
|
1385
1396
|
return {
|
|
1386
|
-
alert:
|
|
1387
|
-
prompt:
|
|
1397
|
+
alert: mockFn(),
|
|
1398
|
+
prompt: mockFn()
|
|
1388
1399
|
};
|
|
1389
1400
|
}
|
|
1390
1401
|
//#endregion
|
|
@@ -1396,7 +1407,7 @@ function createLinkingMock() {
|
|
|
1396
1407
|
getInitialURL: vi.fn(() => Promise.resolve(null)),
|
|
1397
1408
|
openSettings: vi.fn(() => Promise.resolve()),
|
|
1398
1409
|
sendIntent: vi.fn(() => Promise.resolve()),
|
|
1399
|
-
addEventListener: vi.fn(() => ({ remove:
|
|
1410
|
+
addEventListener: vi.fn(() => ({ remove: mockFn() }))
|
|
1400
1411
|
};
|
|
1401
1412
|
}
|
|
1402
1413
|
//#endregion
|
|
@@ -1474,7 +1485,7 @@ function createKeyboardMock() {
|
|
|
1474
1485
|
width: 390,
|
|
1475
1486
|
height: keyboardHeight
|
|
1476
1487
|
} : void 0),
|
|
1477
|
-
scheduleLayoutAnimation:
|
|
1488
|
+
scheduleLayoutAnimation: mockFn(),
|
|
1478
1489
|
_show: (height = 336) => {
|
|
1479
1490
|
visible = true;
|
|
1480
1491
|
keyboardHeight = height;
|
|
@@ -1500,7 +1511,7 @@ function createKeyboardMock() {
|
|
|
1500
1511
|
function createBackHandlerMock() {
|
|
1501
1512
|
const listeners = /* @__PURE__ */ new Set();
|
|
1502
1513
|
return {
|
|
1503
|
-
exitApp:
|
|
1514
|
+
exitApp: mockFn(),
|
|
1504
1515
|
addEventListener: vi.fn((event, handler) => {
|
|
1505
1516
|
if (event === "hardwareBackPress") listeners.add(handler);
|
|
1506
1517
|
return { remove: vi.fn(() => listeners.delete(handler)) };
|
|
@@ -1518,8 +1529,8 @@ function createBackHandlerMock() {
|
|
|
1518
1529
|
//#region src/mocks/apis/Vibration.ts
|
|
1519
1530
|
function createVibrationMock() {
|
|
1520
1531
|
return {
|
|
1521
|
-
vibrate:
|
|
1522
|
-
cancel:
|
|
1532
|
+
vibrate: mockFn(),
|
|
1533
|
+
cancel: mockFn()
|
|
1523
1534
|
};
|
|
1524
1535
|
}
|
|
1525
1536
|
//#endregion
|
|
@@ -1621,7 +1632,7 @@ function createPixelRatioMock(getDimensions) {
|
|
|
1621
1632
|
//#endregion
|
|
1622
1633
|
//#region src/mocks/apis/LayoutAnimation.ts
|
|
1623
1634
|
function createLayoutAnimationMock() {
|
|
1624
|
-
const configureNext =
|
|
1635
|
+
const configureNext = mockFn();
|
|
1625
1636
|
const presets = {
|
|
1626
1637
|
easeInEaseOut: {
|
|
1627
1638
|
duration: 300,
|
|
@@ -1697,7 +1708,7 @@ function createLayoutAnimationMock() {
|
|
|
1697
1708
|
checkConfig: vi.fn(() => {
|
|
1698
1709
|
console.error("LayoutAnimation.checkConfig(...) has been disabled.");
|
|
1699
1710
|
}),
|
|
1700
|
-
setEnabled:
|
|
1711
|
+
setEnabled: mockFn()
|
|
1701
1712
|
};
|
|
1702
1713
|
}
|
|
1703
1714
|
//#endregion
|
|
@@ -1732,11 +1743,11 @@ function createAccessibilityInfoMock() {
|
|
|
1732
1743
|
isReduceMotionEnabled: vi.fn(async () => false),
|
|
1733
1744
|
isReduceTransparencyEnabled: vi.fn(async () => false),
|
|
1734
1745
|
prefersCrossFadeTransitions: vi.fn(async () => false),
|
|
1735
|
-
addEventListener: vi.fn((_eventName, _handler) => ({ remove:
|
|
1736
|
-
announceForAccessibility:
|
|
1737
|
-
announceForAccessibilityWithOptions:
|
|
1738
|
-
setAccessibilityFocus:
|
|
1739
|
-
sendAccessibilityEvent:
|
|
1746
|
+
addEventListener: vi.fn((_eventName, _handler) => ({ remove: mockFn() })),
|
|
1747
|
+
announceForAccessibility: mockFn(),
|
|
1748
|
+
announceForAccessibilityWithOptions: mockFn(),
|
|
1749
|
+
setAccessibilityFocus: mockFn(),
|
|
1750
|
+
sendAccessibilityEvent: mockFn(),
|
|
1740
1751
|
getRecommendedTimeoutMillis: vi.fn(async (originalTimeout) => originalTimeout)
|
|
1741
1752
|
};
|
|
1742
1753
|
}
|
|
@@ -1750,12 +1761,12 @@ function createInteractionManagerMock() {
|
|
|
1750
1761
|
return {
|
|
1751
1762
|
then: promise.then.bind(promise),
|
|
1752
1763
|
done: promise.then.bind(promise),
|
|
1753
|
-
cancel:
|
|
1764
|
+
cancel: mockFn()
|
|
1754
1765
|
};
|
|
1755
1766
|
}),
|
|
1756
1767
|
createInteractionHandle: vi.fn(() => 1),
|
|
1757
|
-
clearInteractionHandle:
|
|
1758
|
-
setDeadline:
|
|
1768
|
+
clearInteractionHandle: mockFn(),
|
|
1769
|
+
setDeadline: mockFn()
|
|
1759
1770
|
};
|
|
1760
1771
|
}
|
|
1761
1772
|
//#endregion
|
|
@@ -1803,9 +1814,9 @@ function createPanResponderMock() {
|
|
|
1803
1814
|
//#region src/mocks/apis/ToastAndroid.ts
|
|
1804
1815
|
function createToastAndroidMock() {
|
|
1805
1816
|
return {
|
|
1806
|
-
show:
|
|
1807
|
-
showWithGravity:
|
|
1808
|
-
showWithGravityAndOffset:
|
|
1817
|
+
show: mockFn(),
|
|
1818
|
+
showWithGravity: mockFn(),
|
|
1819
|
+
showWithGravityAndOffset: mockFn(),
|
|
1809
1820
|
SHORT: 0,
|
|
1810
1821
|
LONG: 1,
|
|
1811
1822
|
TOP: 0,
|
|
@@ -1817,18 +1828,18 @@ function createToastAndroidMock() {
|
|
|
1817
1828
|
//#region src/mocks/apis/ActionSheetIOS.ts
|
|
1818
1829
|
function createActionSheetIOSMock() {
|
|
1819
1830
|
return {
|
|
1820
|
-
showActionSheetWithOptions:
|
|
1821
|
-
showShareActionSheetWithOptions:
|
|
1831
|
+
showActionSheetWithOptions: mockFn(),
|
|
1832
|
+
showShareActionSheetWithOptions: mockFn()
|
|
1822
1833
|
};
|
|
1823
1834
|
}
|
|
1824
1835
|
//#endregion
|
|
1825
1836
|
//#region src/mocks/apis/LogBox.ts
|
|
1826
1837
|
function createLogBoxMock() {
|
|
1827
1838
|
return {
|
|
1828
|
-
ignoreLogs:
|
|
1829
|
-
ignoreAllLogs:
|
|
1830
|
-
uninstall:
|
|
1831
|
-
install:
|
|
1839
|
+
ignoreLogs: mockFn(),
|
|
1840
|
+
ignoreAllLogs: mockFn(),
|
|
1841
|
+
uninstall: mockFn(),
|
|
1842
|
+
install: mockFn()
|
|
1832
1843
|
};
|
|
1833
1844
|
}
|
|
1834
1845
|
//#endregion
|
|
@@ -1985,7 +1996,7 @@ function createDeviceEventEmitterMock() {
|
|
|
1985
1996
|
if (event) listeners.delete(event);
|
|
1986
1997
|
else listeners.clear();
|
|
1987
1998
|
}),
|
|
1988
|
-
removeSubscription:
|
|
1999
|
+
removeSubscription: mockFn(),
|
|
1989
2000
|
emit: vi.fn((event, ...args) => {
|
|
1990
2001
|
listeners.get(event)?.forEach((fn) => fn(...args));
|
|
1991
2002
|
}),
|
|
@@ -2142,19 +2153,19 @@ function createUIManagerMock() {
|
|
|
2142
2153
|
measureLayout: vi.fn((_node, _relativeNode, _onFail, onSuccess) => {
|
|
2143
2154
|
onSuccess(0, 0, 0, 0);
|
|
2144
2155
|
}),
|
|
2145
|
-
setChildren:
|
|
2146
|
-
manageChildren:
|
|
2147
|
-
createView:
|
|
2148
|
-
updateView:
|
|
2149
|
-
removeSubviewsFromContainerWithID:
|
|
2150
|
-
replaceExistingNonRootView:
|
|
2151
|
-
setLayoutAnimationEnabledExperimental:
|
|
2152
|
-
configureNextLayoutAnimation:
|
|
2156
|
+
setChildren: mockFn(),
|
|
2157
|
+
manageChildren: mockFn(),
|
|
2158
|
+
createView: mockFn(),
|
|
2159
|
+
updateView: mockFn(),
|
|
2160
|
+
removeSubviewsFromContainerWithID: mockFn(),
|
|
2161
|
+
replaceExistingNonRootView: mockFn(),
|
|
2162
|
+
setLayoutAnimationEnabledExperimental: mockFn(),
|
|
2163
|
+
configureNextLayoutAnimation: mockFn(),
|
|
2153
2164
|
getViewManagerConfig: vi.fn((_name) => ({})),
|
|
2154
2165
|
hasViewManagerConfig: vi.fn((_name) => false),
|
|
2155
|
-
dispatchViewManagerCommand:
|
|
2156
|
-
findSubviewIn:
|
|
2157
|
-
viewIsDescendantOf:
|
|
2166
|
+
dispatchViewManagerCommand: mockFn(),
|
|
2167
|
+
findSubviewIn: mockFn(),
|
|
2168
|
+
viewIsDescendantOf: mockFn()
|
|
2158
2169
|
};
|
|
2159
2170
|
}
|
|
2160
2171
|
//#endregion
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { t as VitestNativeError } from "./errors-CxoBUfVJ.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/native/worker-vitest.ts
|
|
5
|
+
/**
|
|
6
|
+
* Fail fast when the hot worker would load a different Vitest VERSION from the
|
|
7
|
+
* project's.
|
|
8
|
+
*
|
|
9
|
+
* The worker entry ships inside this package, so its `import 'vitest/worker'`
|
|
10
|
+
* resolves from THIS package's location rather than the project's. Where a monorepo
|
|
11
|
+
* has more than one Vitest install — a linked package, a hoisted `node_modules`,
|
|
12
|
+
* mixed versions across workspaces — the two can differ, and a version difference is
|
|
13
|
+
* invisible at runtime: the start handshake succeeds, the run request is accepted,
|
|
14
|
+
* and no result is ever reported. Vitest then prints "No test files found" with no
|
|
15
|
+
* error at all, and on some paths still exits 0 — a green run that tested nothing.
|
|
16
|
+
*
|
|
17
|
+
* Only a VERSION difference is an error. Two installs of the same version are two
|
|
18
|
+
* module registries but identical code, and they talk to each other perfectly well;
|
|
19
|
+
* failing on the paths alone would block working monorepos where the same version is
|
|
20
|
+
* simply installed twice.
|
|
21
|
+
*/
|
|
22
|
+
function workerVitestMismatch(workerEntry, projectRoot) {
|
|
23
|
+
const resolveVitest = (from) => {
|
|
24
|
+
try {
|
|
25
|
+
const require_ = createRequire(from);
|
|
26
|
+
const pkgPath = require_.resolve("vitest/package.json");
|
|
27
|
+
return {
|
|
28
|
+
path: pkgPath,
|
|
29
|
+
version: require_(pkgPath).version
|
|
30
|
+
};
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const worker = resolveVitest(workerEntry);
|
|
36
|
+
const project = resolveVitest(path.join(projectRoot, "package.json"));
|
|
37
|
+
if (worker === null || project === null || worker.version === project.version) return null;
|
|
38
|
+
return {
|
|
39
|
+
worker,
|
|
40
|
+
project
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** The error for an explicit hotRuntime whose worker would run a different Vitest. */
|
|
44
|
+
function workerVitestMismatchError(mismatch) {
|
|
45
|
+
const { worker, project } = mismatch;
|
|
46
|
+
return new VitestNativeError("HOT_RUNTIME_UNAVAILABLE", `'hotRuntime' cannot run: its worker would load vitest@${worker.version}, but this run is driven by vitest@${project.version}. They talk over Vitest's worker protocol, and a version mismatch reports no results at all rather than failing.\n worker would load: ${worker.path}\n project resolves: ${project.path}\nThis happens when vitest-native and vitest resolve to different node_modules trees (linked packages, hoisted monorepo installs, mixed Vitest versions). Install one Vitest version reachable from vitest-native, or set 'hotRuntime: false'.`);
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { workerVitestMismatchError as n, workerVitestMismatch as t };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_errors = require("./errors-B3lJK46O.cjs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
|
+
let node_module = require("node:module");
|
|
6
|
+
//#region src/native/worker-vitest.ts
|
|
7
|
+
/**
|
|
8
|
+
* Fail fast when the hot worker would load a different Vitest VERSION from the
|
|
9
|
+
* project's.
|
|
10
|
+
*
|
|
11
|
+
* The worker entry ships inside this package, so its `import 'vitest/worker'`
|
|
12
|
+
* resolves from THIS package's location rather than the project's. Where a monorepo
|
|
13
|
+
* has more than one Vitest install — a linked package, a hoisted `node_modules`,
|
|
14
|
+
* mixed versions across workspaces — the two can differ, and a version difference is
|
|
15
|
+
* invisible at runtime: the start handshake succeeds, the run request is accepted,
|
|
16
|
+
* and no result is ever reported. Vitest then prints "No test files found" with no
|
|
17
|
+
* error at all, and on some paths still exits 0 — a green run that tested nothing.
|
|
18
|
+
*
|
|
19
|
+
* Only a VERSION difference is an error. Two installs of the same version are two
|
|
20
|
+
* module registries but identical code, and they talk to each other perfectly well;
|
|
21
|
+
* failing on the paths alone would block working monorepos where the same version is
|
|
22
|
+
* simply installed twice.
|
|
23
|
+
*/
|
|
24
|
+
function workerVitestMismatch(workerEntry, projectRoot) {
|
|
25
|
+
const resolveVitest = (from) => {
|
|
26
|
+
try {
|
|
27
|
+
const require_ = (0, node_module.createRequire)(from);
|
|
28
|
+
const pkgPath = require_.resolve("vitest/package.json");
|
|
29
|
+
return {
|
|
30
|
+
path: pkgPath,
|
|
31
|
+
version: require_(pkgPath).version
|
|
32
|
+
};
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const worker = resolveVitest(workerEntry);
|
|
38
|
+
const project = resolveVitest(node_path.default.join(projectRoot, "package.json"));
|
|
39
|
+
if (worker === null || project === null || worker.version === project.version) return null;
|
|
40
|
+
return {
|
|
41
|
+
worker,
|
|
42
|
+
project
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The error for an explicit hotRuntime whose worker would run a different Vitest. */
|
|
46
|
+
function workerVitestMismatchError(mismatch) {
|
|
47
|
+
const { worker, project } = mismatch;
|
|
48
|
+
return new require_errors.VitestNativeError("HOT_RUNTIME_UNAVAILABLE", `'hotRuntime' cannot run: its worker would load vitest@${worker.version}, but this run is driven by vitest@${project.version}. They talk over Vitest's worker protocol, and a version mismatch reports no results at all rather than failing.\n worker would load: ${worker.path}\n project resolves: ${project.path}\nThis happens when vitest-native and vitest resolve to different node_modules trees (linked packages, hoisted monorepo installs, mixed Vitest versions). Install one Vitest version reachable from vitest-native, or set 'hotRuntime: false'.`);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
Object.defineProperty(exports, "workerVitestMismatch", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return workerVitestMismatch;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "workerVitestMismatchError", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function() {
|
|
60
|
+
return workerVitestMismatchError;
|
|
61
|
+
}
|
|
62
|
+
});
|