vitest-native 0.15.0 → 0.16.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +177 -31
- package/dist/context.d.mts +6 -0
- package/dist/context.mjs +5 -0
- package/dist/errors.d.mts +5 -0
- package/dist/hang-watch.d.mts +2 -0
- package/dist/hang-watch.mjs +60 -3
- package/dist/{host-TAGjG56H.mjs → host-X6VHF-a4.mjs} +456 -15
- package/dist/{index-BpZ0E2eJ.d.mts → index-X3wuvaqa.d.mts} +25 -13
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +220 -117
- package/dist/jest-compat/jest-object.mjs +62 -17
- package/dist/jest-compat/node-registry.mjs +496 -126
- package/dist/jest-compat/setup.mjs +32 -4
- package/dist/jest-compat.cjs +277 -33
- package/dist/jest-compat.d.cts +1 -1
- package/dist/jest-compat.d.mts +1 -1
- package/dist/jest-compat.mjs +257 -33
- package/dist/native/assets.mjs +41 -10
- package/dist/native/babel-worker.mjs +4 -2
- package/dist/native/boundary.mjs +52 -14
- package/dist/native/bounded-process.mjs +110 -27
- package/dist/native/explain.mjs +101 -5
- package/dist/native/expo-module-mocks.mjs +3 -0
- package/dist/native/gesture-handler-buttons.mjs +148 -0
- package/dist/native/hooks.mjs +8 -2
- package/dist/native/hot-diagnostic.mjs +7 -0
- package/dist/native/library-jest.mjs +16 -8
- package/dist/native/loader.mjs +159 -2
- package/dist/native/metro-profile-compiler.mjs +2 -1
- package/dist/native/metro-profile.mjs +2 -0
- package/dist/native/ownership-ledger.d.mts +2 -0
- package/dist/native/ownership-ledger.mjs +3 -2
- package/dist/native/react-dedupe.d.mts +7 -0
- package/dist/native/react-dedupe.mjs +191 -0
- package/dist/native/registry-compiler.mjs +3 -2
- package/dist/native/registry-process.mjs +90 -12
- package/dist/native/registry.mjs +9 -4
- package/dist/native/reset.mjs +51 -26
- package/dist/native/resolve.mjs +5 -1
- package/dist/native/setup.mjs +15 -7
- package/dist/native/state-manifest.mjs +2 -3
- package/dist/native/transform.mjs +125 -3
- package/dist/native/worker.mjs +3 -12
- package/dist/node-dispatch.mjs +2 -0
- package/dist/preset-react.d.mts +11 -0
- package/dist/preset-react.mjs +121 -0
- package/dist/{presets-DLH7uRGA.mjs → presets-Dw0Sz9O6.mjs} +1352 -567
- package/dist/presets.d.mts +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/setup-files-C6-77IIs.mjs +22 -0
- package/dist/setup.mjs +15 -13
- package/package.json +15 -5
- package/dist/memory-Couw0Esx.mjs +0 -151
- package/dist/native/compile-cache.mjs +0 -57
|
@@ -181,12 +181,26 @@ function originalOf(object, key, accessType) {
|
|
|
181
181
|
// reads from the real clock on every install while Vitest resumes the last fake one.
|
|
182
182
|
// A `now` set in `test.fakeTimers` is therefore overridden, as in Jest only an
|
|
183
183
|
// explicit `now` sets the start.
|
|
184
|
-
// - `
|
|
185
|
-
//
|
|
186
|
-
//
|
|
187
|
-
// FakeTimers.useFakeTimers)
|
|
188
|
-
//
|
|
189
|
-
//
|
|
184
|
+
// - `queueMicrotask` is faked, as Jest fakes it, so a callback queued with it waits for
|
|
185
|
+
// the timers to run (#835): react-native-worklets' Jest mock reports `runOnJS` and
|
|
186
|
+
// `scheduleOnRN` calls through it. Vitest leaves it real unless asked ("Do not mock
|
|
187
|
+
// timers internally used by node by default", FakeTimers.useFakeTimers), so the
|
|
188
|
+
// translation always passes an explicit `toFake`: every fakeable API minus
|
|
189
|
+
// `doNotFake`. Vitest's runner captured its own queueMicrotask before any test ran.
|
|
190
|
+
// `jest.useFakeTimers({ doNotFake: ['queueMicrotask'] })` keeps it real.
|
|
191
|
+
// - `nextTick` stays real. Jest fakes it too, but Vitest refuses to under the forks
|
|
192
|
+
// pool, and Node's streams and Vitest's runner use it internally.
|
|
193
|
+
// - A project whose `test.fakeTimers` names the APIs to fake (`toFake` or `toNotFake`)
|
|
194
|
+
// keeps that choice: with no `doNotFake` the translation passes no `toFake`, so
|
|
195
|
+
// Vitest merges the project's in. A `toFake` given to the call is kept as given.
|
|
196
|
+
// The project's config is the one Vitest resolved for the worker, so a workspace
|
|
197
|
+
// project's inherited `test.fakeTimers` counts too (#892).
|
|
198
|
+
// - A call's `doNotFake` replaces the project's list, as Jest's call config replaces
|
|
199
|
+
// its project's `doNotFake` (jest-runtime 30.2 spreads `this._config.fakeTimers`
|
|
200
|
+
// under the call's). Vitest merges the same way, but @sinonjs/fake-timers refuses
|
|
201
|
+
// `toFake` beside the project's `toNotFake`, so under a project `toNotFake` the
|
|
202
|
+
// translation passes its list as `toNotFake`, the complement. Vitest then adds
|
|
203
|
+
// `queueMicrotask` to that list, so it stays real there.
|
|
190
204
|
// - `legacyFakeTimers: true` has no Vitest counterpart (Jest's legacy timers are
|
|
191
205
|
// jest.fn mocks). It is approximated with modern timers over the functions legacy
|
|
192
206
|
// timers replace, leaving Date real as they do, and warns once that assertions on
|
|
@@ -227,8 +241,8 @@ export const FAKEABLE_TIMER_APIS = [
|
|
|
227
241
|
"Temporal",
|
|
228
242
|
];
|
|
229
243
|
|
|
230
|
-
/**
|
|
231
|
-
const KEPT_REAL = new Set(["nextTick"
|
|
244
|
+
/** Never faked: Vitest refuses `nextTick` under the forks pool, and its runner relies on it. */
|
|
245
|
+
const KEPT_REAL = new Set(["nextTick"]);
|
|
232
246
|
|
|
233
247
|
/**
|
|
234
248
|
* What Jest's legacy timers replace (LegacyFakeTimers.useFakeTimers, @jest/fake-timers
|
|
@@ -253,12 +267,17 @@ const loopLimitOf = (timerLimit) => timerLimit || 100_000;
|
|
|
253
267
|
* Translate a Jest fake-timers config into the one `vi.useFakeTimers` takes. Keys that
|
|
254
268
|
* are not Jest's (a Vitest option passed through `jest.*`) are kept as given.
|
|
255
269
|
*/
|
|
256
|
-
export function toVitestFakeTimersConfig(config, realNow = Date.now) {
|
|
270
|
+
export function toVitestFakeTimersConfig(config, realNow = Date.now, projectFakeTimers) {
|
|
257
271
|
const { advanceTimers, doNotFake, legacyFakeTimers, now, timerLimit, ...rest } = config ?? {};
|
|
258
272
|
const out = { ...rest, loopLimit: loopLimitOf(timerLimit) };
|
|
259
273
|
if (legacyFakeTimers) {
|
|
260
274
|
// Legacy timers take no options of their own: no auto-advance, no clock to set.
|
|
261
|
-
|
|
275
|
+
// A call's own Vitest `toNotFake` stays real, as beside doNotFake below.
|
|
276
|
+
const real = new Set(rest.toNotFake ?? []);
|
|
277
|
+
const { toNotFake: _, ...legacy } = out;
|
|
278
|
+
legacy.shouldAdvanceTime = false;
|
|
279
|
+
legacy.toFake = LEGACY_FAKED.filter((api) => !real.has(api));
|
|
280
|
+
return besideProject(legacy, rest, projectFakeTimers);
|
|
262
281
|
}
|
|
263
282
|
if (advanceTimers !== undefined) {
|
|
264
283
|
out.shouldAdvanceTime = Boolean(advanceTimers);
|
|
@@ -268,13 +287,37 @@ export function toVitestFakeTimersConfig(config, realNow = Date.now) {
|
|
|
268
287
|
// Vitest would start the new clock where the last fake one stopped, so a date one
|
|
269
288
|
// test pinned with setSystemTime leaked into every later jest.useFakeTimers().
|
|
270
289
|
out.now = now ?? realNow();
|
|
271
|
-
|
|
272
|
-
|
|
290
|
+
const chosen = rest.toFake !== undefined || rest.toNotFake !== undefined;
|
|
291
|
+
const projectChose =
|
|
292
|
+
projectFakeTimers?.toFake !== undefined || projectFakeTimers?.toNotFake !== undefined;
|
|
293
|
+
const real = new Set(doNotFake ?? []);
|
|
294
|
+
if (Array.isArray(rest.toFake)) {
|
|
295
|
+
// A call's own Vitest `toFake` is its list, less anything doNotFake names.
|
|
296
|
+
if (doNotFake !== undefined) out.toFake = rest.toFake.filter((api) => !real.has(api));
|
|
297
|
+
} else if (doNotFake !== undefined || (!chosen && !projectChose)) {
|
|
298
|
+
// A call's own Vitest `toNotFake` beside doNotFake stays real too: sinon takes one list.
|
|
299
|
+
for (const api of rest.toNotFake ?? []) real.add(api);
|
|
300
|
+
delete out.toNotFake;
|
|
273
301
|
out.toFake = FAKEABLE_TIMER_APIS.filter((api) => !KEPT_REAL.has(api) && !real.has(api));
|
|
274
302
|
}
|
|
275
|
-
return out;
|
|
303
|
+
return besideProject(out, rest, projectFakeTimers);
|
|
276
304
|
}
|
|
277
305
|
|
|
306
|
+
/**
|
|
307
|
+
* `out` as Vitest can install it over the project's `test.fakeTimers`: under a project
|
|
308
|
+
* `toNotFake`, a `toFake` the translation chose becomes the `toNotFake` it implies, which
|
|
309
|
+
* replaces the project's. A `toFake` the call passed itself is left as given.
|
|
310
|
+
*/
|
|
311
|
+
function besideProject(out, rest, projectFakeTimers) {
|
|
312
|
+
if (out.toFake === undefined || rest.toFake !== undefined) return out;
|
|
313
|
+
if (projectFakeTimers?.toNotFake === undefined) return out;
|
|
314
|
+
const { toFake, ...kept } = out;
|
|
315
|
+
return { ...kept, toNotFake: FAKEABLE_TIMER_APIS.filter((api) => !toFake.includes(api)) };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** The `test.fakeTimers` Vitest resolved for this worker's project: what `vi.useFakeTimers` merges in. */
|
|
319
|
+
const workerFakeTimers = () => globalThis.__vitest_worker__?.config?.fakeTimers;
|
|
320
|
+
|
|
278
321
|
let warnedLegacy = false;
|
|
279
322
|
function warnLegacyOnce() {
|
|
280
323
|
if (warnedLegacy) return;
|
|
@@ -293,7 +336,7 @@ function warnLegacyOnce() {
|
|
|
293
336
|
* on `vi` (requireActual, the timer guards), and anything a suite assigns to
|
|
294
337
|
* `jest.*`, stay one shared object.
|
|
295
338
|
*/
|
|
296
|
-
export function createJestObject(vi, members = {}) {
|
|
339
|
+
export function createJestObject(vi, members = {}, { projectFakeTimers = workerFakeTimers } = {}) {
|
|
297
340
|
function fn(impl) {
|
|
298
341
|
// `vi.fn(existingMock)` returns that mock; it is someone else's, so leave it be.
|
|
299
342
|
if (vi.isMockFunction(impl)) return vi.fn(impl);
|
|
@@ -312,7 +355,9 @@ export function createJestObject(vi, members = {}) {
|
|
|
312
355
|
// `jest.useFakeTimers().setSystemTime(…)` chains on `jest`, not on `vi`.
|
|
313
356
|
function useFakeTimers(config) {
|
|
314
357
|
if (config?.legacyFakeTimers) warnLegacyOnce();
|
|
315
|
-
vi.useFakeTimers(
|
|
358
|
+
vi.useFakeTimers(
|
|
359
|
+
toVitestFakeTimersConfig(config, () => vi.getRealSystemTime(), projectFakeTimers()),
|
|
360
|
+
);
|
|
316
361
|
return jest;
|
|
317
362
|
}
|
|
318
363
|
function useRealTimers() {
|
|
@@ -354,8 +399,8 @@ export function createJestObject(vi, members = {}) {
|
|
|
354
399
|
const CURRENT = Symbol.for("vitest-native.jest-compat.jest");
|
|
355
400
|
|
|
356
401
|
/** Create this file's `jest` and make it the one `currentJestObject` returns. */
|
|
357
|
-
export function installJestObject(vi, members) {
|
|
358
|
-
const jest = createJestObject(vi, members);
|
|
402
|
+
export function installJestObject(vi, members, options) {
|
|
403
|
+
const jest = createJestObject(vi, members, options);
|
|
359
404
|
Object.defineProperty(vi, CURRENT, { value: jest, configurable: true, writable: true });
|
|
360
405
|
return jest;
|
|
361
406
|
}
|