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.
Files changed (77) hide show
  1. package/CHANGELOG.md +339 -0
  2. package/README.md +138 -48
  3. package/dist/cli.cjs +70 -5
  4. package/dist/cli.d.cts +2 -3
  5. package/dist/cli.d.mts +2 -3
  6. package/dist/cli.mjs +70 -5
  7. package/dist/{ecosystem-Duw40-mO.mjs → ecosystem-DFbU_MPe.mjs} +389 -18
  8. package/dist/{ecosystem-CEIF_-jq.cjs → ecosystem-DI1AhK_k.cjs} +408 -25
  9. package/dist/errors.d.mts +12 -0
  10. package/dist/helpers.cjs +6 -3
  11. package/dist/helpers.d.cts +8 -9
  12. package/dist/helpers.d.mts +8 -9
  13. package/dist/helpers.mjs +6 -3
  14. package/dist/{index-CPGq6p95.d.cts → index-BxzW2D7K.d.cts} +33 -9
  15. package/dist/{index-CmETArCM.d.mts → index-CEbwa4QU.d.mts} +33 -9
  16. package/dist/index.d.mts +4 -4
  17. package/dist/index.mjs +537 -118
  18. package/dist/jest-compat/aliases.d.mts +5 -0
  19. package/dist/jest-compat/aliases.mjs +65 -0
  20. package/dist/jest-compat/caller.mjs +53 -0
  21. package/dist/jest-compat/setup.mjs +72 -36
  22. package/dist/jest-compat.cjs +1 -3
  23. package/dist/jest-compat.d.cts +4 -5
  24. package/dist/jest-compat.d.mts +4 -5
  25. package/dist/jest-compat.mjs +1 -1
  26. package/dist/matchers.d.cts +9 -9
  27. package/dist/matchers.d.mts +9 -9
  28. package/dist/memory-6EPHrJA1.cjs +144 -0
  29. package/dist/memory-FYbP0_gg.mjs +126 -0
  30. package/dist/native/boundary.mjs +13 -2
  31. package/dist/native/bounded-process.mjs +165 -0
  32. package/dist/native/export-condition-recovery-preload.mjs +5 -0
  33. package/dist/native/export-condition-recovery.mjs +195 -0
  34. package/dist/native/globals.mjs +133 -5
  35. package/dist/native/hooks.mjs +131 -71
  36. package/dist/native/loader.mjs +41 -28
  37. package/dist/native/match.d.mts +3 -0
  38. package/dist/native/match.mjs +38 -2
  39. package/dist/native/metro-profile-compiler.mjs +234 -0
  40. package/dist/native/metro-profile.mjs +115 -0
  41. package/dist/native/module-reset.mjs +111 -6
  42. package/dist/native/ownership.d.mts +105 -0
  43. package/dist/native/ownership.mjs +474 -0
  44. package/dist/native/registry-compiler.mjs +43 -0
  45. package/dist/native/registry-process.mjs +124 -0
  46. package/dist/native/registry.mjs +139 -32
  47. package/dist/native/reset.mjs +305 -135
  48. package/dist/native/resolve.d.mts +20 -3
  49. package/dist/native/resolve.mjs +32 -12
  50. package/dist/native/rntl-hooks.mjs +76 -0
  51. package/dist/native/setup.mjs +81 -32
  52. package/dist/native/state-manifest.d.mts +22 -0
  53. package/dist/native/state-manifest.mjs +136 -0
  54. package/dist/native/transform.mjs +29 -8
  55. package/dist/native/worker.mjs +52 -4
  56. package/dist/pool-B4yesGhI.cjs +121 -0
  57. package/dist/pool-DjpOjOf3.mjs +119 -0
  58. package/dist/{presets-CoNf4ByH.cjs → presets-BYHmi7-W.cjs} +117 -18
  59. package/dist/{presets-DGProTaA.mjs → presets-DC-eM5IA.mjs} +117 -18
  60. package/dist/presets.d.mts +1 -1
  61. package/dist/presets.mjs +1 -1
  62. package/dist/rntl-matchers.d.ts +58 -12
  63. package/dist/serializer.cjs +4 -2
  64. package/dist/serializer.d.cts +3 -4
  65. package/dist/serializer.d.mts +3 -4
  66. package/dist/serializer.mjs +4 -2
  67. package/dist/setup.mjs +61 -50
  68. package/dist/worker-vitest-BGPo0ek6.mjs +49 -0
  69. package/dist/worker-vitest-BfiQB8ND.cjs +62 -0
  70. package/docs/hot-default-design.md +175 -88
  71. package/docs/migrating-from-jest.md +12 -5
  72. package/docs/migrating-from-vitest-react-native.md +4 -4
  73. package/docs/release-readiness.md +39 -13
  74. package/docs/versioning.md +19 -18
  75. package/package.json +42 -31
  76. package/dist/pool-BU-1ecIF.cjs +0 -122
  77. package/dist/pool-Bcxn9a3I.mjs +0 -118
