vitest-native 0.3.0 → 0.4.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +254 -11
  3. package/dist/chunk-CZWwpsFl.cjs +43 -0
  4. package/dist/{index-CJqS-y_M.d.cts → index-CJIhukN_.d.mts} +58 -4
  5. package/dist/{index-h4vpIkQO.d.mts → index-DEB7OFaJ.d.cts} +60 -2
  6. package/dist/index.cjs +252 -21
  7. package/dist/index.d.cts +1 -1
  8. package/dist/index.d.mts +1 -1
  9. package/dist/index.mjs +248 -18
  10. package/dist/jest-compat/interop.mjs +30 -0
  11. package/dist/jest-compat/jest-globals.d.mts +3 -0
  12. package/dist/jest-compat/jest-globals.mjs +9 -0
  13. package/dist/jest-compat/noop.d.mts +3 -0
  14. package/dist/jest-compat/noop.mjs +7 -0
  15. package/dist/jest-compat/setup.d.mts +3 -0
  16. package/dist/jest-compat/setup.mjs +41 -0
  17. package/dist/jest-compat.cjs +109 -0
  18. package/dist/jest-compat.d.cts +38 -0
  19. package/dist/jest-compat.d.mts +38 -0
  20. package/dist/jest-compat.mjs +104 -0
  21. package/dist/matchers.cjs +69 -0
  22. package/dist/matchers.d.cts +51 -0
  23. package/dist/matchers.d.mts +51 -0
  24. package/dist/matchers.mjs +66 -0
  25. package/dist/native/boundary.mjs +225 -0
  26. package/dist/native/globals.mjs +112 -0
  27. package/dist/native/hooks.mjs +85 -0
  28. package/dist/native/loader.mjs +123 -0
  29. package/dist/native/match.mjs +9 -0
  30. package/dist/native/reset.mjs +170 -0
  31. package/dist/native/resolve.mjs +22 -0
  32. package/dist/native/runner.mjs +18 -0
  33. package/dist/native/setup.mjs +134 -0
  34. package/dist/native/transform.mjs +79 -0
  35. package/dist/native/worker.mjs +96 -0
  36. package/dist/pool-B4mWN3N5.cjs +60 -0
  37. package/dist/pool-oPTZiSXU.mjs +58 -0
  38. package/dist/{preset-map-DxU6UgYS.cjs → preset-map-C3jxnkiX.cjs} +5 -1
  39. package/dist/{preset-map-BTpoNH3G.mjs → preset-map-OJm5IWuL.mjs} +5 -1
  40. package/dist/{presets-B-spxZz7.cjs → presets-2I68Ipyl.cjs} +437 -41
  41. package/dist/{presets-DvrcfEPz.mjs → presets-DOGXQzYT.mjs} +401 -6
  42. package/dist/presets.cjs +5 -1
  43. package/dist/presets.d.cts +2 -2
  44. package/dist/presets.d.mts +2 -2
  45. package/dist/presets.mjs +2 -2
  46. package/dist/setup.cjs +263 -115
  47. package/dist/setup.mjs +259 -112
  48. package/docs/migrating-from-jest.md +123 -0
  49. package/docs/migrating-from-vitest-react-native.md +109 -0
  50. package/package.json +65 -9
