|
1 | 1 | import { logging } from '@angular-devkit/core'; |
2 | 2 | import { HostTree, SchematicContext } from '@angular-devkit/schematics'; |
| 3 | +import * as typescript from 'typescript'; |
3 | 4 | import { firebaseVersionRange } from '../../common.js'; |
4 | 5 | import { ngUpdate } from './index.js'; |
5 | 6 | import 'jasmine'; |
@@ -40,4 +41,45 @@ describe('migration-v21 ngUpdate', () => { |
40 | 41 | expect(addTask).not.toHaveBeenCalled(); |
41 | 42 | }); |
42 | 43 |
|
| 44 | + it('keeps the firebase alignment when the rewrite throws', () => { |
| 45 | + const logger = new logging.Logger('test'); |
| 46 | + const warn = spyOn(logger, 'warn'); |
| 47 | + const addTask = jasmine.createSpy('addTask'); |
| 48 | + const context = { logger, addTask } as unknown as SchematicContext; |
| 49 | + const tree = treeWithFirebase('^11.0.0'); |
| 50 | + tree.create('angular.json', JSON.stringify({ |
| 51 | + projects: { app: { root: '', sourceRoot: 'src' } }, |
| 52 | + })); |
| 53 | + tree.create('src/app/foo.ts', `import { getVertexAI } from '@angular/fire/vertexai';`); |
| 54 | + const throwingCompiler = { |
| 55 | + ScriptTarget: typescript.ScriptTarget, |
| 56 | + createSourceFile: () => { throw new Error('boom'); }, |
| 57 | + } as unknown as typeof typescript; |
| 58 | + |
| 59 | + ngUpdate({ compiler: throwingCompiler })(tree, context); |
| 60 | + |
| 61 | + // The rewrite failure costs only the rewrite, never the firebase alignment. |
| 62 | + const written = JSON.parse(tree.readText('package.json')); |
| 63 | + expect(written.dependencies.firebase).toBe(firebaseVersionRange); |
| 64 | + expect(addTask).toHaveBeenCalledTimes(1); |
| 65 | + expect(warn.calls.allArgs().map(callArgs => String(callArgs[0])).join('\n')) |
| 66 | + .toContain('Skipped the Vertex AI -> AI Logic source rewrite'); |
| 67 | + }); |
| 68 | + |
| 69 | + it('runs the Vertex AI rewrite and the alignment through one ngUpdate call', () => { |
| 70 | + const { context, addTask } = contextWithTaskSpy(); |
| 71 | + const tree = treeWithFirebase('^11.0.0'); |
| 72 | + tree.create('angular.json', JSON.stringify({ |
| 73 | + projects: { app: { root: '', sourceRoot: 'src' } }, |
| 74 | + })); |
| 75 | + tree.create('src/app/foo.ts', `import { getVertexAI } from '@angular/fire/vertexai';`); |
| 76 | + |
| 77 | + ngUpdate({ compiler: typescript })(tree, context); |
| 78 | + |
| 79 | + expect(tree.readText('src/app/foo.ts')).toBe(`import { getAI } from '@angular/fire/ai';`); |
| 80 | + const written = JSON.parse(tree.readText('package.json')); |
| 81 | + expect(written.dependencies.firebase).toBe(firebaseVersionRange); |
| 82 | + expect(addTask).toHaveBeenCalledTimes(1); |
| 83 | + }); |
| 84 | + |
43 | 85 | }); |
0 commit comments