@@ -0,0 +1,5 @@
1
+ export declare function serializableAliases(
2
+ alias: unknown,
3
+ root: string,
4
+ ): { entries: [string, string][]; skipped: string[] };
5
+ export declare function expandAlias(specifier: string, entries: [string, string][]): string;
@@ -0,0 +1,65 @@
1
+ // `resolve.alias` for `jest.requireActual` / `jest.requireMock`.
2
+ //
3
+ // Vite applies the project's aliases to imports, but `requireActual` resolves through
4
+ // Node, which knows nothing of them — so `jest.requireActual('@/services/api')` threw
5
+ // "Cannot find module" in a suite whose imports of the same path worked. The plugin
6
+ // knows the aliases at config time and hands the serializable ones to the compat setup;
7
+ // these helpers are the two halves of that hand-off.
8
+ import path from "node:path";
9
+
10
+ /**
11
+ * The string-to-string entries of a Vite `resolve.alias`, in either of its shapes, with
12
+ * relative replacements made absolute against `root`. Regex `find`s and custom
13
+ * resolvers cannot cross into the test worker, so they are listed as `skipped` for the
14
+ * error that explains a miss.
15
+ *
16
+ * @param {unknown} alias `resolve.alias`: an object, or an array of `{ find, replacement }`
17
+ * @param {string} root project root, for relative replacements
18
+ * @returns {{ entries: [string, string][], skipped: string[] }}
19
+ */
20
+ export function serializableAliases(alias, root) {
21
+ const entries = [];
22
+ const skipped = [];
23
+ const list = Array.isArray(alias)
24
+ ? alias
25
+ : alias && typeof alias === "object"
26
+ ? Object.entries(alias).map(([find, replacement]) => ({ find, replacement }))
27
+ : [];
28
+ for (const item of list) {
29
+ const find = item?.find;
30
+ const replacement = item?.replacement;
31
+ if (typeof find !== "string" || typeof replacement !== "string" || item.customResolver) {
32
+ skipped.push(String(find));
33
+ continue;
34
+ }
35
+ entries.push([
36
+ find,
37
+ replacement.startsWith(".") ? path.resolve(root, replacement) : replacement,
38
+ ]);
39
+ }
40
+ return { entries, skipped };
41
+ }
42
+
43
+ /**
44
+ * Apply the longest matching alias to `specifier`, as Vite does for string `find`s: a
45
+ * match is the whole specifier or a prefix followed by `/`, so an `@` alias does not
46
+ * capture `@scope/pkg`. A `find` that itself ends in `/` matches as a plain prefix.
47
+ * Returns the specifier unchanged when nothing matches.
48
+ *
49
+ * @param {string} specifier
50
+ * @param {[string, string][]} entries
51
+ */
52
+ export function expandAlias(specifier, entries) {
53
+ let best = null;
54
+ for (const [find, replacement] of entries) {
55
+ const matches = find.endsWith("/")
56
+ ? specifier.startsWith(find)
57
+ : specifier === find || specifier.startsWith(`${find}/`);
58
+ if (matches && (best === null || find.length > best[0].length)) best = [find, replacement];
59
+ }
60
+ if (!best) return specifier;
61
+ const [find, replacement] = best;
62
+ const rest = specifier.slice(find.length);
63
+ if (find.endsWith("/") && !replacement.endsWith("/")) return `${replacement}/${rest}`;
64
+ return replacement + rest;
65
+ }
@@ -0,0 +1,53 @@
1
+ // Which user file called into the jest-compat shim.
2
+ //
3
+ // Jest resolves a relative `requireActual('../x')` — and `setMock`/`dontMock` — against
4
+ // the CALLING module. These are plain runtime calls on the `jest` global, not rewritten
5
+ // at transform time, so there is no import.meta to consult: the stack is the only thing
6
+ // that knows the caller.
7
+ import path from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+
10
+ const SHIM_DIR = path.dirname(fileURLToPath(import.meta.url));
11
+
12
+ /**
13
+ * Whether `file` sits directly in `dir`. Separators and, on Windows, letter case are
14
+ * normalised first: Vite's module runner reports frames as `D:/a/b/setup.mjs`, while a
15
+ * path from `fileURLToPath` is `D:\a\b`, and a plain comparison treated the shim's own
16
+ * frames as the caller there.
17
+ *
18
+ * @param {string} file
19
+ * @param {string} dir
20
+ * @param {typeof path} [pathApi] injectable for tests of the other platform's rules
21
+ */
22
+ export function inDirectory(file, dir, pathApi = path) {
23
+ const normalise = (p) => {
24
+ const resolved = pathApi.resolve(p);
25
+ return pathApi.sep === "\\" ? resolved.toLowerCase() : resolved;
26
+ };
27
+ return normalise(pathApi.dirname(file)) === normalise(dir);
28
+ }
29
+
30
+ /**
31
+ * The file that called into the shim, skipping the shim's own frames (matched by
32
+ * directory: a path substring missed Windows paths and skipped any user file under a
33
+ * `jest-compat/` directory). Null when the stack does not say.
34
+ */
35
+ export function callerFile() {
36
+ const original = Error.prepareStackTrace;
37
+ try {
38
+ Error.prepareStackTrace = (_, frames) => frames;
39
+ const frames = new Error().stack;
40
+ for (const frame of frames) {
41
+ const file = typeof frame.getFileName === "function" ? frame.getFileName() : null;
42
+ if (!file || file.startsWith("node:")) continue;
43
+ const filePath = file.startsWith("file://") ? fileURLToPath(file) : file;
44
+ if (inDirectory(filePath, SHIM_DIR)) continue;
45
+ return filePath;
46
+ }
47
+ } catch {
48
+ // The caller is unknown; callers fall back to the project root.
49
+ } finally {
50
+ Error.prepareStackTrace = original;
51
+ }
52
+ return null;
53
+ }
@@ -13,9 +13,11 @@
13
13
  // `jest.useFakeTimers` work at runtime via the `jest` global installed here.
