@nx/vite 23.0.0-beta.18 → 23.0.0-beta.19

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 (168) hide show
  1. package/dist/PLUGIN.md +33 -0
  2. package/{executors.d.ts → dist/executors.d.ts} +0 -1
  3. package/{index.d.ts → dist/index.d.ts} +0 -1
  4. package/{plugin.d.ts → dist/plugin.d.ts} +0 -1
  5. package/{plugins → dist/plugins}/nx-copy-assets.plugin.d.ts +0 -1
  6. package/{plugins → dist/plugins}/nx-tsconfig-paths.plugin.d.ts +0 -1
  7. package/{plugins → dist/plugins}/nx-vite-build-coordination.plugin.d.ts +0 -1
  8. package/{plugins → dist/plugins}/rollup-replace-files.plugin.d.ts +0 -1
  9. package/{src → dist/src}/executors/build/build.impl.d.ts +0 -1
  10. package/{src → dist/src}/executors/build/build.impl.js +3 -35
  11. package/{src → dist/src}/executors/build/compat.d.ts +0 -1
  12. package/{src → dist/src}/executors/dev-server/compat.d.ts +0 -1
  13. package/{src → dist/src}/executors/dev-server/dev-server.impl.d.ts +0 -1
  14. package/{src → dist/src}/executors/dev-server/dev-server.impl.js +3 -35
  15. package/{src → dist/src}/executors/preview-server/compat.d.ts +0 -1
  16. package/{src → dist/src}/executors/preview-server/preview-server.impl.d.ts +0 -1
  17. package/{src → dist/src}/executors/preview-server/preview-server.impl.js +3 -35
  18. package/{src → dist/src}/generators/configuration/configuration.d.ts +0 -1
  19. package/{src → dist/src}/generators/configuration/configuration.js +3 -1
  20. package/{src → dist/src}/generators/configuration/lib/convert-non-vite.d.ts +0 -1
  21. package/{src → dist/src}/generators/convert-to-inferred/convert-to-inferred.d.ts +0 -1
  22. package/{src → dist/src}/generators/convert-to-inferred/lib/build-post-target-transformer.d.ts +0 -1
  23. package/{src → dist/src}/generators/convert-to-inferred/lib/preview-post-target-transformer.d.ts +0 -1
  24. package/{src → dist/src}/generators/convert-to-inferred/lib/serve-post-target-transformer.d.ts +0 -1
  25. package/{src → dist/src}/generators/convert-to-inferred/lib/utils.d.ts +0 -1
  26. package/{src → dist/src}/generators/init/init.d.ts +0 -1
  27. package/{src → dist/src}/generators/init/lib/utils.d.ts +0 -1
  28. package/dist/src/generators/setup-paths-plugin/lib/utils.d.ts +1 -0
  29. package/dist/src/generators/setup-paths-plugin/lib/utils.js +2 -0
  30. package/{src → dist/src}/generators/setup-paths-plugin/setup-paths-plugin.d.ts +0 -1
  31. package/{src → dist/src}/migrations/update-20-0-4/add-vite-temp-files-to-git-ignore.d.ts +0 -1
  32. package/dist/src/migrations/update-20-0-4/add-vite-temp-files-to-git-ignore.md +12 -0
  33. package/{src → dist/src}/migrations/update-20-5-0/eslint-ignore-vite-temp-files.d.ts +0 -1
  34. package/dist/src/migrations/update-20-5-0/eslint-ignore-vite-temp-files.js +44 -0
  35. package/dist/src/migrations/update-20-5-0/eslint-ignore-vite-temp-files.md +45 -0
  36. package/{src → dist/src}/migrations/update-20-5-0/install-jiti.d.ts +0 -1
  37. package/dist/src/migrations/update-20-5-0/install-jiti.md +6 -0
  38. package/{src → dist/src}/migrations/update-20-5-0/update-resolve-conditions.d.ts +0 -1
  39. package/dist/src/migrations/update-20-5-0/update-resolve-conditions.md +42 -0
  40. package/dist/src/migrations/update-22-2-0/ai-instructions-for-vitest-4.md +725 -0
  41. package/{src → dist/src}/migrations/update-22-2-0/migrate-vitest-to-vitest-package.d.ts +0 -1
  42. package/dist/src/migrations/update-23-0-0/ai-instructions-for-vite-8.md +254 -0
  43. package/{src → dist/src}/migrations/update-23-0-0/ensure-vitest-package-migration.d.ts +0 -1
  44. package/dist/src/migrations/update-23-0-0/ensure-vitest-package-migration.md +18 -0
  45. package/{src → dist/src}/migrations/update-23-0-0/rename-rollup-options-to-rolldown-options.d.ts +0 -1
  46. package/dist/src/migrations/update-23-0-0/rename-rollup-options-to-rolldown-options.md +65 -0
  47. package/{src → dist/src}/plugins/plugin.d.ts +0 -1
  48. package/{src → dist/src}/utils/deprecation.d.ts +0 -1
  49. package/{src → dist/src}/utils/detect-ui-framework.d.ts +0 -1
  50. package/{src → dist/src}/utils/e2e-web-server-info-utils.d.ts +0 -1
  51. package/{src → dist/src}/utils/ensure-dependencies.d.ts +0 -1
  52. package/{src → dist/src}/utils/executor-utils.d.ts +0 -1
  53. package/{src → dist/src}/utils/find-vite-config.d.ts +0 -1
  54. package/{src → dist/src}/utils/generator-utils.d.ts +0 -1
  55. package/{src → dist/src}/utils/ignore-vite-temp-files.d.ts +0 -1
  56. package/{src → dist/src}/utils/ignore-vite-temp-files.js +7 -35
  57. package/{src → dist/src}/utils/nx-tsconfig-paths-find-file.d.ts +0 -1
  58. package/{src → dist/src}/utils/options-utils.d.ts +0 -1
  59. package/{src → dist/src}/utils/test-files/test-vite-configs.d.ts +0 -1
  60. package/{src → dist/src}/utils/version-utils.d.ts +0 -1
  61. package/{src → dist/src}/utils/versions.d.ts +0 -1
  62. package/{src → dist/src}/utils/versions.js +2 -1
  63. package/{src → dist/src}/utils/vite-config-edit-utils.d.ts +0 -1
  64. package/executors.json +12 -12
  65. package/generators.json +8 -8
  66. package/migrations.json +10 -10
  67. package/package.json +73 -28
  68. package/executors.d.ts.map +0 -1
  69. package/index.d.ts.map +0 -1
  70. package/plugin.d.ts.map +0 -1
  71. package/plugins/nx-copy-assets.plugin.d.ts.map +0 -1
  72. package/plugins/nx-tsconfig-paths.plugin.d.ts.map +0 -1
  73. package/plugins/nx-vite-build-coordination.plugin.d.ts.map +0 -1
  74. package/plugins/rollup-replace-files.plugin.d.ts.map +0 -1
  75. package/src/executors/build/build.impl.d.ts.map +0 -1
  76. package/src/executors/build/compat.d.ts.map +0 -1
  77. package/src/executors/dev-server/compat.d.ts.map +0 -1
  78. package/src/executors/dev-server/dev-server.impl.d.ts.map +0 -1
  79. package/src/executors/preview-server/compat.d.ts.map +0 -1
  80. package/src/executors/preview-server/preview-server.impl.d.ts.map +0 -1
  81. package/src/generators/configuration/configuration.d.ts.map +0 -1
  82. package/src/generators/configuration/lib/convert-non-vite.d.ts.map +0 -1
  83. package/src/generators/convert-to-inferred/convert-to-inferred.d.ts.map +0 -1
  84. package/src/generators/convert-to-inferred/lib/build-post-target-transformer.d.ts.map +0 -1
  85. package/src/generators/convert-to-inferred/lib/preview-post-target-transformer.d.ts.map +0 -1
  86. package/src/generators/convert-to-inferred/lib/serve-post-target-transformer.d.ts.map +0 -1
  87. package/src/generators/convert-to-inferred/lib/utils.d.ts.map +0 -1
  88. package/src/generators/init/init.d.ts.map +0 -1
  89. package/src/generators/init/lib/utils.d.ts.map +0 -1
  90. package/src/generators/setup-paths-plugin/lib/utils.d.ts +0 -1
  91. package/src/generators/setup-paths-plugin/lib/utils.d.ts.map +0 -1
  92. package/src/generators/setup-paths-plugin/lib/utils.js +0 -0
  93. package/src/generators/setup-paths-plugin/setup-paths-plugin.d.ts.map +0 -1
  94. package/src/migrations/update-20-0-4/add-vite-temp-files-to-git-ignore.d.ts.map +0 -1
  95. package/src/migrations/update-20-5-0/eslint-ignore-vite-temp-files.d.ts.map +0 -1
  96. package/src/migrations/update-20-5-0/eslint-ignore-vite-temp-files.js +0 -76
  97. package/src/migrations/update-20-5-0/install-jiti.d.ts.map +0 -1
  98. package/src/migrations/update-20-5-0/update-resolve-conditions.d.ts.map +0 -1
  99. package/src/migrations/update-22-2-0/migrate-vitest-to-vitest-package.d.ts.map +0 -1
  100. package/src/migrations/update-23-0-0/ensure-vitest-package-migration.d.ts.map +0 -1
  101. package/src/migrations/update-23-0-0/rename-rollup-options-to-rolldown-options.d.ts.map +0 -1
  102. package/src/plugins/plugin.d.ts.map +0 -1
  103. package/src/utils/deprecation.d.ts.map +0 -1
  104. package/src/utils/detect-ui-framework.d.ts.map +0 -1
  105. package/src/utils/e2e-web-server-info-utils.d.ts.map +0 -1
  106. package/src/utils/ensure-dependencies.d.ts.map +0 -1
  107. package/src/utils/executor-utils.d.ts.map +0 -1
  108. package/src/utils/find-vite-config.d.ts.map +0 -1
  109. package/src/utils/generator-utils.d.ts.map +0 -1
  110. package/src/utils/ignore-vite-temp-files.d.ts.map +0 -1
  111. package/src/utils/nx-tsconfig-paths-find-file.d.ts.map +0 -1
  112. package/src/utils/options-utils.d.ts.map +0 -1
  113. package/src/utils/test-files/test-vite-configs.d.ts.map +0 -1
  114. package/src/utils/version-utils.d.ts.map +0 -1
  115. package/src/utils/versions.d.ts.map +0 -1
  116. package/src/utils/vite-config-edit-utils.d.ts.map +0 -1
  117. /package/{LICENSE → dist/LICENSE} +0 -0
  118. /package/{executors.js → dist/executors.js} +0 -0
  119. /package/{index.js → dist/index.js} +0 -0
  120. /package/{plugin.js → dist/plugin.js} +0 -0
  121. /package/{plugins → dist/plugins}/nx-copy-assets.plugin.js +0 -0
  122. /package/{plugins → dist/plugins}/nx-tsconfig-paths.plugin.js +0 -0
  123. /package/{plugins → dist/plugins}/nx-vite-build-coordination.plugin.js +0 -0
  124. /package/{plugins → dist/plugins}/rollup-replace-files.plugin.js +0 -0
  125. /package/{src → dist/src}/executors/build/compat.js +0 -0
  126. /package/{src → dist/src}/executors/build/schema.d.ts +0 -0
  127. /package/{src → dist/src}/executors/build/schema.json +0 -0
  128. /package/{src → dist/src}/executors/dev-server/compat.js +0 -0
  129. /package/{src → dist/src}/executors/dev-server/schema.d.ts +0 -0
  130. /package/{src → dist/src}/executors/dev-server/schema.json +0 -0
  131. /package/{src → dist/src}/executors/preview-server/compat.js +0 -0
  132. /package/{src → dist/src}/executors/preview-server/schema.d.ts +0 -0
  133. /package/{src → dist/src}/executors/preview-server/schema.json +0 -0
  134. /package/{src → dist/src}/generators/configuration/lib/convert-non-vite.js +0 -0
  135. /package/{src → dist/src}/generators/configuration/schema.d.ts +0 -0
  136. /package/{src → dist/src}/generators/configuration/schema.json +0 -0
  137. /package/{src → dist/src}/generators/convert-to-inferred/convert-to-inferred.js +0 -0
  138. /package/{src → dist/src}/generators/convert-to-inferred/lib/build-post-target-transformer.js +0 -0
  139. /package/{src → dist/src}/generators/convert-to-inferred/lib/preview-post-target-transformer.js +0 -0
  140. /package/{src → dist/src}/generators/convert-to-inferred/lib/serve-post-target-transformer.js +0 -0
  141. /package/{src → dist/src}/generators/convert-to-inferred/lib/utils.js +0 -0
  142. /package/{src → dist/src}/generators/convert-to-inferred/schema.json +0 -0
  143. /package/{src → dist/src}/generators/init/init.js +0 -0
  144. /package/{src → dist/src}/generators/init/lib/utils.js +0 -0
  145. /package/{src → dist/src}/generators/init/schema.d.ts +0 -0
  146. /package/{src → dist/src}/generators/init/schema.json +0 -0
  147. /package/{src → dist/src}/generators/setup-paths-plugin/schema.d.ts +0 -0
  148. /package/{src → dist/src}/generators/setup-paths-plugin/schema.json +0 -0
  149. /package/{src → dist/src}/generators/setup-paths-plugin/setup-paths-plugin.js +0 -0
  150. /package/{src → dist/src}/migrations/update-20-0-4/add-vite-temp-files-to-git-ignore.js +0 -0
  151. /package/{src → dist/src}/migrations/update-20-5-0/install-jiti.js +0 -0
  152. /package/{src → dist/src}/migrations/update-20-5-0/update-resolve-conditions.js +0 -0
  153. /package/{src → dist/src}/migrations/update-22-2-0/migrate-vitest-to-vitest-package.js +0 -0
  154. /package/{src → dist/src}/migrations/update-23-0-0/ensure-vitest-package-migration.js +0 -0
  155. /package/{src → dist/src}/migrations/update-23-0-0/rename-rollup-options-to-rolldown-options.js +0 -0
  156. /package/{src → dist/src}/plugins/plugin.js +0 -0
  157. /package/{src → dist/src}/utils/deprecation.js +0 -0
  158. /package/{src → dist/src}/utils/detect-ui-framework.js +0 -0
  159. /package/{src → dist/src}/utils/e2e-web-server-info-utils.js +0 -0
  160. /package/{src → dist/src}/utils/ensure-dependencies.js +0 -0
  161. /package/{src → dist/src}/utils/executor-utils.js +0 -0
  162. /package/{src → dist/src}/utils/find-vite-config.js +0 -0
  163. /package/{src → dist/src}/utils/generator-utils.js +0 -0
  164. /package/{src → dist/src}/utils/nx-tsconfig-paths-find-file.js +0 -0
  165. /package/{src → dist/src}/utils/options-utils.js +0 -0
  166. /package/{src → dist/src}/utils/test-files/test-vite-configs.js +0 -0
  167. /package/{src → dist/src}/utils/version-utils.js +0 -0
  168. /package/{src → dist/src}/utils/vite-config-edit-utils.js +0 -0