@@ -0,0 +1,109 @@
1
+ # Migrating from `vitest-react-native`
2
+
3
+ If you used [`vitest-community/vitest-react-native`](https://github.com/vitest-community/vitest-react-native)
4
+ and it stopped working on a newer Vitest, this is the continuation you're looking for.
5
+
6
+ **The short version:** it's the same idea, maintained. The original plugin and
7
+ `vitest-native`'s default engine share the same architecture — externalize React
8
+ Native to Node, strip its Flow types through a require hook, and mock only the
9
+ thin native boundary (`View`/`Text`/`UIManager`/`NativeModules`/…). The original
10
+ simply went unmaintained through Vitest's module-runner rewrites (v2 → v3 → v4)
11
+ and bit-rotted. `vitest-native` tracks current Vitest and React Native, and a CI
12
+ matrix gates it across both so it stays alive.
13
+
14
+ For the common case — render real RN with RNTL, mock your *own* modules with
15
+ `vi.mock` — migration is a config swap.
16
+
17
+ ---
18
+
19
+ ## 1. Swap the package
20
+
21
+ ```bash
22
+ # remove the old plugin
23
+ npm rm vitest-react-native @vitejs/plugin-react
24
+
25
+ # add this one (+ the babel preset it uses to strip RN's Flow types)
26
+ npm i -D vitest-native @react-native/babel-preset @babel/core
27
+ ```
28
+
29
+ Keep your existing `vitest`, `vite`, `react`, `react-native`, and
30
+ `@testing-library/react-native`. Requirements: **Vitest ≥ 4, Vite ≥ 5, React 19,
31
+ React Native 0.81–0.84 (validated), RNTL ≥ 12.**
32
+
33
+ ## 2. Update `vitest.config`
34
+
35
+ **Before** (`vitest-react-native`):
36
+
37
+ ```ts
38
+ import reactNative from 'vitest-react-native';
39
+ import react from '@vitejs/plugin-react';
40
+ import { defineConfig } from 'vitest/config';
41
+
42
+ export default defineConfig({
43
+ plugins: [reactNative(), react()],
44
+ });
45
+ ```
46
+
47
+ **After** (`vitest-native`):
48
+
49
+ ```ts
50
+ import { reactNative } from 'vitest-native';
51
+ import { defineConfig } from 'vitest/config';
52
+
53
+ export default defineConfig({
54
+ plugins: [reactNative()],
55
+ });
56
+ ```
57
+
58
+ Two changes:
59
+
60
+ - **Named import** — `import { reactNative }`, not a default import.
61
+ - **Drop `@vitejs/plugin-react`** — `vitest-native` configures the JSX runtime
62
+ itself (both engines). Adding `plugin-react` alongside it is unnecessary and
63
+ can double-transform.
64
+
65
+ That's it. `reactNative()` with no options resolves to the **native engine** (real
66
+ RN) whenever `@react-native/babel-preset` is installed, which it now is.
67
+
68
+ ## 3. Run
69
+
70
+ ```bash
71
+ npx vitest run
72
+ ```
73
+
74
+ Your existing tests render against real React Native exactly as before.
75
+
76
+ ---
77
+
78
+ ## What's the same
79
+
80
+ - Real RN component rendering via `@testing-library/react-native`.
81
+ - `vi.mock()` of **your own** modules (anything in your app's source graph).
82
+ - Standard Vitest everything — `expect`, `vi.fn`, coverage, watch, UI.
83
+
84
+ ## What's new (and optional)
85
+
86
+ - **Native is the zero-config default**, but a fast **mock engine** is one option
87
+ away — `reactNative({ engine: 'mock' })` — for pure-logic and environment-control
88
+ tests. A CI-gated cross-check keeps the mock behaviorally honest against real RN.
89
+ - **Presets** auto-shadow common native libraries (Reanimated, Gesture Handler,
90
+ Safe Area, Navigation, …) the way `jest` mocks them — no per-lib wiring.
91
+ - An opt-in **hot runtime** (`reactNative({ hotRuntime: true })`) keeps RN warm
92
+ across files for large suites.
93
+
94
+ ## Gotchas (the margins)
95
+
96
+ These are inherent to running RN externalized to Node — they applied to the
97
+ original plugin too:
98
+
99
+ - **`vi.mock` of an externalized RN-side library may not intercept.** Libraries
100
+ that load through Node (not your Vite source graph) bypass Vitest's mocker.
101
+ Prefer a **preset** (if one exists) or mock at the boundary. Your *own* modules
102
+ mock normally.
103
+ - **Custom Babel plugins don't run.** Transforms go through Vite/esbuild, not your
104
+ `babel.config.js`. Flow/TS stripping for RN and allow-listed packages is handled
105
+ by the require hook; use the `transform` allowlist for extra pure-JS packages
106
+ that ship untranspiled source.
107
+
108
+ If something that worked under the old plugin doesn't here, open an issue — parity
109
+ with `vitest-react-native` is a goal, and the cross-check corpus is how we prove it.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "vitest-native",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
- "description": "A Vitest plugin for React Native. One install, zero config.",
5
+ "description": "Run real React Native tests under Vitest. One install, zero config.",
6
6
  "license": "MIT",
7
7
  "author": "Daniel Fry",
8
8
  "repository": {
@@ -77,10 +77,43 @@
77
77
  "types": "./dist/presets.d.cts",
78
78
  "default": "./dist/presets.cjs"
79
79
  }
80
+ },
81
+ "./matchers": {
82
+ "import": {
83
+ "types": "./dist/matchers.d.mts",
84
+ "default": "./dist/matchers.mjs"
85
+ },
86
+ "require": {
87
+ "types": "./dist/matchers.d.cts",
88
+ "default": "./dist/matchers.cjs"
89
+ }
90
+ },
91
+ "./jest-compat": {
92
+ "import": {
93
+ "types": "./dist/jest-compat.d.mts",
94
+ "default": "./dist/jest-compat.mjs"
95
+ },
96
+ "require": {
97
+ "types": "./dist/jest-compat.d.cts",
98
+ "default": "./dist/jest-compat.cjs"
99
+ }
100
+ },
101
+ "./jest-compat/setup": {
102
+ "types": "./dist/jest-compat/setup.d.mts",
103
+ "default": "./dist/jest-compat/setup.mjs"
104
+ },
105
+ "./jest-compat/jest-globals": {
106
+ "types": "./dist/jest-compat/jest-globals.d.mts",
107
+ "default": "./dist/jest-compat/jest-globals.mjs"
108
+ },
109
+ "./jest-compat/extend-expect-noop": {
110
+ "types": "./dist/jest-compat/noop.d.mts",
111
+ "default": "./dist/jest-compat/noop.mjs"
80
112
  }
