fix(core): static-query migration should not prompt if no queries are used (#30254)

Currently we always prompt when the static-query migration runs. This is not
always needed because some applications do not even use `ViewChild` or
`ContentChild` queries and it just causes confusion if developers need to
decide on a migration strategy while there is nothing to migrate.

In order to avoid this confusion, we no longer prompt for a strategy
if there are no queries declared within the project.

PR Close #30254
This commit is contained in:
Paul Gschwendtner
2019-05-03 15:02:08 +02:00
committed by Alex Rickabaugh
parent 04a9f28c3d
commit 4c12d742dc
9 changed files with 147 additions and 97 deletions

View File

@ -1367,5 +1367,22 @@ describe('static-queries migration with usage strategy', () => {
expect(tree.readContent('/src/index.ts'))
.toContain(`@${queryType}('test', { static: false }) query: any;`);
});
it(`should not prompt for migration strategy if no @${queryType} query is used`, async() => {
writeFile('/index.ts', `
import {Component, ${queryType}} from '@angular/core';
@Component({template: '<span #test></span>'})
export class NoQueriesDeclared {
}
`);
const testModule = require('../migrations/static-queries/strategy_prompt');
spyOn(testModule, 'promptForMigrationStrategy').and.callThrough();
await runMigration();
expect(testModule.promptForMigrationStrategy).toHaveBeenCalledTimes(0);
});
}
});