14
14
  import { vi } from "vitest";
15
15
  import { createRequire } from "node:module";
16
- import { fileURLToPath } from "node:url";
17
16
  import path from "node:path";
18
17
  import { jestMockInterop } from "./interop.mjs";
18
+ import { expandAlias } from "./aliases.mjs";
19
+ import { callerFile } from "./caller.mjs";
20
+ import { resolvePlatformFile } from "../native/resolve.mjs";
19
21
  import { VitestNativeError } from "../errors.mjs";
20
22
 
21
23
  // Resolve modules from the consumer project root, not this file's location, so
@@ -45,35 +47,31 @@ function writableModuleFacade(mod) {
45
47
  });
46
48
  }
47
49
 
48
- /**
49
- * The file that called into here, taken from the stack.
50
- *
51
- * Jest resolves a relative `requireActual('../x')` against the CALLING module. This
52
- * shim had a single require anchored at the project root, so bare specifiers worked
53
- * and relative ones escaped the source tree: `jest.requireActual('../thing')` threw
54
- * MODULE_NOT_FOUND with a requireStack pointing at <projectRoot>/package.json, which
55
- * is a confusing place to be sent when the file sits next to the test.
56
- *
57
- * The stack is the only thing that knows the caller. These are plain runtime calls
58
- * on the `jest` global, not rewritten at transform time, so there is no import.meta
59
- * to consult.
60
- */
61
- function callerFile() {
62
- const original = Error.prepareStackTrace;
50
+ // The project's string-to-string `resolve.alias` entries, from the plugin. Vite applies
51
+ // them to imports, but `requireActual` resolves through Node, so without this
52
+ // `jest.requireActual('@/services/api')` could not find a module the suite imports.
53
+ function envList(name) {
63
54
  try {
64
- Error.prepareStackTrace = (_, frames) => frames;
65
- const frames = new Error().stack;
66
- for (const frame of frames) {
67
- const file = typeof frame.getFileName === "function" ? frame.getFileName() : null;
68
- if (!file || file.startsWith("node:") || file.includes("/jest-compat/")) continue;
69
- return file.startsWith("file://") ? fileURLToPath(file) : file;
70
- }
55
+ const value = JSON.parse(process.env[name] || "[]");
56
+ return Array.isArray(value) ? value : [];
71
57
  } catch {
72
- // Fall through to the project-root require below.
73
- } finally {
74
- Error.prepareStackTrace = original;
58
+ return [];
75
59
  }
76
- return null;
60
+ }
61
+ const aliases = envList("VITEST_NATIVE_REQUIRE_ALIASES");
62
+ const skippedAliases = envList("VITEST_NATIVE_REQUIRE_ALIASES_SKIPPED");
63
+ const platform = process.env.VITEST_NATIVE_PLATFORM === "android" ? "android" : "ios";
64
+
65
+ /**
66
+ * An alias usually lands on an extensionless app path (`@/Button`), which Node alone
67
+ * would not find as `Button.ios.tsx`: resolve it with the same platform-extension order
68
+ * the engine uses for imports, then let Node (and the .ts/.tsx handlers) load it.
69
+ */
70
+ function resolveAliased(target) {
71
+ if (path.isAbsolute(target) && !path.extname(target)) {
72
+ return resolvePlatformFile(target, platform) ?? target;
73
+ }
74
+ return target;
77
75
  }
78
76
 
79
77
  /** Resolve as Jest does: relative against the caller, bare from the project root. */
@@ -84,7 +82,25 @@ function requireFrom(specifier) {
84
82
  // could resolve some other file that happens to sit at the same relative path.
85
83
  if (caller) return createRequire(caller)(specifier);
86
84
  }
87
- return require(specifier);
85
+ if (typeof specifier === "string" && aliases.length > 0) {
86
+ const expanded = expandAlias(specifier, aliases);
87
+ if (expanded !== specifier) return require(resolveAliased(expanded));
88
+ }
89
+ try {
90
+ return require(specifier);
91
+ } catch (error) {
92
+ if (error?.code === "MODULE_NOT_FOUND" && skippedAliases.length > 0) {
93
+ throw new VitestNativeError(
94
+ "REQUIRE_ACTUAL_ALIAS_UNSUPPORTED",
95
+ `jest.requireActual('${specifier}') could not be resolved. The project defines ` +
96
+ `resolve.alias entries that cannot be applied to requireActual — only ` +
97
+ `string-to-string entries can be (skipped: ${skippedAliases.join(", ")}). ` +
98
+ `Use a string \`find\` for this alias, or a relative path.`,
99
+ { cause: error },
100
+ );
101
+ }
102
+ throw error;
103
+ }
88
104
  }
