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
package/dist/helpers.cjs CHANGED
@@ -1,55 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- // src/errors.mjs
3
- /**
4
- * The error types this package throws.
5
- *
6
- * Plain .mjs on purpose. The shipped native and jest-compat runtimes are copied to dist
7
- * verbatim and import this by relative path, and the test suite loads those same files
8
- * from src — so the module has to resolve identically in both trees. A .ts source would
9
- * only exist in one of them.
10
- *
11
- * WHAT SURVIVES WHERE, measured rather than assumed:
12
- *
13
- * - In the main process, and in a user's own try/catch inside a test, everything is
14
- * intact.
15
- * - Across the worker/reporter boundary Vitest keeps only `name`, `message` and
16
- * `stack`. `code` and every other own property is dropped.
17
- *
18
- * So the message must stay self-sufficient: nothing may move out of it into a field on
19
- * the assumption a reader will see it.
20
- *
21
- * `isVitestNativeError` deliberately checks SHAPE rather than `instanceof`. Bundled
22
- * entries and the verbatim .mjs runtimes can hold separate copies of this module, and a
23
- * prototype check would quietly fail across that seam. Shape does not care.
24
- */
25
- const PREFIX = "[vitest-native]";
26
- /** Guarantees the prefix exactly once, however the caller wrote the message. */
27
- function withPrefix(message) {
28
- return message.startsWith(PREFIX) ? message : `${PREFIX} ${message}`;
29
- }
30
- function buildMessage(message, options) {
31
- const base = withPrefix(message);
32
- return options?.docs ? `${base}\nSee ${options.docs}` : base;
33
- }
34
- /**
35
- * Error options, omitted entirely when there is no cause.
36
- *
37
- * `new Error(msg, { cause: undefined })` installs an own `cause` property set to
38
- * undefined, which a plain `new Error(msg)` does not — enough to make some reporters
39
- * print an empty cause and to make these errors shaped differently from every other
40
- * error in the process. Passing nothing keeps them identical.
41
- */
42
- function errorOptions(options) {
43
- return options && "cause" in options && options.cause !== void 0 ? { cause: options.cause } : void 0;
44
- }
45
- /** A failure originating in vitest-native. */
46
- var VitestNativeError = class extends Error {
47
- constructor(code, message, options) {
48
- super(buildMessage(message, options), errorOptions(options));
49
- this.name = "VitestNativeError";
50
- this.code = code;
51
- }
52
- };
2
+ let src_errors_mjs = require("./errors.mjs");
53
3
  // src/helpers.ts
54
4
  /**
55
5
  * Test helpers for vitest-native.
@@ -59,7 +9,7 @@ var VitestNativeError = class extends Error {
59
9
  */
60
10
  function getMock() {
61
11
  const mock = globalThis.__vitest_native_mock;
62
- if (!mock) throw new VitestNativeError("HELPERS_BEFORE_SETUP", "helpers were called before setup ran. Ensure the vitest-native plugin is configured.");
12
+ if (!mock) throw new src_errors_mjs.VitestNativeError("HELPERS_BEFORE_SETUP", "helpers were called before setup ran. Ensure the vitest-native plugin is configured.");
63
13
  return mock;
64
14
  }
65
15
  function getNativeControl() {
@@ -94,9 +44,28 @@ function setColorScheme(scheme) {
94
44
  }
95
45
  function setInsets(insets) {
96
46
  const safeArea = globalThis.__vitest_native_preset_mocks?.["react-native-safe-area-context"];
97
- if (safeArea?._setInsets) safeArea._setInsets(insets);
47
+ if (safeArea?._setInsets) {
48
+ safeArea._setInsets(insets);
49
+ return;
50
+ }
51
+ const hook = safeArea?.useSafeAreaInsets;
52
+ if (typeof hook?.mockImplementation === "function" && typeof hook.getMockImplementation === "function") {
53
+ const current = hook.getMockImplementation();
54
+ presetMockUndos.push(() => hook.mockImplementation(current));
55
+ hook.mockImplementation((...args) => ({
56
+ ...current ? current(...args) : {
57
+ top: 0,
58
+ right: 0,
59
+ bottom: 0,
60
+ left: 0
61
+ },
62
+ ...insets
63
+ }));
64
+ }
98
65
  }
99
66
  let presetMockOverrides = [];
67
+ /** Undos of what a helper changed on a library's own mock (setInsets), replayed by resetAllMocks(). */
68
+ let presetMockUndos = [];
100
69
  /**
101
70
  * Merge overrides into a preset's module mock (and its `default`, when that is
102
71
  * an object) — e.g. to give expo-constants a real `expoConfig` or add an export
@@ -126,6 +95,8 @@ function extendPresetMock(pkg, overrides) {
126
95
  return true;
127
96
  }
128
97
  function restorePresetMockOverrides() {
98
+ for (let i = presetMockUndos.length - 1; i >= 0; i--) presetMockUndos[i]();
99
+ presetMockUndos = [];
129
100
  for (let i = presetMockOverrides.length - 1; i >= 0; i--) {
130
101
  const { target, key, had, previous } = presetMockOverrides[i];
131
102
  if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
package/dist/helpers.mjs CHANGED
@@ -43,9 +43,28 @@ function setColorScheme(scheme) {
43
43
  }
44
44
  function setInsets(insets) {
45
45
  const safeArea = globalThis.__vitest_native_preset_mocks?.["react-native-safe-area-context"];
46
- if (safeArea?._setInsets) safeArea._setInsets(insets);
46
+ if (safeArea?._setInsets) {
47
+ safeArea._setInsets(insets);
48
+ return;
49
+ }
50
+ const hook = safeArea?.useSafeAreaInsets;
51
+ if (typeof hook?.mockImplementation === "function" && typeof hook.getMockImplementation === "function") {
52
+ const current = hook.getMockImplementation();
53
+ presetMockUndos.push(() => hook.mockImplementation(current));
54
+ hook.mockImplementation((...args) => ({
55
+ ...current ? current(...args) : {
56
+ top: 0,
57
+ right: 0,
58
+ bottom: 0,
59
+ left: 0
60
+ },
61
+ ...insets
62
+ }));
63
+ }
47
64
  }
48
65
  let presetMockOverrides = [];
66
+ /** Undos of what a helper changed on a library's own mock (setInsets), replayed by resetAllMocks(). */
67
+ let presetMockUndos = [];
49
68
  /**
50
69
  * Merge overrides into a preset's module mock (and its `default`, when that is
51
70
  * an object) — e.g. to give expo-constants a real `expoConfig` or add an export
@@ -75,6 +94,8 @@ function extendPresetMock(pkg, overrides) {
75
94
  return true;
76
95
  }
77
96
  function restorePresetMockOverrides() {
97
+ for (let i = presetMockUndos.length - 1; i >= 0; i--) presetMockUndos[i]();
98
+ presetMockUndos = [];
78
99
  for (let i = presetMockOverrides.length - 1; i >= 0; i--) {
79
100
  const { target, key, had, previous } = presetMockOverrides[i];
80
101
  if (key === "__proto__" || key === "constructor" || key === "prototype") continue;