@@ -0,0 +1,725 @@
1
+ # Vitest 4.0 Migration Instructions for LLM
2
+
3
+ ## Overview
4
+
5
+ These instructions guide you through migrating an Nx workspace containing multiple Vitest projects from Vitest 3.x to Vitest 4.0. Work systematically through each breaking change category.
6
+
7
+ ## Pre-Migration Checklist
8
+
9
+ 1. **Identify all Vitest projects**:
10
+
11
+ ```bash
12
+ nx show projects --with-target test
13
+ ```
14
+
15
+ 2. **Locate all Vitest configuration files**:
16
+ - Search for `vitest.config.{ts,js,mjs}`
17
+ - Search for `vitest.workspace.{ts,js,mjs}`
18
+ - Check `project.json` files for inline Vitest configuration
19
+
20
+ 3. **Identify affected code**:
21
+ - Test files: `**/*.{spec,test}.{ts,js,tsx,jsx}`
22
+ - Mock usage: Files using `vi.fn()`, `vi.spyOn()`, `vi.mock()`
23
+ - Coverage configuration references
24
+
25
+ ## Migration Steps by Category
26
+
27
+ ### 1. Configuration File Updates
28
+
29
+ #### 1.1 Coverage Configuration
30
+
31
+ **Search Pattern**: `coverage` in all `vitest.config.*` files and `project.json` test target options
32
+
33
+ **Changes Required**:
34
+
35
+ ```typescript
36
+ // ❌ BEFORE (Vitest 3.x)
37
+ export default defineConfig({
38
+ test: {
39
+ coverage: {
40
+ all: true,
41
+ extensions: ['.ts', '.tsx'],
42
+ ignoreEmptyLines: false,
43
+ experimentalAstAwareRemapping: true,
44
+ },
45
+ },
46
+ });
47
+
48
+ // ✅ AFTER (Vitest 4.0)
49
+ export default defineConfig({
50
+ test: {
51
+ coverage: {
52
+ // Explicitly define files to include in coverage
53
+ include: ['src/**/*.{ts,tsx}'],
54
+ // Remove: all, extensions, ignoreEmptyLines, experimentalAstAwareRemapping
55
+ },
56
+ },
57
+ });
58
+ ```
59
+
60
+ **Action Items**:
61
+
62
+ - [ ] Remove `coverage.all` option
63
+ - [ ] Remove `coverage.extensions` option
64
+ - [ ] Remove `coverage.ignoreEmptyLines` option
65
+ - [ ] Remove `coverage.experimentalAstAwareRemapping` option
66
+ - [ ] Add explicit `coverage.include` patterns based on project structure
67
+ - [ ] Update any documentation referencing these options
68
+
69
+ #### 1.2 Pool Options Restructuring
70
+
71
+ **Search Pattern**: `poolOptions`, `maxThreads`, `maxForks`, `singleThread`, `singleFork` in all Vitest config files
72
+
73
+ **Changes Required**:
74
+
75
+ ```typescript
76
+ // ❌ BEFORE (Vitest 3.x)
77
+ export default defineConfig({
78
+ test: {
79
+ maxThreads: 4,
80
+ maxForks: 2,
81
+ singleThread: false,
82
+ poolOptions: {
83
+ threads: {
84
+ useAtomics: true,
85
+ },
86
+ vmThreads: {
87
+ memoryLimit: '512MB',
88
+ },
89
+ },
90
+ },
91
+ });
92
+
93
+ // ✅ AFTER (Vitest 4.0)
94
+ export default defineConfig({
95
+ test: {
96
+ maxWorkers: 4, // Consolidates maxThreads and maxForks
97
+ isolate: true, // Replaces singleThread: false
98
+ // Remove: poolOptions, threads.useAtomics
99
+ vmMemoryLimit: '512MB', // Moved to top-level
100
+ },
101
+ });
102
+ ```
103
+
104
+ **Action Items**:
105
+
106
+ - [ ] Replace `maxThreads` and `maxForks` with single `maxWorkers` option
107
+ - [ ] Replace `singleThread: true` or `singleFork: true` with `maxWorkers: 1, isolate: false`
108
+ - [ ] Move all `poolOptions.*` nested options to top-level (e.g., `poolOptions.vmThreads.memoryLimit` → `vmMemoryLimit`)
109
+ - [ ] Remove `threads.useAtomics` option
110
+ - [ ] Update CI environment variables: `VITEST_MAX_THREADS` and `VITEST_MAX_FORKS` → `VITEST_MAX_WORKERS`
111
+
112
+ #### 1.3 Workspace to Projects Rename
113
+
114
+ **Search Pattern**: `workspace` property in Vitest config files
115
+
116
+ **Changes Required**:
117
+
118
+ ```typescript
119
+ // ❌ BEFORE (Vitest 3.x)
120
+ export default defineConfig({
121
+ test: {
122
+ workspace: ['apps/*', 'libs/*'],
123
+ },
124
+ });
125
+
126
+ // ✅ AFTER (Vitest 4.0)
127
+ export default defineConfig({
128
+ test: {
129
+ projects: ['apps/*', 'libs/*'],
130
+ },
131
+ });
132
+ ```
133
+
134
+ **Action Items**:
135
+
136
+ - [ ] Rename `workspace` property to `projects` in all config files
137
+ - [ ] Remove external workspace file references (must be inline in config)
138
+ - [ ] Update `poolMatchGlobs` to use `projects` pattern matching instead
139
+ - [ ] Update `environmentMatchGlobs` to use `projects` pattern matching instead
140
+
141
+ #### 1.4 Browser Configuration
142
+
143
+ **Search Pattern**: `browser.provider`, `browser.testerScripts`, imports from `@vitest/browser`
144
+
145
+ **Changes Required**:
146
+
147
+ ```typescript
148
+ // ❌ BEFORE (Vitest 3.x)
149
+ export default defineConfig({
150
+ test: {
151
+ browser: {
152
+ enabled: true,
153
+ provider: 'playwright', // String value
154
+ testerScripts: ['./setup.js'],
155
+ },
156
+ },
157
+ });
158
+
159
+ // Import changes
160
+ import { page } from '@vitest/browser';
161
+
162
+ // ✅ AFTER (Vitest 4.0)
163
+ export default defineConfig({
164
+ test: {
165
+ browser: {
166
+ enabled: true,
167
+ provider: { name: 'playwright' }, // Object value
168
+ testerHtmlPath: './test-setup.html', // Renamed from testerScripts
169
+ },
170
+ },
171
+ });
172
+
173
+ // Import changes
174
+ import { page } from 'vitest/browser';
175
+ ```
176
+
177
+ **Action Items**:
178
+
179
+ - [ ] Convert `browser.provider` string values to object format: `{ name: 'provider-name' }`
180
+ - [ ] Replace `browser.testerScripts` with `browser.testerHtmlPath`
181
+ - [ ] Update all imports from `@vitest/browser` to `vitest/browser`
182
+ - [ ] Remove `@vitest/browser` from dependencies if no longer needed
183
+
184
+ #### 1.5 Deprecated Configuration Options
185
+
186
+ **Search Pattern**: `deps.external`, `deps.inline`, `deps.fallbackCJS` in config files
187
+
188
+ **Changes Required**:
189
+
190
+ ```typescript
191
+ // ❌ BEFORE (Vitest 3.x)
192
+ export default defineConfig({
193
+ test: {
194
+ deps: {
195
+ external: ['some-package'],
196
+ inline: ['inline-package'],
197
+ fallbackCJS: true,
198
+ },
199
+ },
200
+ });
201
+
202
+ // ✅ AFTER (Vitest 4.0)
203
+ export default defineConfig({
204
+ test: {
205
+ server: {
206
+ deps: {
207
+ external: ['some-package'],
208
+ inline: ['inline-package'],
209
+ fallbackCJS: true,
210
+ },
211
+ },
212
+ },
213
+ });
214
+ ```
215
+
216
+ **Action Items**:
217
+
218
+ - [ ] Move `deps.*` options under `server.deps` namespace
219
+ - [ ] Remove `poolMatchGlobs` (use `projects` with conditions instead)
220
+ - [ ] Remove `environmentMatchGlobs` (use `projects` with conditions instead)
221
+
222
+ ### 2. Test Code Updates
223
+
224
+ #### 2.1 Mock Function Name Changes
225
+
226
+ **Search Pattern**: `.getMockName()` calls in test files
227
+
228
+ **Changes Required**:
229
+
230
+ ```typescript
231
+ // ❌ BEFORE (Vitest 3.x)
232
+ const mockFn = vi.fn();
233
+ expect(mockFn.getMockName()).toBe('spy'); // Old default
234
+
235
+ // ✅ AFTER (Vitest 4.0)
236
+ const mockFn = vi.fn();
237
+ expect(mockFn.getMockName()).toBe('vi.fn()'); // New default
238
+
239
+ // If you need custom names, set them explicitly
240
+ const namedMock = vi.fn().mockName('myCustomName');
241
+ expect(namedMock.getMockName()).toBe('myCustomName');
242
+ ```
243
+
244
+ **Action Items**:
245
+
246
+ - [ ] Update test assertions checking default mock names from `'spy'` to `'vi.fn()'`
247
+ - [ ] Add explicit `.mockName()` calls where specific names are required
248
+
249
+ #### 2.2 Mock Invocation Call Order
250
+
251
+ **Search Pattern**: `.mock.invocationCallOrder` in test files
252
+
253
+ **Changes Required**:
254
+
255
+ ```typescript
256
+ // ❌ BEFORE (Vitest 3.x)
257
+ const mockFn = vi.fn();
258
+ mockFn();
259
+ expect(mockFn.mock.invocationCallOrder[0]).toBe(0); // Started at 0
260
+
261
+ // ✅ AFTER (Vitest 4.0)
262
+ const mockFn = vi.fn();
263
+ mockFn();
264
+ expect(mockFn.mock.invocationCallOrder[0]).toBe(1); // Now starts at 1 (Jest-compatible)
265
+ ```
266
+
267
+ **Action Items**:
268
+
269
+ - [ ] Update assertions on `invocationCallOrder` to account for 1-based indexing
270
+ - [ ] Search for off-by-one errors in call order comparisons
271
+
272
+ #### 2.3 Constructor Spies and Mocks
273
+
274
+ **Search Pattern**: `vi.spyOn` on constructors, `vi.fn()` used as constructors
275
+
276
+ **Changes Required**:
277
+
278
+ ```typescript
279
+ // ❌ BEFORE (Vitest 3.x) - Arrow function constructors might have worked
280
+ const MockConstructor = vi.fn(() => ({ value: 42 }));
281
+ new MockConstructor(); // May have worked in v3
282
+
283
+ // ✅ AFTER (Vitest 4.0) - Must use function or class
284
+ const MockConstructor = vi.fn(function () {
285
+ return { value: 42 };
286
+ });
287
+ new MockConstructor(); // Correctly supports 'new'
288
+
289
+ // Or use class syntax
290
+ class MockClass {
291
+ value = 42;
292
+ }
293
+ const MockConstructor = vi.fn(MockClass);
294
+ ```
295
+
296
+ **Action Items**:
297
+
298
+ - [ ] Convert arrow function mocks used as constructors to `function` keyword or `class` syntax
299
+ - [ ] Test all constructor spies to ensure `new` keyword works correctly
300
+ - [ ] Update any mocks that expect constructor behavior
301
+
302
+ #### 2.4 RestoreAllMocks Behavior
303
+
304
+ **Search Pattern**: `vi.restoreAllMocks()` in test files
305
+
306
+ **Changes Required**:
307
+
308
+ ```typescript
309
+ // ❌ BEFORE (Vitest 3.x)
310
+ vi.mock('./module', () => ({ fn: vi.fn() }));
311
+ vi.restoreAllMocks(); // Would restore automocks
312
+
313
+ // ✅ AFTER (Vitest 4.0)
314
+ vi.mock('./module', () => ({ fn: vi.fn() }));
315
+ vi.restoreAllMocks(); // Only restores manual spies, NOT automocks
316
+
317
+ // To reset automocks, use:
318
+ vi.unmock('./module');
319
+ // or
320
+ vi.resetModules();
321
+ ```
322
+
323
+ **Action Items**:
324
+
325
+ - [ ] Review all `vi.restoreAllMocks()` usage
326
+ - [ ] Add explicit `vi.unmock()` or `vi.resetModules()` calls for automocked modules
327
+ - [ ] Ensure test isolation is maintained after this change
328
+
329
+ #### 2.5 SpyOn Return Value Changes
330
+
331
+ **Search Pattern**: `vi.spyOn()` on already mocked functions
332
+
333
+ **Changes Required**:
334
+
335
+ ```typescript
336
+ // ❌ BEFORE (Vitest 3.x)
337
+ const mock = vi.fn();
338
+ const spy = vi.spyOn({ method: mock }, 'method');
339
+ // spy !== mock (created new spy)
340
+
341
+ // ✅ AFTER (Vitest 4.0)
342
+ const mock = vi.fn();
343
+ const spy = vi.spyOn({ method: mock }, 'method');
344
+ // spy === mock (returns same instance)
345
+ ```
346
+
347
+ **Action Items**:
348
+
349
+ - [ ] Review code that creates spies on existing mocks
350
+ - [ ] Remove redundant spy creation if same instance is returned
351
+ - [ ] Update assertions that check spy identity
352
+
353
+ #### 2.6 Automock Behavior Changes
354
+
355
+ **Search Pattern**: `vi.mock()` with factory functions, `.mockRestore()` on automocks
356
+
357
+ **Changes Required**:
358
+
359
+ ```typescript
360
+ // ❌ BEFORE (Vitest 3.x)
361
+ vi.mock('./utils', () => ({
362
+ get value() {
363
+ return 42;
364
+ }, // Would call getter
365
+ }));
366
+
367
+ import { value } from './utils';
368
+ console.log(value); // Would execute getter logic
369
+
370
+ // Restore might have worked
371
+ const spy = vi.spyOn(obj, 'method');
372
+ spy.mockRestore(); // Might work on automocks
373
+
374
+ // ✅ AFTER (Vitest 4.0)
375
+ vi.mock('./utils', () => ({
376
+ get value() {
377
+ return 42;
378
+ },
379
+ }));
380
+
381
+ import { value } from './utils';
382
+ console.log(value); // Returns undefined (doesn't call getter)
383
+
384
+ // Explicitly return value if needed
385
+ vi.mock('./utils', () => ({
386
+ value: 42, // Not a getter
387
+ }));
388
+
389
+ // mockRestore no longer works on automocks
390
+ const spy = vi.spyOn(obj, 'method');
391
+ spy.mockRestore(); // Throws error if method is automocked
392
+
393
+ // Use unmock instead
394
+ vi.unmock('./module');
395
+ ```
396
+
397
+ **Action Items**:
398
+
399
+ - [ ] Convert automocked getters to plain property values where needed
400
+ - [ ] Remove `.mockRestore()` calls on automocked methods
401
+ - [ ] Use `vi.unmock()` to clear automocks instead
402
+ - [ ] Test instance method isolation (they now share state with prototype)
403
+
404
+ #### 2.7 Settled Results Immediate Population
405
+
406
+ **Search Pattern**: `.mock.settledResults` in test files
407
+
408
+ **Changes Required**:
409
+
410
+ ```typescript
411
+ // ✅ AFTER (Vitest 4.0)
412
+ const asyncMock = vi.fn(async () => 'result');
413
+ const promise = asyncMock();
414
+
415
+ // settledResults is immediately populated with 'incomplete' status
416
+ expect(asyncMock.mock.settledResults[0]).toEqual({
417
+ type: 'incomplete',
418
+ value: undefined,
419
+ });
420
+
421
+ // After promise resolves
422
+ await promise;
423
+ expect(asyncMock.mock.settledResults[0]).toEqual({
424
+ type: 'fulfilled',
425
+ value: 'result',
426
+ });
427
+ ```
428
+
429
+ **Action Items**:
430
+
431
+ - [ ] Update tests that check `settledResults` before promise resolution
432
+ - [ ] Handle `'incomplete'` status in assertions
433
+ - [ ] Ensure tests properly await promises before checking settled results
434
+
435
+ ### 3. Reporter and CLI Changes
436
+
437
+ #### 3.1 Reporter API Changes
438
+
439
+ **Search Pattern**: Custom reporters, `onCollected`, `onTaskUpdate`, `onFinished`
440
+
441
+ **Changes Required**:
442
+
443
+ ```typescript
444
+ // ❌ BEFORE (Vitest 3.x)
445
+ export default {
446
+ onCollected(files) {
447
+ // Handle collected files
448
+ },
449
+ onTaskUpdate(task) {
450
+ // Handle task update
451
+ },
452
+ onFinished(files) {
453
+ // Handle completion
454
+ },
455
+ };
456
+
457
+ // ✅ AFTER (Vitest 4.0)
458
+ // Use new reporter API - consult Vitest 4 docs for replacement methods
459
+ ```
460
+
461
+ **Action Items**:
462
+
463
+ - [ ] Review custom reporters for removed API usage
464
+ - [ ] Consult Vitest 4 documentation for new reporter API
465
+ - [ ] Update or rewrite custom reporters to use new APIs
466
+
467
+ #### 3.2 Built-in Reporter Changes
468
+
469
+ **Search Pattern**: `reporters: ['basic']`, `reporters: ['verbose']`
470
+
471
+ **Changes Required**:
472
+
473
+ ```typescript
474
+ // ❌ BEFORE (Vitest 3.x)
475
+ export default defineConfig({
476
+ test: {
477
+ reporters: ['basic'],
478
+ },
479
+ });
480
+
481
+ // ✅ AFTER (Vitest 4.0)
482
+ export default defineConfig({
483
+ test: {
484
+ reporters: [['default', { summary: false }]], // Equivalent to 'basic'
485
+ },
486
+ });
487
+
488
+ // For verbose (tree output)
489
+ reporters: ['tree']; // Use 'tree' for hierarchical output
490
+ ```
491
+
492
+ **Action Items**:
493
+
494
+ - [ ] Replace `'basic'` reporter with `['default', { summary: false }]`
495
+ - [ ] Replace `'verbose'` reporter with `'tree'` for hierarchical output
496
+ - [ ] Update CI configuration if reporters are specified there
497
+
498
+ ### 4. Snapshot Changes
499
+
500
+ #### 4.1 Custom Elements Shadow Root
501
+
502
+ **Search Pattern**: Snapshot tests involving custom elements or Web Components
503
+
504
+ **Changes Required**:
505
+
506
+ ```typescript
507
+ // ✅ AFTER (Vitest 4.0)
508
+ // Shadow root contents now printed by default in snapshots
509
+
510
+ // If you want old behavior (don't print shadow root):
511
+ export default defineConfig({
512
+ test: {
513
+ printShadowRoot: false,
514
+ },
515
+ });
516
+ ```
517
+
518
+ **Action Items**:
519
+
520
+ - [ ] Review snapshot tests for custom elements
521
+ - [ ] Update snapshots if shadow root contents are now included
522
+ - [ ] Add `printShadowRoot: false` if old behavior is required
523
+
524
+ ### 5. Environment Variable Updates
525
+
526
+ **Search Pattern**: CI/CD configuration files, `.env` files, documentation
527
+
528
+ **Changes Required**:
529
+
530
+ ```bash
531
+ # ❌ BEFORE (Vitest 3.x)
532
+ VITEST_MAX_THREADS=4
533
+ VITEST_MAX_FORKS=2
534
+ VITE_NODE_DEPS_MODULE_DIRECTORIES=/custom/path
535
+
536
+ # ✅ AFTER (Vitest 4.0)
537
+ VITEST_MAX_WORKERS=4
538
+ VITEST_MODULE_DIRECTORIES=/custom/path
539
+ ```
540
+
541
+ **Action Items**:
542
+
543
+ - [ ] Update CI/CD pipeline environment variables
544
+ - [ ] Update `.env` files
545
+ - [ ] Update documentation referencing old environment variables
546
+ - [ ] Search for `VITEST_MAX_THREADS`, `VITEST_MAX_FORKS`, `VITE_NODE_DEPS_MODULE_DIRECTORIES`
547
+
548
+ ### 6. Advanced: Module Runner Changes
549
+
550
+ **Search Pattern**: `vitest/execute`, `__vitest_executor`, `vite-node`
551
+
552
+ **Changes Required**:
553
+
554
+ ```typescript
555
+ // ❌ BEFORE (Vitest 3.x)
556
+ import { execute } from 'vitest/execute';
557
+ // Access to __vitest_executor
558
+
559
+ // ✅ AFTER (Vitest 4.0)
560
+ // Use Vite's Module Runner API instead
561
+ // Consult Vite Module Runner documentation
562
+ ```
563
+
564
+ **Action Items**:
565
+
566
+ - [ ] If using `vitest/execute`, migrate to Vite Module Runner
567
+ - [ ] Remove dependencies on `__vitest_executor`
568
+ - [ ] Update custom pool implementations (complete rewrite needed)
569
+
570
+ ### 7. Type Definition Updates
571
+
572
+ **Search Pattern**: TypeScript imports from `vitest`, type errors after upgrade
573
+
574
+ **Changes Required**:
575
+
576
+ ```typescript
577
+ // All deprecated type exports removed
578
+ // If you get TypeScript errors about missing types:
579
+ // - Check if you're using deprecated type names
580
+ // - Update to current type names from Vitest 4 API
581
+ // - Remove explicit @types/node if it was only needed due to Vitest bug
582
+ ```
583
+
584
+ **Action Items**:
585
+
586
+ - [ ] Run TypeScript compilation on all test files
587
+ - [ ] Fix any type errors related to removed Vitest type definitions
588
+ - [ ] Review `@types/node` usage (may no longer be accidentally included)
589
+
590
+ ## Post-Migration Validation
591
+
592
+ ### 1. Run Tests Per Project
593
+
594
+ ```bash
595
+ # Test each project individually
596
+ nx run-many -t test -p PROJECT_NAME
597
+ ```
598
+
599
+ ### 2. Run All Tests
600
+
601
+ ```bash
602
+ # Run tests across all affected projects
603
+ nx affected -t test
604
+ ```
605
+
606
+ ### 3. Check Coverage
607
+
608
+ ```bash
609
+ # Verify coverage generation works with new config
610
+ nx affected -t test --coverage
611
+ ```
612
+
613
+ ### 4. Validate CI Pipeline
614
+
615
+ ```bash
616
+ # Run full CI validation
617
+ nx prepush
618
+ ```
619
+
620
+ ### 5. Review Migration Checklist
621
+
622
+ - [ ] All configuration files updated
623
+ - [ ] All test files pass
624
+ - [ ] Coverage reports generate correctly
625
+ - [ ] CI/CD pipeline runs successfully
626
+ - [ ] Environment variables updated
627
+ - [ ] Documentation updated
628
+ - [ ] No deprecated API warnings in console
629
+
630
+ ## Common Issues and Solutions
631
+
632
+ ### Issue: Coverage includes too many files
633
+
634
+ **Solution**: Add explicit `coverage.include` patterns to match your source files
635
+
636
+ ### Issue: Tests fail with "arrow function constructors not supported"
637
+
638
+ **Solution**: Convert arrow functions used as constructors to `function` keyword or `class` syntax
639
+
640
+ ### Issue: Automocks not resetting between tests
641
+
642
+ **Solution**: Use `vi.unmock()` or `vi.resetModules()` instead of `vi.restoreAllMocks()`
643
+
644
+ ### Issue: Mock call order assertions failing
645
+
646
+ **Solution**: Update to 1-based indexing for `invocationCallOrder`
647
+
648
+ ### Issue: Browser tests failing after upgrade
649
+
650
+ **Solution**: Check browser provider is object format and imports use `vitest/browser`
651
+
652
+ ### Issue: TypeScript errors in test files
653
+
654
+ **Solution**: Update to new type definitions and remove usage of deprecated types
655
+
656
+ ## Files to Review
657
+
658
+ Create a checklist of all files that need review:
659
+
660
+ ```bash
661
+ # Configuration files
662
+ find . -name "vitest.config.*" -o -name "vitest.workspace.*"
663
+ find . -name "project.json" -exec grep -l "vitest" {} \;
664
+
665
+ # Test files
666
+ find . -name "*.spec.*" -o -name "*.test.*"
667
+
668
+ # Files with mock usage
669
+ rg "vi\.(fn|spyOn|mock|restoreAllMocks)" --type ts --type tsx --type js
670
+
671
+ # Files with coverage config
672
+ rg "coverage\.(all|extensions|ignoreEmptyLines)" --type ts --type js
673
+
674
+ # CI configuration
675
+ find . -name ".github/workflows/*.yml" -o -name ".gitlab-ci.yml" -o -name "azure-pipelines.yml"
676
+ ```
677
+
678
+ ## Migration Strategy for Large Workspaces
679
+
680
+ 1. **Migrate in phases**: Start with a small project, validate, then expand
681
+ 2. **Use feature branches**: Create separate branches for different migration aspects
682
+ 3. **Run tests frequently**: After each configuration change, run affected tests
683
+ 4. **Document issues**: Keep track of project-specific issues and solutions
684
+ 5. **Automate where possible**: Create codemods for repetitive changes
685
+
686
+ ## Useful Commands During Migration
687
+
688
+ ```bash
689
+ # Find all vitest configurations
690
+ nx show projects --with-target test
691
+
692
+ # Test specific project after changes
693
+ nx test PROJECT_NAME
694
+
695
+ # Test all affected
696
+ nx affected -t test
697
+
698
+ # View project details
699
+ nx show project PROJECT_NAME --web
700
+
701
+ # Clear Nx cache if needed
702
+ nx reset
703
+ ```
704
+
705
+ ## Guard Rails
706
+
707
+ DO NOT
708
+
709
+ - Force tests to pass by removing test logic and replacing it with `expect(true).toBe(true)`
710
+ - Remove assertions
711
+ - Add additional mocks that force tests to pass
712
+
713
+ ---
714
+
715
+ ## Notes for LLM Execution
716
+
717
+ When executing this migration:
718
+
719
+ 1. **Work systematically**: Complete one category before moving to the next
720
+ 2. **Test after each change**: Don't batch all changes without validation
721
+ 3. **Keep user informed**: Report progress through each section
722
+ 4. **Handle errors promptly**: If tests fail, fix immediately before proceeding
723
+ 5. **Update documentation**: Note any workspace-specific patterns or issues
724
+ 6. **Create meaningful commits**: Group related changes together with clear messages
725
+ 7. **Use TodoWrite tool**: Track migration progress for visibility