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