You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/angular/cli/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.ts
+14-11Lines changed: 14 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -6,23 +6,25 @@
6
6
* found in the LICENSE file at https://angular.dev/license
@@ -54,26 +49,17 @@ export function createProvideZonelessForTestsSetupPrompt(testFilePath: string):
54
49
});
55
50
// ... rest of the test
56
51
});
57
-
58
-
// Example for a group of failing tests
59
-
describe('tests that require Zone.js', () => {
60
-
beforeEach(() => {
61
-
TestBed.configureTestingModule({
62
-
providers: [provideZoneChangeDetection()]
63
-
});
64
-
});
65
-
66
-
// ... all failing tests go here
67
-
});
68
52
\`\`\`
69
53
70
54
### IMPORTANT: Rules and Constraints
71
55
72
56
You must follow these rules without exception:
73
-
1. **DO** add \`provideZonelessChangeDetection()\` to the top-level \`beforeEach\` block as instructed in Step 1.
74
-
2. **DO** add \`provideZoneChangeDetection()\` to the providers for each individual test or group of tests that fail after the change in Step 1.
75
-
3. **DO NOT** attempt to fix the logic of the failing tests at this stage. The goal is only to enable zoneless for the suite and isolate the incompatible tests.
76
-
4. **DO NOT** make any other changes to the test file or any application code.
57
+
1. **DO** add \`provideZonelessChangeDetection()\` _once_ to the top-most \`describe\` in a \`beforeEach\` block as instructed in Step 1.
58
+
2. **DO** run the tests after adding \`provideZonelessChangeDetection\` to see which ones fail. **DO NOT** make assumptions about which tests will might fail.
59
+
3. **DO** add \`provideZoneChangeDetection()\` to the providers for each individual test or group of tests that fail after the change in Step 1.
60
+
4. **DO NOT** attempt to fix the logic of the failing tests at this stage. The goal is only to enable zoneless for the suite and isolate the incompatible tests.
61
+
5. **DO NOT** make any other changes to the test file or any application code.
62
+
6. **DO NOT** move tests around or create new describe blocks if it can be avoided. Changes are easier to review when code moves around less.
77
63
78
64
### Final Step
79
65
After you have applied all the required changes and followed all the rules, consult this tool again for the next steps in the migration process.`;
@@ -189,47 +175,26 @@ export function generateZonelessMigrationInstructionsForComponent(
consttext=`You are an expert Angular developer assisting with a migration to zoneless.
194
182
195
183
No actionable migration steps were found in the application code for \`${fileOrDirPath}\`. However, if the tests for this code are failing with zoneless enabled, the tests themselves likely need to be updated.
196
184
197
185
Your task is to investigate and fix any failing tests related to the code in \`${fileOrDirPath}\`.
198
186
199
-
### Test Debugging Guide
200
-
201
-
When running tests in a zoneless environment, you may encounter new types of failures. Here are common issues and how to resolve them:
* **Cause**: This error indicates that a value in a component's template was updated, but Angular was not notified to run change detection.
205
-
* **Solution**:
206
-
* If the value is in a test-only wrapper component, update the property to be a signal.
207
-
* For application components, either convert the property to a signal or call \`ChangeDetectorRef.markForCheck()\` immediately after the property is updated.
208
-
209
-
2. **Asynchronous Operations and Timing**:
210
-
* **Cause**: Without Zone.js, change detection is always scheduled asynchronously. Tests that previously relied on synchronous updates might now fail. The \`fixture.whenStable()\` utility also no longer waits for timers (like \`setTimeout\` or \`setInterval\`).
211
-
* **Solution**:
212
-
* Avoid relying on synchronous change detection.
213
-
* To wait for asynchronous operations to complete, you may need to poll for an expected state, use \`fakeAsync\` with \`tick()\`, or use a mock clock to flush timers.
214
-
215
-
3. **Indirect Dependencies**:
216
-
* **Cause**: The component itself might be zoneless-compatible, but it could be using a service or another dependency that is not.
217
-
* **Solution**: Investigate the services and dependencies used by the component and its tests. Run this tool on those dependencies to identify and fix any issues.
218
-
219
-
### IMPORTANT: Rules and Constraints
220
-
221
-
You must follow these rules without exception:
222
-
1. **DO** focus only on fixing the tests for the code in \`${fileOrDirPath}\`.
223
-
2. **DO** apply the solutions described in the debugging guide to fix test failures.
224
-
3. **DO NOT** make changes to application code unless it is to fix a bug revealed by the zoneless migration (e.g., converting a property to a signal to fix an \`ExpressionChangedAfterItHasBeenCheckedError\`).
225
-
4. **DO NOT** re-introduce \`provideZoneChangeDetection()\` into tests that are already using \`provideZonelessChangeDetection()\`.
@@ -255,7 +220,16 @@ export function createFixResponseForZoneTests(sourceFile: ts.SourceFile): Migrat
255
220
256
221
The following usages of \`provideZoneChangeDetection\` must be removed:
257
222
${locations.map((loc)=>`- ${loc}`).join('\n')}
223
+
${testDebuggingGuideText(sourceFile.fileName)}
258
224
225
+
### Final Step
226
+
After you have applied all the required changes and followed all the rules, consult this tool again for the next steps in the migration process.`;
227
+
228
+
returncreateResponse(text);
229
+
}
230
+
231
+
functiontestDebuggingGuideText(fileName: string){
232
+
return`
259
233
### Test Debugging Guide
260
234
261
235
After removing \`provideZoneChangeDetection\`, the tests will likely fail. Use this guide to diagnose and fix the failures.
@@ -279,15 +253,13 @@ export function createFixResponseForZoneTests(sourceFile: ts.SourceFile): Migrat
279
253
### IMPORTANT: Rules and Constraints
280
254
281
255
You must follow these rules without exception:
282
-
1. **DO** remove all usages of \`provideZoneChangeDetection\` from the test file.
283
-
2. **DO** apply the solutions described in the debugging guide to fix any resulting test failures.
284
-
3. **DO NOT** make changes to application code unless it is to fix a bug revealed by the zoneless migration (e.g., converting a property to a signal to fix an \`ExpressionChangedAfterItHasBeenCheckedError\`).
285
-
4. **DO NOT** make any changes unrelated to fixing the failing tests in \`${sourceFile.fileName}\`.
286
-
287
-
### Final Step
288
-
After you have applied all the required changes and followed all the rules, consult this tool again for the next steps in the migration process.`;
289
-
290
-
returncreateResponse(text);
256
+
1. **DO** focus only on fixing the tests for the code in \`${fileName}\`.
257
+
2. **DO** remove all usages of \`provideZoneChangeDetection\` from the test file.
258
+
3. **DO** apply the solutions described in the debugging guide to fix any resulting test failures.
259
+
4. **DO** update properties of test components and directives to use signals. Tests often use plain objects and values and update the component state directly before calling \`fixture.detectChanges\`. This will not work and will result in \`ExpressionChangedAfterItHasBeenCheckedError\` because Angular was not notifed of the change.
260
+
5. **DO NOT** make changes to application code unless it is to fix a bug revealed by the zoneless migration (e.g., converting a property to a signal to fix an \`ExpressionChangedAfterItHasBeenCheckedError\`).
261
+
6. **DO NOT** make any changes unrelated to fixing the failing tests in \`${fileName}\`.
262
+
7. **DO NOT** re-introduce \`provideZoneChangeDetection()\` into tests that are already using \`provideZonelessChangeDetection()\`.`;
0 commit comments