89
105
 
90
106
  if (typeof vi.requireActual !== "function")
@@ -116,20 +132,40 @@ if (typeof vi.setTimeout !== "function") {
116
132
  // extends `vi` above) to match Jest's leniency — done on `vi` rather than a wrapper
117
133
  // so `globalThis.jest`, the `@jest/globals` shim (which exports `vi` as `jest`), and
118
134
  // direct `vi` usage stay the same object.
119
- const advanceTimersByTime = vi.advanceTimersByTime.bind(vi);
120
- const advanceTimersByTimeAsync = vi.advanceTimersByTimeAsync.bind(vi);
121
- vi.advanceTimersByTime = (...args) =>
122
- vi.isFakeTimers() ? advanceTimersByTime(...args) : undefined;
123
- vi.advanceTimersByTimeAsync = async (...args) =>
124
- vi.isFakeTimers() ? advanceTimersByTimeAsync(...args) : undefined;
135
+ //
136
+ // This file evaluates once per test file, and under the hot runtime `vi` survives
137
+ // between files, so the guard is installed once: re-wrapping per file would grow a
138
+ // chain of wrappers for as long as the worker lives.
139
+ const LENIENT_ADVANCE = Symbol.for("vitest-native.jest-compat.lenient-advance");
140
+ if (!vi.advanceTimersByTime[LENIENT_ADVANCE]) {
141
+ const advanceTimersByTime = vi.advanceTimersByTime.bind(vi);
142
+ const advanceTimersByTimeAsync = vi.advanceTimersByTimeAsync.bind(vi);
143
+ vi.advanceTimersByTime = (...args) =>
144
+ vi.isFakeTimers() ? advanceTimersByTime(...args) : undefined;
145
+ vi.advanceTimersByTimeAsync = async (...args) =>
146
+ vi.isFakeTimers() ? advanceTimersByTimeAsync(...args) : undefined;
147
+ vi.advanceTimersByTime[LENIENT_ADVANCE] = true;
148
+ }
125
149
 
126
150
  // Jest APIs that DO have a Vitest equivalent, under a different name. Each of these
127
151
  // was missing, so a suite calling it hit `jest.X is not a function` — the bare
128
152
  // TypeError the signposting below exists to avoid — even though the behaviour was
129
153
  // available all along. `dontMock` is the sibling of the already-signposted
130
154
  // `deepUnmock`, which is what marks these as omissions rather than decisions.
131
- if (typeof vi.dontMock !== "function") vi.dontMock = (m) => vi.doUnmock(m);
132
- if (typeof vi.setMock !== "function") vi.setMock = (m, exports) => vi.doMock(m, () => exports);
155
+ //
156
+ // `vi.doMock`/`vi.doUnmock` resolve a relative path against THEIR caller, which for
157
+ // these aliases is this file, so `jest.setMock('./x', …)` registered a mock for a
158
+ // module next to the shim and the test kept its previous mock. Anchor relative paths
159
+ // at the calling test file first, as Jest resolves them.
160
+ const anchoredAtCaller = (specifier) => {
161
+ if (typeof specifier !== "string" || !specifier.startsWith(".")) return specifier;
162
+ const caller = callerFile();
163
+ return caller ? path.resolve(path.dirname(caller), specifier) : specifier;
164
+ };
165
+ if (typeof vi.dontMock !== "function") vi.dontMock = (m) => vi.doUnmock(anchoredAtCaller(m));
166
+ if (typeof vi.setMock !== "function") {
167
+ vi.setMock = (m, exports) => vi.doMock(anchoredAtCaller(m), () => exports);
168
+ }
133
169
  // `Date.now()` alone is right for both clocks: Vitest's fake timers replace Date, so
134
170
  // this returns the faked time when they are active and the real time otherwise —
135
171
  // which is what jest.now() reports. An earlier version consulted
@@ -1,7 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
3
2
  let magic_string = require("magic-string");
4
- magic_string = require_rolldown_runtime.__toESM(magic_string, 1);
5
3
  //#region src/jest-compat/transform.ts
6
4
  const HOISTABLE = /* @__PURE__ */ new Set([
7
5
  "mock",
@@ -57,7 +55,7 @@ function jestMockTransform() {
57
55
  } catch {
58
56
  return null;
59
57
  }
60
- const s = new magic_string.default(code);
58
+ const s = new magic_string.MagicString(code);
61
59
  let changed = false;
62
60
  walk(ast, (node) => {
63
61
  if (node.type !== "CallExpression") return;
@@ -19,11 +19,11 @@ import { Plugin } from "vite";
19
19
  *
20
20
  * Opt-in: add after `reactNative()`; pair with `jestCompatSetup` + `globals: true`.
21
21
  */
22
- declare function jestMockTransform(): Plugin;
22
+ export declare function jestMockTransform(): Plugin;
23
23
  //#endregion
24
24
  //#region src/jest-compat/index.d.ts
25
25
  /** Setup-file specifier: gives the suite a `jest` global backed by Vitest's `vi`. */
26
- declare const jestCompatSetup = "vitest-native/jest-compat/setup";
26
+ export declare const jestCompatSetup = "vitest-native/jest-compat/setup";
27
27
  /**
28
28
  * `resolve.alias` entries that redirect Jest-only modules to Vitest-backed shims:
29
29
  * - `@jest/globals` → a shim re-exporting Vitest globals (unblocks RNTL < 12)
@@ -32,6 +32,5 @@ declare const jestCompatSetup = "vitest-native/jest-compat/setup";
32
32
  *
33
33
  * Spread into your config's `resolve.alias`.
34
34
  */
35
- declare function jestCompatAliases(): Record<string, string>;
36
- //#endregion
37
- export { jestCompatAliases, jestCompatSetup, jestMockTransform };
35
+ export declare function jestCompatAliases(): Record<string, string>;
36
+ //#endregion
@@ -19,11 +19,11 @@ import { Plugin } from "vite";
19
19
  *
20
20
  * Opt-in: add after `reactNative()`; pair with `jestCompatSetup` + `globals: true`.
21
21
  */
22
- declare function jestMockTransform(): Plugin;
22
+ export declare function jestMockTransform(): Plugin;
23
23
  //#endregion
24
24
  //#region src/jest-compat/index.d.ts
25
25
  /** Setup-file specifier: gives the suite a `jest` global backed by Vitest's `vi`. */
26
- declare const jestCompatSetup = "vitest-native/jest-compat/setup";
26
+ export declare const jestCompatSetup = "vitest-native/jest-compat/setup";
27
27
  /**
28
28
  * `resolve.alias` entries that redirect Jest-only modules to Vitest-backed shims:
29
29
  * - `@jest/globals` → a shim re-exporting Vitest globals (unblocks RNTL < 12)
@@ -32,6 +32,5 @@ declare const jestCompatSetup = "vitest-native/jest-compat/setup";
32
32
  *
33
33
  * Spread into your config's `resolve.alias`.
34
34
  */
35
- declare function jestCompatAliases(): Record<string, string>;
36
- //#endregion
37
- export { jestCompatAliases, jestCompatSetup, jestMockTransform };
35
+ export declare function jestCompatAliases(): Record<string, string>;
36
+ //#endregion
@@ -1,4 +1,4 @@
1
- import MagicString from "magic-string";
1
+ import { MagicString } from "magic-string";
2
2
  //#region src/jest-compat/transform.ts
3
3
  const HOISTABLE = /* @__PURE__ */ new Set([
4
4
  "mock",
@@ -1,3 +1,4 @@
1
+ /// <reference types="vitest" />
1
2
  //#region src/matchers/animated.d.ts
2
3
  /**
3
4
  * Reanimated-compatible matchers: `toHaveAnimatedStyle` and `toHaveAnimatedProps`.
@@ -26,26 +27,25 @@ interface MatcherResult {
26
27
  pass: boolean;
27
28
  message: () => string;
28
29
  }
29
- interface AnimatedStyleConfig {
30
+ export interface AnimatedStyleConfig {
30
31
  /** When true, every key of the current style must match `expectedStyle` exactly. */
31
32
  shouldMatchAllProps?: boolean;
32
33
  }
33
- declare function toHaveAnimatedStyle(this: MatcherContext, received: unknown, expectedStyle: Record<string, unknown>, config?: AnimatedStyleConfig): MatcherResult;
34
- declare function toHaveAnimatedProps(this: MatcherContext, received: unknown, expectedProps: Record<string, unknown>): MatcherResult;
34
+ export declare function toHaveAnimatedStyle(this: MatcherContext, received: unknown, expectedStyle: Record<string, unknown>, config?: AnimatedStyleConfig): MatcherResult;
35
+ export declare function toHaveAnimatedProps(this: MatcherContext, received: unknown, expectedProps: Record<string, unknown>): MatcherResult;
35
36
  /** All reanimated-compatible matchers, keyed by name for `expect.extend`. */
36
- declare const animatedMatchers: {
37
+ export declare const animatedMatchers: {
37
38
  toHaveAnimatedStyle: typeof toHaveAnimatedStyle;
38
39
  toHaveAnimatedProps: typeof toHaveAnimatedProps;
39
40
  };
40
41
  declare module "vitest" {
41
- interface Assertion<T = any> {
42
- toHaveAnimatedStyle(style: Record<string, unknown>, config?: AnimatedStyleConfig): T;
43
- toHaveAnimatedProps(props: Record<string, unknown>): T;
42
+ interface Assertion<R extends void | Promise<void> = void, T = unknown> {
43
+ toHaveAnimatedStyle(style: Record<string, unknown>, config?: AnimatedStyleConfig): R;
44
+ toHaveAnimatedProps(props: Record<string, unknown>): R;
44
45
  }
45
46
  interface AsymmetricMatchersContaining {
46
47
  toHaveAnimatedStyle(style: Record<string, unknown>, config?: AnimatedStyleConfig): unknown;
47
48
  toHaveAnimatedProps(props: Record<string, unknown>): unknown;
48
49
  }
49
50
  }
50
- //#endregion
51
- export { AnimatedStyleConfig, animatedMatchers, toHaveAnimatedProps, toHaveAnimatedStyle };
51
+ //#endregion
@@ -1,3 +1,4 @@
1
+ /// <reference types="vitest" />
1
2
  //#region src/matchers/animated.d.ts
2
3
  /**
3
4
  * Reanimated-compatible matchers: `toHaveAnimatedStyle` and `toHaveAnimatedProps`.
@@ -26,26 +27,25 @@ interface MatcherResult {
26
27
  pass: boolean;
27
28
  message: () => string;
28
29
  }
29
- interface AnimatedStyleConfig {
30
+ export interface AnimatedStyleConfig {
30
31
  /** When true, every key of the current style must match `expectedStyle` exactly. */
31
32
  shouldMatchAllProps?: boolean;
32
33
  }
33
- declare function toHaveAnimatedStyle(this: MatcherContext, received: unknown, expectedStyle: Record<string, unknown>, config?: AnimatedStyleConfig): MatcherResult;
34
- declare function toHaveAnimatedProps(this: MatcherContext, received: unknown, expectedProps: Record<string, unknown>): MatcherResult;
34
+ export declare function toHaveAnimatedStyle(this: MatcherContext, received: unknown, expectedStyle: Record<string, unknown>, config?: AnimatedStyleConfig): MatcherResult;
35
+ export declare function toHaveAnimatedProps(this: MatcherContext, received: unknown, expectedProps: Record<string, unknown>): MatcherResult;
35
36
  /** All reanimated-compatible matchers, keyed by name for `expect.extend`. */
36
- declare const animatedMatchers: {
37
+ export declare const animatedMatchers: {
37
38
  toHaveAnimatedStyle: typeof toHaveAnimatedStyle;
38
39
  toHaveAnimatedProps: typeof toHaveAnimatedProps;
39
40
  };
40
41
  declare module "vitest" {
41
- interface Assertion<T = any> {
42
- toHaveAnimatedStyle(style: Record<string, unknown>, config?: AnimatedStyleConfig): T;
43
- toHaveAnimatedProps(props: Record<string, unknown>): T;
42
+ interface Assertion<R extends void | Promise<void> = void, T = unknown> {
43
+ toHaveAnimatedStyle(style: Record<string, unknown>, config?: AnimatedStyleConfig): R;
44
+ toHaveAnimatedProps(props: Record<string, unknown>): R;
44
45
  }
45
46
  interface AsymmetricMatchersContaining {
46
47
  toHaveAnimatedStyle(style: Record<string, unknown>, config?: AnimatedStyleConfig): unknown;
47
48
  toHaveAnimatedProps(props: Record<string, unknown>): unknown;
48
49
  }
49
50
  }
50
- //#endregion
51
- export { AnimatedStyleConfig, animatedMatchers, toHaveAnimatedProps, toHaveAnimatedStyle };
51
+ //#endregion
@@ -0,0 +1,144 @@
1
+ const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
+ let node_os = require("node:os");
3
+ node_os = require_rolldown_runtime.__toESM(node_os, 1);
4
+ //#region src/native/memory.mjs
5
+ var memory_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
6
+ createHotMemoryPlan: () => createHotMemoryPlan,
7
+ defaultRequestedWorkers: () => defaultRequestedWorkers,
8
+ effectiveMemoryLimit: () => effectiveMemoryLimit,
9
+ formatBytes: () => formatBytes,
10
+ formatHotMemoryPlan: () => formatHotMemoryPlan,
11
+ resolveRequestedWorkers: () => resolveRequestedWorkers
12
+ });
13
+ const MIB = 1048576;
14
+ const MIN_WORKER_HEAP = 96 * MIB;
15
+ const MAX_WORKER_HEAP = 512 * MIB;
16
+ const MAIN_PROCESS_RESERVE = 256 * MIB;
17
+ const REPLACEMENT_OVERLAP_RESERVE = 192 * MIB;
18
+ const WORKER_RSS_ADMISSION_COST = 256 * MIB;
19
+ const MAX_AUTO_WORKERS = 4;
20
+ function finitePositive(value) {
21
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
22
+ }
23
+ function effectiveMemoryLimit({ totalMemory, constrainedMemory }) {
24
+ const total = finitePositive(totalMemory);
25
+ const constrained = finitePositive(constrainedMemory);
26
+ if (total === null && constrained === null) return {
27
+ bytes: null,
28
+ source: "unknown"
29
+ };
30
+ if (total === null) return {
31
+ bytes: constrained,
32
+ source: "constrained"
33
+ };
34
+ if (constrained === null || total <= constrained) return {
35
+ bytes: total,
36
+ source: "host"
37
+ };
38
+ return {
39
+ bytes: constrained,
40
+ source: "constrained"
41
+ };
42
+ }
43
+ function defaultRequestedWorkers(parallelism = node_os.default.availableParallelism?.() ?? node_os.default.cpus().length) {
44
+ return Math.max(1, Math.floor(parallelism) - 1);
45
+ }
46
+ /** Resolve Vitest's number/percentage worker option without importing Vitest internals. */
47
+ function resolveRequestedWorkers(value, { parallelism, fileParallelism = true } = {}) {
48
+ if (fileParallelism === false) return 1;
49
+ const cpus = Math.max(1, Math.floor(parallelism ?? node_os.default.availableParallelism?.() ?? node_os.default.cpus().length));
50
+ if (typeof value === "number" && Number.isFinite(value)) return Math.max(1, Math.floor(value));
51
+ if (typeof value === "string") {
52
+ const trimmed = value.trim();
53
+ if (/^\d+(?:\.\d+)?%$/.test(trimmed)) return Math.max(1, Math.floor(cpus * Number.parseFloat(trimmed) / 100));
54
+ if (/^\d+$/.test(trimmed)) return Math.max(1, Number.parseInt(trimmed, 10));
55
+ }
56
+ return Math.max(1, cpus - 1);
57
+ }
58
+ /**
59
+ * Compute the automatic hot-runtime envelope.
60
+ *
61
+ * The reserves and four-worker cap were earned by the packed 406-file RNTL
62
+ * experiment. They are conservative defaults, not portable benchmark claims.
63
+ */
64
+ function createHotMemoryPlan({ totalMemory = node_os.default.totalmem(), constrainedMemory = process.constrainedMemory?.() ?? 0, requestedWorkers = defaultRequestedWorkers() } = {}) {
65
+ const effective = effectiveMemoryLimit({
66
+ totalMemory,
67
+ constrainedMemory
68
+ });
69
+ const requested = Math.max(1, Math.floor(requestedWorkers));
70
+ if (effective.bytes === null) return Object.freeze({
71
+ version: 1,
72
+ source: effective.source,
73
+ effectiveLimit: null,
74
+ softRssLimit: null,
75
+ hardRssLimit: null,
76
+ requestedWorkers: requested,
77
+ admittedWorkers: Math.min(MAX_AUTO_WORKERS, requested),
78
+ maxWorkers: Math.min(MAX_AUTO_WORKERS, requested),
79
+ workerHeapLimit: 256 * MIB,
80
+ mainProcessReserve: MAIN_PROCESS_RESERVE,
81
+ replacementOverlapReserve: REPLACEMENT_OVERLAP_RESERVE
82
+ });
83
+ const softRssLimit = Math.floor(effective.bytes * .8);
84
+ const hardRssLimit = Math.floor(effective.bytes * .9);
85
+ const workerEnvelope = Math.max(0, softRssLimit - MAIN_PROCESS_RESERVE - REPLACEMENT_OVERLAP_RESERVE);
86
+ const admittedWorkers = Math.max(1, Math.min(MAX_AUTO_WORKERS, Math.floor(workerEnvelope / WORKER_RSS_ADMISSION_COST)));
87
+ const maxWorkers = Math.min(requested, admittedWorkers);
88
+ const perWorkerEnvelope = workerEnvelope / maxWorkers;
89
+ const workerHeapLimit = Math.min(MAX_WORKER_HEAP, Math.max(MIN_WORKER_HEAP, Math.floor(perWorkerEnvelope * .65)));
90
+ return Object.freeze({
91
+ version: 1,
92
+ source: effective.source,
93
+ effectiveLimit: effective.bytes,
94
+ softRssLimit,
95
+ hardRssLimit,
96
+ requestedWorkers: requested,
97
+ admittedWorkers,
98
+ maxWorkers,
99
+ workerHeapLimit,
100
+ mainProcessReserve: MAIN_PROCESS_RESERVE,
101
+ replacementOverlapReserve: REPLACEMENT_OVERLAP_RESERVE
102
+ });
103
+ }
104
+ function formatBytes(bytes) {
105
+ if (bytes == null) return "unknown";
106
+ return `${Math.round(bytes / MIB)} MiB`;
107
+ }
108
+ function formatHotMemoryPlan(plan) {
109
+ return [
110
+ `effective limit: ${formatBytes(plan.effectiveLimit)} (${plan.source})`,
111
+ `RSS soft/hard: ${formatBytes(plan.softRssLimit)} / ${formatBytes(plan.hardRssLimit)}`,
112
+ `workers requested/admitted/selected: ${plan.requestedWorkers} / ${plan.admittedWorkers} / ${plan.maxWorkers}`,
113
+ `worker heap recycle threshold: ${formatBytes(plan.workerHeapLimit)}`,
114
+ `reserves main/replacement: ${formatBytes(plan.mainProcessReserve)} / ${formatBytes(plan.replacementOverlapReserve)}`
115
+ ];
116
+ }
117
+ Object.freeze({
118
+ MIB,
119
+ MIN_WORKER_HEAP,
120
+ MAX_WORKER_HEAP,
121
+ MAIN_PROCESS_RESERVE,
122
+ REPLACEMENT_OVERLAP_RESERVE,
123
+ WORKER_RSS_ADMISSION_COST,
124
+ MAX_AUTO_WORKERS
125
+ });
126
+ //#endregion
127
+ Object.defineProperty(exports, "createHotMemoryPlan", {
128
+ enumerable: true,
129
+ get: function() {
130
+ return createHotMemoryPlan;
131
+ }
132
+ });
133
+ Object.defineProperty(exports, "formatHotMemoryPlan", {
134
+ enumerable: true,
135
+ get: function() {
136
+ return formatHotMemoryPlan;
137
+ }
138
+ });
139
+ Object.defineProperty(exports, "memory_exports", {
140
+ enumerable: true,
141
+ get: function() {
142
+ return memory_exports;
143
+ }
144
+ });