vitest-native 0.14.1 → 0.15.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/README.md +11 -10
- package/dist/cli.d.mts +9 -1
- package/dist/cli.mjs +2609 -361
- package/dist/context.d.mts +19 -0
- package/dist/context.mjs +47 -1
- package/dist/docs-url.d.mts +4 -0
- package/dist/docs-url.mjs +9 -0
- package/dist/errors.d.mts +21 -1
- package/dist/hang-watch-setup.mjs +55 -0
- package/dist/hang-watch.d.mts +56 -0
- package/dist/hang-watch.mjs +343 -0
- package/dist/helpers.cjs +24 -53
- package/dist/helpers.mjs +22 -1
- package/dist/host-D0r3P_T1.mjs +1985 -0
- package/dist/{index-aNBCTfA5.d.mts → index-JOR602XU.d.mts} +105 -2
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +723 -149
- package/dist/jest-compat/aliases.d.mts +1 -0
- package/dist/jest-compat/aliases.mjs +11 -0
- package/dist/jest-compat/interop.mjs +1 -1
- package/dist/jest-compat/jest-object.mjs +23 -5
- package/dist/jest-compat/node-registry.mjs +836 -68
- package/dist/jest-compat/setup.mjs +205 -12
- package/dist/jest-compat.cjs +383 -47
- package/dist/jest-compat.d.cts +19 -2
- package/dist/jest-compat.d.mts +19 -2
- package/dist/jest-compat.mjs +232 -47
- package/dist/matchers.d.cts +0 -1
- package/dist/matchers.d.mts +0 -1
- package/dist/native/assets.mjs +3 -1
- package/dist/native/babel-caller.d.mts +13 -0
- package/dist/native/babel-caller.mjs +24 -0
- package/dist/native/babel-toolchain.mjs +27 -3
- package/dist/native/boundary.mjs +45 -8
- package/dist/native/bounded-process.mjs +63 -5
- package/dist/native/bridge-client.mjs +133 -0
- package/dist/native/bridge-server.mjs +215 -0
- package/dist/native/bridge-thread.mjs +79 -0
- package/dist/native/bridge.mjs +512 -0
- package/dist/native/compile-error.mjs +120 -0
- package/dist/native/explain.mjs +3 -2
- package/dist/native/expo-module-mocks.mjs +2 -0
- package/dist/native/export-condition-recovery.mjs +20 -99
- package/dist/native/hooks.mjs +256 -133
- package/dist/native/jest-resolvers.mjs +94 -0
- package/dist/native/library-jest.mjs +352 -0
- package/dist/native/loader.mjs +167 -73
- package/dist/native/match.mjs +67 -7
- package/dist/native/module-reset.mjs +44 -49
- package/dist/native/ownership-ledger.d.mts +87 -0
- package/dist/native/ownership-ledger.mjs +524 -0
- package/dist/native/ownership.d.mts +20 -0
- package/dist/native/ownership.mjs +114 -0
- package/dist/native/registry-compiler.mjs +39 -5
- package/dist/native/registry-process.mjs +327 -28
- package/dist/native/registry.mjs +752 -200
- package/dist/native/resident-health.mjs +1 -0
- package/dist/native/resolve.d.mts +7 -0
- package/dist/native/resolve.mjs +119 -4
- package/dist/native/rntl-hooks.mjs +9 -5
- package/dist/native/rntl-text-host.mjs +5 -15
- package/dist/native/root-spelling.d.mts +6 -0
- package/dist/native/root-spelling.mjs +77 -0
- package/dist/native/runner.mjs +2 -19
- package/dist/native/setup.mjs +119 -38
- package/dist/native/shared-resolver.d.mts +141 -0
- package/dist/native/shared-resolver.mjs +719 -0
- package/dist/native/test-runner.mjs +26 -0
- package/dist/native/transform.mjs +18 -22
- package/dist/native/worker.mjs +9 -4
- package/dist/node-dispatch.mjs +293 -0
- package/dist/{preset-map-CogjYmSw.mjs → preset-map-DdAexIwz.mjs} +113 -2
- package/dist/{presets-CXDyg51l.mjs → presets-_EaSw29m.mjs} +710 -130
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rntl-matchers.d.ts +11 -15
- package/dist/rntl-support.mjs +28 -13
- package/dist/root-mocks-BNXeosbR.mjs +155 -0
- package/dist/serializer.cjs +7 -5
- package/dist/serializer.d.cts +7 -5
- package/dist/serializer.d.mts +7 -5
- package/dist/serializer.mjs +7 -5
- package/dist/setup.mjs +26 -27
- package/docs/migrating-from-jest.md +9 -232
- package/docs/migrating-from-vitest-react-native.md +4 -4
- package/docs/release-readiness.md +9 -11
- package/docs/versioning.md +38 -9
- package/package.json +59 -33
- package/dist/host-BAAAlSkO.mjs +0 -1028
|
@@ -3,3 +3,4 @@ export declare function serializableAliases(
|
|
|
3
3
|
root: string,
|
|
4
4
|
): { entries: [string, string][]; skipped: string[] };
|
|
5
5
|
export declare function expandAlias(specifier: string, entries: [string, string][]): string;
|
|
6
|
+
export declare const JEST_COMPAT_SHIM_FILES: Readonly<Record<string, string>>;
|
|
@@ -63,3 +63,14 @@ export function expandAlias(specifier, entries) {
|
|
|
63
63
|
if (find.endsWith("/") && !replacement.endsWith("/")) return `${replacement}/${rest}`;
|
|
64
64
|
return replacement + rest;
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* jest-compat's shims for packages that work only inside Jest, the targets of
|
|
69
|
+
* jestCompatAliases(), as files beside the jest-compat setup: each export names only an
|
|
70
|
+
* `import` target, which a CommonJS require() cannot resolve by name. Kept in step with
|
|
71
|
+
* jestCompatAliases() by tests/jest-compat.test.ts.
|
|
72
|
+
*/
|
|
73
|
+
export const JEST_COMPAT_SHIM_FILES = Object.freeze({
|
|
74
|
+
"vitest-native/jest-compat/jest-globals": "./jest-globals.mjs",
|
|
75
|
+
"vitest-native/jest-compat/extend-expect-noop": "./noop.mjs",
|
|
76
|
+
});
|
|
@@ -97,7 +97,7 @@ function withDefault(mod) {
|
|
|
97
97
|
* Jest hands the factory's return to the importer as `module.exports`, and Babel's
|
|
98
98
|
* CommonJS output reads a named import as a property of it (`_m.applicationId`): a
|
|
99
99
|
* name the factory left out is simply `undefined`. Vitest instead wraps the factory
|
|
100
|
-
* result in a proxy (VitestMocker#callFunctionMock
|
|
100
|
+
* result in a proxy (VitestMocker#callFunctionMock in Vitest 5) whose
|
|
101
101
|
* `get` throws `No "x" export is defined on the "m" mock` when `!(prop in target)`.
|
|
102
102
|
* Mocking only what a test needs is ordinary in Jest suites, so a migrated suite
|
|
103
103
|
* failed on imports its tests never touched.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// jest.mock('x', () => ({ Api: jest.fn().mockImplementation(() => ({ fetch })) }))
|
|
12
12
|
// new Api() // → { fetch }
|
|
13
13
|
//
|
|
14
|
-
// Vitest
|
|
14
|
+
// Vitest constructs the implementation itself (`Reflect.construct(impl, args,
|
|
15
15
|
// new.target)` in @vitest/spy), so an arrow implementation throws `… is not a
|
|
16
16
|
// constructor`, and `mockReturnValue`/`mockResolvedValue` throw a dedicated error
|
|
17
17
|
// under `new`. That is a deliberate Vitest design, so `vi.fn` is left exactly as it
|
|
@@ -110,9 +110,27 @@ function withJestSemantics(mock, original) {
|
|
|
110
110
|
if (resting !== original) {
|
|
111
111
|
spyDefaults.add(resting);
|
|
112
112
|
mockImplementation.call(mock, resting);
|
|
113
|
+
// Vitest's resetAllMocks() iterates the set of mocks it marked dirty with for…of, and
|
|
114
|
+
// mockReset() takes the mock out of it. Installing the resting implementation marks it
|
|
115
|
+
// dirty again, which appends it to that set, so the same loop visits it again: every
|
|
116
|
+
// visit reset it and appended it once more, and resetAllMocks() never returned.
|
|
117
|
+
//
|
|
118
|
+
// A mock whose state is exactly what a reset leaves is left alone, so the second
|
|
119
|
+
// visit changes nothing and the loop moves on. The state is read from Vitest itself,
|
|
120
|
+
// not tracked here, so no way of changing the mock can leave it stale: the next
|
|
121
|
+
// implementation it would run (getMockImplementation() returns a queued once-
|
|
122
|
+
// implementation first) is the resting one, it has no calls, and its name is the one
|
|
123
|
+
// the reset left.
|
|
124
|
+
let nameAfterReset;
|
|
125
|
+
const asReset = () =>
|
|
126
|
+
getMockImplementation.call(mock) === resting &&
|
|
127
|
+
mock.mock.calls.length === 0 &&
|
|
128
|
+
mock.getMockName() === nameAfterReset;
|
|
113
129
|
mock.mockReset = () => {
|
|
130
|
+
if (asReset()) return mock;
|
|
114
131
|
mockReset.call(mock);
|
|
115
132
|
mockImplementation.call(mock, resting);
|
|
133
|
+
nameAfterReset = mock.getMockName();
|
|
116
134
|
return mock;
|
|
117
135
|
};
|
|
118
136
|
}
|
|
@@ -167,9 +185,8 @@ function originalOf(object, key, accessType) {
|
|
|
167
185
|
// never fakes them unless asked, because Node and Vitest's runner use them
|
|
168
186
|
// internally ("Do not mock timers internally used by node by default", Vitest's
|
|
169
187
|
// FakeTimers.useFakeTimers). This keeps Vitest's choice.
|
|
170
|
-
// - `doNotFake` becomes an explicit `toFake
|
|
171
|
-
//
|
|
172
|
-
// `toNotFake` at all, so only `toFake` means the same on every supported major.
|
|
188
|
+
// - `doNotFake` becomes an explicit `toFake`: the list of every fakeable API minus the
|
|
189
|
+
// ones named.
|
|
173
190
|
// - `legacyFakeTimers: true` has no Vitest counterpart (Jest's legacy timers are
|
|
174
191
|
// jest.fn mocks). It is approximated with modern timers over the functions legacy
|
|
175
192
|
// timers replace, leaving Date real as they do, and warns once that assertions on
|
|
@@ -310,7 +327,8 @@ export function createJestObject(vi, members = {}) {
|
|
|
310
327
|
["spyOn", spyOn],
|
|
311
328
|
["useFakeTimers", useFakeTimers],
|
|
312
329
|
["useRealTimers", useRealTimers],
|
|
313
|
-
//
|
|
330
|
+
// Members the compat setup supplies (setup.mjs): the module registry's,
|
|
331
|
+
// replaceProperty and restoreAllMocks.
|
|
314
332
|
...Object.entries(members),
|
|
315
333
|
]);
|
|
316
334
|
const jest = new Proxy(vi, {
|