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.
Files changed (89) hide show
  1. package/README.md +11 -10
  2. package/dist/cli.d.mts +9 -1
  3. package/dist/cli.mjs +2609 -361
  4. package/dist/context.d.mts +19 -0
  5. package/dist/context.mjs +47 -1
  6. package/dist/docs-url.d.mts +4 -0
  7. package/dist/docs-url.mjs +9 -0
  8. package/dist/errors.d.mts +21 -1
  9. package/dist/hang-watch-setup.mjs +55 -0
  10. package/dist/hang-watch.d.mts +56 -0
  11. package/dist/hang-watch.mjs +343 -0
  12. package/dist/helpers.cjs +24 -53
  13. package/dist/helpers.mjs +22 -1
  14. package/dist/host-D0r3P_T1.mjs +1985 -0
  15. package/dist/{index-aNBCTfA5.d.mts → index-JOR602XU.d.mts} +105 -2
  16. package/dist/index.d.mts +2 -1
  17. package/dist/index.mjs +723 -149
  18. package/dist/jest-compat/aliases.d.mts +1 -0
  19. package/dist/jest-compat/aliases.mjs +11 -0
  20. package/dist/jest-compat/interop.mjs +1 -1
  21. package/dist/jest-compat/jest-object.mjs +23 -5
  22. package/dist/jest-compat/node-registry.mjs +836 -68
  23. package/dist/jest-compat/setup.mjs +205 -12
  24. package/dist/jest-compat.cjs +383 -47
  25. package/dist/jest-compat.d.cts +19 -2
  26. package/dist/jest-compat.d.mts +19 -2
  27. package/dist/jest-compat.mjs +232 -47
  28. package/dist/matchers.d.cts +0 -1
  29. package/dist/matchers.d.mts +0 -1
  30. package/dist/native/assets.mjs +3 -1
  31. package/dist/native/babel-caller.d.mts +13 -0
  32. package/dist/native/babel-caller.mjs +24 -0
  33. package/dist/native/babel-toolchain.mjs +27 -3
  34. package/dist/native/boundary.mjs +45 -8
  35. package/dist/native/bounded-process.mjs +63 -5
  36. package/dist/native/bridge-client.mjs +133 -0
  37. package/dist/native/bridge-server.mjs +215 -0
  38. package/dist/native/bridge-thread.mjs +79 -0
  39. package/dist/native/bridge.mjs +512 -0
  40. package/dist/native/compile-error.mjs +120 -0
  41. package/dist/native/explain.mjs +3 -2
  42. package/dist/native/expo-module-mocks.mjs +2 -0
  43. package/dist/native/export-condition-recovery.mjs +20 -99
  44. package/dist/native/hooks.mjs +256 -133
  45. package/dist/native/jest-resolvers.mjs +94 -0
  46. package/dist/native/library-jest.mjs +352 -0
  47. package/dist/native/loader.mjs +167 -73
  48. package/dist/native/match.mjs +67 -7
  49. package/dist/native/module-reset.mjs +44 -49
  50. package/dist/native/ownership-ledger.d.mts +87 -0
  51. package/dist/native/ownership-ledger.mjs +524 -0
  52. package/dist/native/ownership.d.mts +20 -0
  53. package/dist/native/ownership.mjs +114 -0
  54. package/dist/native/registry-compiler.mjs +39 -5
  55. package/dist/native/registry-process.mjs +327 -28
  56. package/dist/native/registry.mjs +752 -200
  57. package/dist/native/resident-health.mjs +1 -0
  58. package/dist/native/resolve.d.mts +7 -0
  59. package/dist/native/resolve.mjs +119 -4
  60. package/dist/native/rntl-hooks.mjs +9 -5
  61. package/dist/native/rntl-text-host.mjs +5 -15
  62. package/dist/native/root-spelling.d.mts +6 -0
  63. package/dist/native/root-spelling.mjs +77 -0
  64. package/dist/native/runner.mjs +2 -19
  65. package/dist/native/setup.mjs +119 -38
  66. package/dist/native/shared-resolver.d.mts +141 -0
  67. package/dist/native/shared-resolver.mjs +719 -0
  68. package/dist/native/test-runner.mjs +26 -0
  69. package/dist/native/transform.mjs +18 -22
  70. package/dist/native/worker.mjs +9 -4
  71. package/dist/node-dispatch.mjs +293 -0
  72. package/dist/{preset-map-CogjYmSw.mjs → preset-map-DdAexIwz.mjs} +113 -2
  73. package/dist/{presets-CXDyg51l.mjs → presets-_EaSw29m.mjs} +710 -130
  74. package/dist/presets.d.mts +1 -1
  75. package/dist/presets.mjs +1 -1
  76. package/dist/rntl-matchers.d.ts +11 -15
  77. package/dist/rntl-support.mjs +28 -13
  78. package/dist/root-mocks-BNXeosbR.mjs +155 -0
  79. package/dist/serializer.cjs +7 -5
  80. package/dist/serializer.d.cts +7 -5
  81. package/dist/serializer.d.mts +7 -5
  82. package/dist/serializer.mjs +7 -5
  83. package/dist/setup.mjs +26 -27
  84. package/docs/migrating-from-jest.md +9 -232
  85. package/docs/migrating-from-vitest-react-native.md +4 -4
  86. package/docs/release-readiness.md +9 -11
  87. package/docs/versioning.md +38 -9
  88. package/package.json +59 -33
  89. 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, the same in Vitest 4 and 5) whose
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 4+ constructs the implementation itself (`Reflect.construct(impl, args,
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`. Vitest 5 also accepts `toNotFake`, but
171
- // Vitest 4 always passes its own `toFake` to sinon, whose bundled version has no
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
- // Jest's module-registry members, supplied by the compat setup (setup.mjs).
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, {