81
113
  },
82
114
  "files": [
83
115
  "dist",
116
+ "docs",
84
117
  "LICENSE",
85
118
  "CHANGELOG.md"
86
119
  ],
@@ -95,37 +128,60 @@
95
128
  "react": ">=18",
96
129
  "vite": ">=5",
97
130
  "vitest": ">=4",
98
- "@testing-library/react-native": ">=12"
131
+ "@testing-library/react-native": ">=12",
132
+ "@react-native/babel-preset": "*",
133
+ "@babel/core": "*"
99
134
  },
100
135
  "peerDependenciesMeta": {
101
136
  "@testing-library/react-native": {
102
137
  "optional": true
138
+ },
139
+ "@react-native/babel-preset": {
140
+ "optional": true
141
+ },
142
+ "@babel/core": {
143
+ "optional": true
103
144
  }
104
145
  },
105
146
  "devDependencies": {
147
+ "@babel/core": "^7.29.7",
148
+ "@react-native/babel-preset": "^0.85.3",
149
+ "@react-navigation/native": "7.2.5",
150
+ "@react-navigation/native-stack": "7.16.0",
106
151
  "@testing-library/react-native": "^12.9.0",
107
- "@types/node": "^25.3.5",
108
- "@types/react": "^19.2.14",
152
+ "@types/node": "25.3.5",
153
+ "@types/react": "19.2.14",
154
+ "@vitest/coverage-v8": "4.0.18",
155
+ "expo-constants": "56.0.16",
156
+ "expo-status-bar": "56.0.4",
109
157
  "react": "^19.0.0",
110
158
  "react-native": "^0.84.1",
159
+ "react-native-gesture-handler": "3.0.0",
160
+ "react-native-reanimated": "4.3.1",
161
+ "react-native-safe-area-context": "5.8.0",
162
+ "react-native-worklets": "0.9.1",
111
163
  "react-test-renderer": "^19.0.0",
112
- "tsdown": "^0.21.0",
113
- "typescript": "^5.7.0",
164
+ "tsdown": "0.21.0",
165
+ "typescript": "5.9.3",
114
166
  "vite": "^6.0.0",
115
167
  "vitest": "^4.0.0"
116
168
  },
117
169
  "scripts": {
118
170
  "build": "tsdown",
119
171
  "test": "vitest run",
172
+ "test:native": "vitest run --config tests-native/vitest.config.mts",
173
+ "test:native:hot": "vitest run --config tests-native/vitest.hot.config.mts",
120
174
  "lint": "oxlint --deny-warnings src/ tests/",
121
175
  "format": "oxfmt --write src/ tests/",
122
176
  "format:check": "oxfmt --check src/ tests/",
123
177
  "check-compat": "bun scripts/check-compat.ts",
124
178
  "typecheck": "tsc --noEmit",
125
179
  "clean": "rm -rf dist",
126
- "prepublishOnly": "bun run build && bun run test && bun run lint && bun run typecheck"
180
+ "prepublishOnly": "bun run build && bun run test && bun run lint && bun run typecheck",
181
+ "crosscheck": "node scripts/crosscheck.mjs"
127
182
  },
128
183
  "dependencies": {
129
- "flow-remove-types": "^2.304.0"
184
+ "flow-remove-types": "^2.304.0",
185
+ "magic-string": "^0.30.21"
130
186
  }
131
187
  }