How to use readContent method in stryker-parent

Best JavaScript code snippet using stryker-parent

static_queries_migration_usage_spec.ts

Source:static_queries_migration_usage_spec.ts Github

copy

Full Screen

...55 }56 }57 `);58 runMigration();59 expect(tree.readContent('/index.ts'))60 .toContain(`@ViewChild('test', { static: true }) query: any;`);61 });62 it('should mark view queries used in "ngAfterContentChecked" as static', () => {63 writeFile('/index.ts', `64 import {Component, ViewChild} from '@angular/core';65 66 @Component({template: '<span #test></span>'})67 export class MyComp {68 @ViewChild('test') query: any;69 70 ngAfterContentChecked() {71 this.query.classList.add('test');72 }73 }74 `);75 runMigration();76 expect(tree.readContent('/index.ts'))77 .toContain(`@ViewChild('test', { static: true }) query: any;`);78 });79 });80 describe('ContentChild', () => {81 createQueryTests('ContentChild');82 it('should not mark content queries used in "ngAfterContentInit" as static', () => {83 writeFile('/index.ts', `84 import {Component, ContentChild} from '@angular/core';85 86 @Component({template: '<span #test></span>'})87 export class MyComp {88 @ContentChild('test') query: any;89 90 ngAfterContentInit() {91 this.query.classList.add('test');92 }93 }94 `);95 runMigration();96 expect(tree.readContent('/index.ts'))97 .toContain(`@ContentChild('test', { static: false }) query: any;`);98 });99 it('should not mark content queries used in "ngAfterContentChecked" as static', () => {100 writeFile('/index.ts', `101 import {Component, ContentChild} from '@angular/core';102 103 @Component({template: '<span #test></span>'})104 export class MyComp {105 @ContentChild('test') query: any;106 107 ngAfterContentChecked() {108 this.query.classList.add('test');109 }110 }111 `);112 runMigration();113 expect(tree.readContent('/index.ts'))114 .toContain(`@ContentChild('test', { static: false }) query: any;`);115 });116 });117 function writeFile(filePath: string, contents: string) {118 host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));119 }120 function runMigration() { runner.runSchematic('migration-v8-static-queries', {}, tree); }121 function createQueryTests(queryType: 'ViewChild' | 'ContentChild') {122 it('should mark queries as dynamic', () => {123 writeFile('/index.ts', `124 import {Component, ${queryType}} from '@angular/core';125 126 @Component({template: '<span #test></span>'})127 export class MyComp {128 @${queryType}('test') unused: any;129 @${queryType}('dynamic') dynamic: any;130 131 onClick() {132 this.dynamicQuery.classList.add('test');133 }134 }135 `);136 runMigration();137 expect(tree.readContent('/index.ts'))138 .toContain(`@${queryType}('test', { static: false }) unused: any;`);139 expect(tree.readContent('/index.ts'))140 .toContain(`@${queryType}('dynamic', { static: false }) dynamic: any`);141 });142 it('should mark queries used in "ngOnChanges" as static', () => {143 writeFile('/index.ts', `144 import {Component, ${queryType}} from '@angular/core';145 146 @Component({template: '<span #test></span>'})147 export class MyComp {148 @${queryType}('test') query: any;149 150 ngOnChanges() {151 this.query.classList.add('test'); 152 }153 }154 `);155 runMigration();156 expect(tree.readContent('/index.ts'))157 .toContain(`@${queryType}('test', { static: true }) query: any;`);158 });159 it('should mark queries used in "ngOnInit" as static', () => {160 writeFile('/index.ts', `161 import {Component, ${queryType}} from '@angular/core';162 163 @Component({template: '<span #test></span>'})164 export class MyComp {165 @${queryType}('test') query: any;166 167 ngOnInit() {168 this.query.classList.add('test'); 169 }170 }171 `);172 runMigration();173 expect(tree.readContent('/index.ts'))174 .toContain(`@${queryType}('test', { static: true }) query: any;`);175 });176 it('should mark queries used in "ngDoCheck" as static', () => {177 writeFile('/index.ts', `178 import {Component, ${queryType}} from '@angular/core';179 180 @Component({template: '<span #test></span>'})181 export class MyComp {182 @${queryType}('test') query: any;183 184 ngDoCheck() {185 this.query.classList.add('test'); 186 }187 }188 `);189 runMigration();190 expect(tree.readContent('/index.ts'))191 .toContain(`@${queryType}('test', { static: true }) query: any;`);192 });193 it('should keep existing query options when updating timing', () => {194 writeFile('/index.ts', `195 import {Component, ${queryType}} from '@angular/core';196 197 @Component({template: '<span #test></span>'})198 export class MyComp {199 @${queryType}('test', { /* test */ read: null }) query: any;200 201 ngOnInit() {202 this.query.classList.add('test');203 }204 }205 `);206 runMigration();207 expect(tree.readContent('/index.ts'))208 .toContain(`@${queryType}('test', { /* test */ read: null, static: true }) query: any;`);209 });210 it('should not overwrite existing explicit query timing', () => {211 writeFile('/index.ts', `212 import {Component, ${queryType}} from '@angular/core';213 214 @Component({template: '<span #test></span>'})215 export class MyComp {216 @${queryType}('test', {static: /* untouched */ someVal}) query: any;217 }218 `);219 runMigration();220 expect(tree.readContent('/index.ts'))221 .toContain(`@${queryType}('test', {static: /* untouched */ someVal}) query: any;`);222 });223 it('should detect queries used in deep method chain', () => {224 writeFile('/index.ts', `225 import {Component, ${queryType}} from '@angular/core';226 227 @Component({template: '<span #test></span>'})228 export class MyComp {229 // We intentionally add this comma for the second parameter in order230 // to ensure that the migration does not incorrectly create an invalid231 // decorator call with three parameters. e.g. "ViewQuery('test', {...}, )"232 @${queryType}('test', ) query: any;233 234 ngOnInit() {235 this.a();236 }237 238 a() {239 this.b();240 }241 242 b() {243 this.c();244 }245 246 c() {247 console.log(this.query);248 }249 }250 `);251 runMigration();252 expect(tree.readContent('/index.ts'))253 .toContain(`@${queryType}('test', { static: true }) query: any;`);254 });255 it('should properly exit if recursive function is analyzed', () => {256 writeFile('/index.ts', `257 import {Component, ${queryType}} from '@angular/core';258 259 @Component({template: '<span #test></span>'})260 export class MyComp {261 @${queryType}('test') query: any;262 263 ngOnInit() {264 this.recursive();265 }266 267 recursive() { 268 this.recursive();269 }270 }271 `);272 runMigration();273 expect(tree.readContent('/index.ts'))274 .toContain(`@${queryType}('test', { static: false }) query: any;`);275 });276 it('should detect queries used in newly instantiated classes', () => {277 writeFile('/index.ts', `278 import {Component, ${queryType}} from '@angular/core';279 280 @Component({template: '<span #test></span>'})281 export class MyComp {282 @${queryType}('test') query: any;283 @${queryType}('test') query2: any;284 285 ngOnInit() {286 new A(this);287 288 new class Inline {289 constructor(private ctx: MyComp) {290 this.a();291 }292 293 a() {294 this.ctx.query2.useStatically();295 }296 }(this);297 }298 }299 300 export class A {301 constructor(ctx: MyComp) {302 ctx.query.test();303 }304 }305 `);306 runMigration();307 expect(tree.readContent('/index.ts'))308 .toContain(`@${queryType}('test', { static: true }) query: any;`);309 expect(tree.readContent('/index.ts'))310 .toContain(`@${queryType}('test', { static: true }) query2: any;`);311 });312 it('should detect queries used in parenthesized new expressions', () => {313 writeFile('/index.ts', `314 import {Component, ${queryType}} from '@angular/core';315 316 @Component({template: '<span #test></span>'})317 export class MyComp {318 @${queryType}('test') query: any;319 320 ngOnInit() {321 new ((A))(this);322 }323 }324 325 export class A {326 constructor(ctx: MyComp) {327 ctx.query.test();328 }329 }330 `);331 runMigration();332 expect(tree.readContent('/index.ts'))333 .toContain(`@${queryType}('test', { static: true }) query: any;`);334 });335 it('should detect queries in lifecycle hook with string literal name', () => {336 writeFile('/index.ts', `337 import {Component, ${queryType}} from '@angular/core';338 339 @Component({template: '<span #test></span>'})340 export class MyComp {341 @${queryType}('test') query: any;342 343 'ngOnInit'() {344 this.query.test();345 }346 }347 `);348 runMigration();349 expect(tree.readContent('/index.ts'))350 .toContain(`@${queryType}('test', { static: true }) query: any;`);351 });352 it('should detect static queries within nested inheritance', () => {353 writeFile('/index.ts', `354 import {Component, ${queryType}} from '@angular/core';355 356 @Component({template: '<span #test></span>'})357 export class MyComp {358 @${queryType}('test') query: any;359 }360 361 export class A extends MyComp {}362 export class B extends A {363 364 ngOnInit() {365 this.query.testFn();366 }367 368 }369 `);370 runMigration();371 expect(tree.readContent('/index.ts'))372 .toContain(`@${queryType}('test', { static: true }) query: any;`);373 });374 it('should detect static queries used within input setters', () => {375 writeFile('/index.ts', `376 import {Component, Input, ${queryType}} from '@angular/core';377 378 @Component({template: '<span #test></span>'})379 export class MyComp {380 @${queryType}('test') query: any;381 382 @Input()383 get myVal() { return null; }384 set myVal(newVal: any) {385 this.query.classList.add('setter');386 }387 }388 `);389 runMigration();390 expect(tree.readContent('/index.ts'))391 .toContain(`@${queryType}('test', { static: true }) query: any;`);392 });393 it('should detect inputs defined in metadata', () => {394 writeFile('/index.ts', `395 import {Component, ${queryType}} from '@angular/core';396 397 @Component({398 template: '<span #test></span>',399 inputs: ["myVal"],400 })401 export class MyComp {402 @${queryType}('test') query: any;403 404 // We don't use the input decorator here as we want to verify405 // that it properly detects the input through the component metadata.406 get myVal() { return null; }407 set myVal(newVal: any) {408 this.query.classList.add('setter');409 }410 }411 `);412 runMigration();413 expect(tree.readContent('/index.ts'))414 .toContain(`@${queryType}('test', { static: true }) query: any;`);415 });416 it('should detect aliased inputs declared in metadata', () => {417 writeFile('/index.ts', `418 import {Component, ${queryType}} from '@angular/core';419 420 @Component({421 template: '<span #test></span>',422 inputs: ['prop: publicName'],423 })424 export class MyComp {425 @${queryType}('test') query: any;426 427 set prop(val: any) {428 this.query.test();429 }430 }431 `);432 runMigration();433 expect(tree.readContent('/index.ts'))434 .toContain(`@${queryType}('test', { static: true }) query: any;`);435 });436 it('should not mark query as static if query is used in non-input setter', () => {437 writeFile('/index.ts', `438 import {Component, ${queryType}} from '@angular/core';439 440 @Component({template: '<span #test></span>'})441 export class MyComp {442 @${queryType}('test') query: any;443 444 set myProperty(val: any) {445 this.query.test();446 }447 }448 `);449 runMigration();450 expect(tree.readContent('/index.ts'))451 .toContain(`@${queryType}('test', { static: false }) query: any;`);452 });453 it('should detect input decorator on setter', () => {454 writeFile('/index.ts', `455 import {Input, Component, ${queryType}} from '@angular/core';456 457 @Component({template: '<span #test></span>'})458 export class MyComp {459 @${queryType}('test') query: any;460 461 get myProperty() { return null; }462 463 // Usually the decorator is set on the get accessor, but it's also possible464 // to declare the input on the setter. This ensures that it is handled properly.465 @Input()466 set myProperty(val: any) {467 this.query.test();468 }469 }470 `);471 runMigration();472 expect(tree.readContent('/index.ts'))473 .toContain(`@${queryType}('test', { static: true }) query: any;`);474 });475 it('should detect setter inputs in derived classes', () => {476 writeFile('/index.ts', `477 import {Component, ${queryType}} from '@angular/core';478 479 @Component({480 template: '<span #test></span>',481 inputs: ['childSetter'],482 })483 export class MyComp {484 protected @${queryType}('test') query: any;485 }486 487 export class B extends MyComp {488 set childSetter(newVal: any) {489 this.query.test();490 }491 }492 `);493 runMigration();494 expect(tree.readContent('/index.ts'))495 .toContain(`@${queryType}('test', { static: true }) query: any;`);496 });497 it('should properly detect static query in external derived class', () => {498 writeFile('/src/index.ts', `499 import {Component, ${queryType}} from '@angular/core';500 501 @Component({template: '<span #test></span>'})502 export class MyComp {503 @${queryType}('test') query: any;504 }505 `);506 writeFile('/src/external.ts', `507 import {MyComp} from './index';508 509 export class ExternalComp extends MyComp {510 ngOnInit() {511 this.query.test();512 }513 }514 `);515 // Move the tsconfig into a subdirectory. This ensures that the update is properly516 // recorded for TypeScript projects not at the schematic tree root.517 host.sync.rename(normalize('/tsconfig.json'), normalize('/src/tsconfig.json'));518 runMigration();519 expect(tree.readContent('/src/index.ts'))520 .toContain(`@${queryType}('test', { static: true }) query: any;`);521 });522 it('should not mark queries used in promises as static', () => {523 writeFile('/index.ts', `524 import {Component, ${queryType}} from '@angular/core';525 526 @Component({template: '<span #test></span>'})527 export class MyComp {528 private @${queryType}('test') query: any;529 private @${queryType}('test') query2: any;530 531 ngOnInit() {532 const a = Promise.resolve();533 534 Promise.resolve().then(() => {535 this.query.doSomething();536 });537 538 Promise.reject().catch(() => {539 this.query.doSomething();540 });541 542 a.then(() => {}).then(() => {543 this.query.doSomething();544 });545 546 Promise.resolve().then(this.createPromiseCb());547 }548 549 createPromiseCb() {550 this.query2.doSomething();551 return () => { /* empty callback */}552 }553 }554 `);555 runMigration();556 expect(tree.readContent('/index.ts'))557 .toContain(`@${queryType}('test', { static: false }) query: any;`);558 expect(tree.readContent('/index.ts'))559 .toContain(`@${queryType}('test', { static: true }) query2: any;`);560 });561 it('should handle function callbacks which statically access queries', () => {562 writeFile('/index.ts', `563 import {Component, ${queryType}} from '@angular/core';564 565 @Component({template: '<span #test></span>'})566 export class MyComp {567 private @${queryType}('test') query: any;568 569 ngOnInit() { 570 this.callSync(() => this.query.doSomething());571 }572 573 callSync(cb: Function) {574 this.callSync2(cb);575 }576 577 callSync2(cb: Function) {578 cb();579 }580 }581 `);582 runMigration();583 expect(tree.readContent('/index.ts'))584 .toContain(`@${queryType}('test', { static: true }) query: any;`);585 });586 it('should handle class instantiations with specified callbacks that access queries', () => {587 writeFile('/index.ts', `588 import {Component, ${queryType}} from '@angular/core';589 import {External} from './external';590 591 @Component({template: '<span #test></span>'})592 export class MyComp {593 private @${queryType}('test') query: any;594 595 ngOnInit() { 596 new External(() => this.query.doSomething());597 }598 }599 `);600 writeFile('/external.ts', `601 export class External {602 constructor(cb: () => void) {603 // Add extra parentheses to ensure that expression is unwrapped. 604 ((cb))();605 }606 }607 `);608 runMigration();609 expect(tree.readContent('/index.ts'))610 .toContain(`@${queryType}('test', { static: true }) query: any;`);611 });612 it('should handle nested functions with arguments from parent closure', () => {613 writeFile('/index.ts', `614 import {Component, ${queryType}} from '@angular/core';615 616 @Component({template: '<span #test></span>'})617 export class MyComp {618 private @${queryType}('test') query: any;619 620 ngOnInit() { 621 this.callSync(() => this.query.doSomething());622 }623 624 callSync(cb: Function) {625 function callSyncNested() {626 // The "cb" identifier comes from the "callSync" function.627 cb();628 }629 630 callSyncNested();631 }632 }633 `);634 runMigration();635 expect(tree.readContent('/index.ts'))636 .toContain(`@${queryType}('test', { static: true }) query: any;`);637 });638 it('should not mark queries used in setTimeout as static', () => {639 writeFile('/index.ts', `640 import {Component, ${queryType}} from '@angular/core';641 642 @Component({template: '<span #test></span>'})643 export class MyComp {644 private @${queryType}('test') query: any;645 private @${queryType}('test') query2: any;646 private @${queryType}('test') query3: any;647 648 ngOnInit() {649 setTimeout(function() {650 this.query.doSomething();651 });652 653 setTimeout(createCallback(this));654 }655 }656 657 function createCallback(instance: MyComp) {658 instance.query2.doSomething();659 return () => instance.query3.doSomething();660 }661 `);662 runMigration();663 expect(tree.readContent('/index.ts'))664 .toContain(`@${queryType}('test', { static: false }) query: any;`);665 expect(tree.readContent('/index.ts'))666 .toContain(`@${queryType}('test', { static: true }) query2: any;`);667 expect(tree.readContent('/index.ts'))668 .toContain(`@${queryType}('test', { static: false }) query3: any;`);669 });670 it('should not mark queries used in "addEventListener" as static', () => {671 writeFile('/index.ts', `672 import {Component, ElementRef, ${queryType}} from '@angular/core';673 674 @Component({template: '<span #test></span>'})675 export class MyComp {676 private @${queryType}('test') query: any;677 678 constructor(private elementRef: ElementRef) {}679 680 ngOnInit() {681 this.elementRef.addEventListener(() => {682 this.query.classList.add('test');683 });684 }685 }686 `);687 runMigration();688 expect(tree.readContent('/index.ts'))689 .toContain(`@${queryType}('test', { static: false }) query: any;`);690 });691 it('should not mark queries used in "requestAnimationFrame" as static', () => {692 writeFile('/index.ts', `693 import {Component, ElementRef, ${queryType}} from '@angular/core';694 695 @Component({template: '<span #test></span>'})696 export class MyComp {697 private @${queryType}('test') query: any;698 699 constructor(private elementRef: ElementRef) {}700 701 ngOnInit() {702 requestAnimationFrame(() => {703 this.query.classList.add('test');704 });705 }706 }707 `);708 runMigration();709 expect(tree.readContent('/index.ts'))710 .toContain(`@${queryType}('test', { static: false }) query: any;`);711 });712 it('should mark queries used in immediately-invoked function expression as static', () => {713 writeFile('/index.ts', `714 import {Component, ${queryType}} from '@angular/core';715 716 @Component({template: '<span #test></span>'})717 export class MyComp {718 private @${queryType}('test') query: any;719 private @${queryType}('test') query2: any;720 721 ngOnInit() {722 (() => {723 this.query.usedStatically();724 })();725 726 (function(ctx) {727 ctx.query2.useStatically();728 })(this);729 }730 }731 `);732 runMigration();733 expect(tree.readContent('/index.ts'))734 .toContain(`@${queryType}('test', { static: true }) query: any;`);735 expect(tree.readContent('/index.ts'))736 .toContain(`@${queryType}('test', { static: true }) query2: any;`);737 });738 it('should detect static queries used in external function-like declaration', () => {739 writeFile('/index.ts', `740 import {Component, ${queryType}} from '@angular/core';741 import {externalFn} from './external';742 743 @Component({template: '<span #test></span>'})744 export class MyComp {745 private @${queryType}('test') query: any;746 747 ngOnInit() {748 externalFn(this);749 }750 }751 `);752 writeFile('/external.ts', `753 import {MyComp} from './index';754 755 export function externalFn(ctx: MyComp) {756 ctx.query.usedStatically();757 }758 `);759 runMigration();760 expect(tree.readContent('/index.ts'))761 .toContain(`@${queryType}('test', { static: true }) query: any;`);762 });763 it('should detect static queries used through getter property access', () => {764 writeFile('/index.ts', `765 import {Component, ${queryType}} from '@angular/core';766 767 @Component({template: '<span #test></span>'})768 export class MyComp {769 private @${queryType}('test') query: any;770 771 get myProp() {772 return this.query.myValue;773 }774 775 ngOnInit() {776 this.myProp.test();777 }778 }779 `);780 runMigration();781 expect(tree.readContent('/index.ts'))782 .toContain(`@${queryType}('test', { static: true }) query: any;`);783 });784 it('should detect static queries used through external getter access', () => {785 writeFile('/index.ts', `786 import {Component, ${queryType}} from '@angular/core';787 import {External} from './external';788 789 @Component({template: '<span #test></span>'})790 export class MyComp {791 @${queryType}('test') query: any;792 793 private external = new External(this);794 795 get myProp() {796 return this.query.myValue;797 }798 799 ngOnInit() {800 console.log(this.external.query);801 }802 }803 `);804 writeFile('/external.ts', `805 import {MyComp} from './index';806 807 export class External {808 constructor(private comp: MyComp) {}809 810 set query() { /** noop */ }811 get query() { return this.comp.query; }812 }813 `);814 runMigration();815 expect(tree.readContent('/index.ts'))816 .toContain(`@${queryType}('test', { static: true }) query: any;`);817 });818 it('should not mark queries as static if a value is assigned to accessor property', () => {819 writeFile('/index.ts', `820 import {Component, ${queryType}} from '@angular/core';821 822 @Component({template: '<span #test></span>'})823 export class MyComp {824 private @${queryType}('test') query: any;825 826 set myProp(value: any) { /* noop */}827 get myProp() {828 return this.query.myValue;829 }830 831 ngOnInit() {832 this.myProp = true;833 }834 }835 `);836 runMigration();837 expect(tree.readContent('/index.ts'))838 .toContain(`@${queryType}('test', { static: false }) query: any;`);839 });840 it('should mark queries as static if non-input setter uses query', () => {841 writeFile('/index.ts', `842 import {Component, ${queryType}} from '@angular/core';843 844 @Component({template: '<span #test></span>'})845 export class MyComp {846 private @${queryType}('test') query: any;847 848 get myProp() { return null; }849 set myProp(value: any) {850 this.query.doSomething();851 }852 853 ngOnInit() {854 this.myProp = 'newValue';855 }856 }857 `);858 runMigration();859 expect(tree.readContent('/index.ts'))860 .toContain(`@${queryType}('test', { static: true }) query: any;`);861 });862 it('should check setter and getter when using compound assignment', () => {863 writeFile('/index.ts', `864 import {Component, ${queryType}} from '@angular/core';865 866 @Component({template: '<span #test></span>'})867 export class MyComp {868 private @${queryType}('test') query: any;869 private @${queryType}('test') query2: any;870 871 get myProp() { return this.query2 }872 set myProp(value: any) {873 this.query.doSomething();874 }875 876 ngOnInit() {877 this.myProp *= 5;878 }879 }880 `);881 runMigration();882 expect(tree.readContent('/index.ts'))883 .toContain(`@${queryType}('test', { static: true }) query: any;`);884 expect(tree.readContent('/index.ts'))885 .toContain(`@${queryType}('test', { static: true }) query2: any;`);886 });887 it('should check getters when using comparison operator in binary expression', () => {888 writeFile('/index.ts', `889 import {Component, ${queryType}} from '@angular/core';890 891 @Component({template: '<span #test></span>'})892 export class MyComp {893 private @${queryType}('test') query: any;894 895 get myProp() { return this.query }896 set myProp(value: any) { /* noop */ }897 898 ngOnInit() {899 if (this.myProp === 3) {900 // noop901 }902 }903 }904 `);905 runMigration();906 expect(tree.readContent('/index.ts'))907 .toContain(`@${queryType}('test', { static: true }) query: any;`);908 });909 it('should check derived abstract class methods', () => {910 writeFile('/index.ts', `911 import {Component, ${queryType}} from '@angular/core';912 913 export abstract class RootBaseClass {914 abstract getQuery(): any;915 916 ngOnInit() {917 this.getQuery().doSomething();918 }919 }920 921 export abstract class BaseClass extends RootBaseClass {922 abstract getQuery2(): any;923 924 getQuery() {925 this.getQuery2();926 }927 }928 929 @Component({template: '<span #test></span>'})930 export class Subclass extends BaseClass {931 @${queryType}('test') query: any;932 933 getQuery2(): any {934 return this.query; 935 }936 }937 `);938 runMigration();939 expect(tree.readContent('/index.ts'))940 .toContain(`@${queryType}('test', { static: true }) query: any;`);941 });942 it('should detect queries accessed through deep abstract class method', () => {943 writeFile('/index.ts', `944 import {Component, ${queryType}} from '@angular/core';945 946 export abstract class RootBaseClass {947 abstract getQuery(): any;948 949 ngOnInit() {950 this.getQuery().doSomething();951 }952 }953 954 export abstract class BaseClass extends RootBaseClass {955 /* additional layer of indirection */956 }957 958 @Component({template: '<span #test></span>'})959 export class Subclass extends BaseClass {960 @${queryType}('test') query: any;961 962 getQuery(): any {963 return this.query; 964 }965 }966 `);967 runMigration();968 expect(tree.readContent('/index.ts'))969 .toContain(`@${queryType}('test', { static: true }) query: any;`);970 });971 it('should detect queries accessed through abstract property getter', () => {972 writeFile('/index.ts', `973 import {Component, ${queryType}} from '@angular/core';974 975 export abstract class BaseClass {976 abstract myQuery: any;977 978 ngOnInit() {979 this.myQuery.doSomething();980 }981 }982 983 @Component({template: '<span #test></span>'})984 export class Subclass extends BaseClass {985 @${queryType}('test') query: any;986 987 get myQuery() { return this.query; }988 }989 `);990 runMigration();991 expect(tree.readContent('/index.ts'))992 .toContain(`@${queryType}('test', { static: true }) query: any;`);993 });994 it('should detect queries accessed through abstract property setter', () => {995 writeFile('/index.ts', `996 import {Component, ${queryType}} from '@angular/core';997 998 export abstract class BaseClass {999 abstract myQuery: any;1000 1001 ngOnInit() {1002 this.myQuery = "trigger";1003 }1004 }1005 1006 @Component({template: '<span #test></span>'})1007 export class Subclass extends BaseClass {1008 @${queryType}('test') query: any;1009 1010 set myQuery(val: any) { this.query.doSomething() }1011 get myQuery() { /* noop */ }1012 }1013 `);1014 runMigration();1015 expect(tree.readContent('/index.ts'))1016 .toContain(`@${queryType}('test', { static: true }) query: any;`);1017 });1018 it('should detect query usage in abstract class methods accessing inherited query', () => {1019 writeFile('/index.ts', `1020 import {Component, ${queryType}} from '@angular/core';1021 1022 export abstract class RootBaseClass {1023 abstract getQuery(): any;1024 1025 ngOnInit() {1026 this.getQuery().doSomething();1027 }1028 }1029 1030 export abstract class BaseClass extends RootBaseClass {1031 @${queryType}('test') query: any;1032 abstract getQuery2(): any;1033 1034 getQuery() {1035 this.getQuery2();1036 }1037 }1038 1039 @Component({template: '<span #test></span>'})1040 export class Subclass extends BaseClass {1041 1042 getQuery2(): any {1043 return this.query;1044 }1045 }1046 `);1047 runMigration();1048 expect(tree.readContent('/index.ts'))1049 .toContain(`@${queryType}('test', { static: true }) query: any;`);1050 });1051 it('should detect query usage within component template', () => {1052 writeFile('/index.ts', `1053 import {Component, ${queryType}} from '@angular/core';1054 1055 @Component({templateUrl: 'my-template.html'})1056 export class MyComponent {1057 @${queryType}('test') query: any;1058 }1059 `);1060 writeFile(`/my-template.html`, `1061 <foo #test></foo>1062 <comp [dir]="query"></comp>1063 `);1064 runMigration();1065 expect(tree.readContent('/index.ts'))1066 .toContain(`@${queryType}('test', { static: true }) query: any;`);1067 });1068 it('should detect query usage with nested property read within component template', () => {1069 writeFile('/index.ts', `1070 import {Component, ${queryType}} from '@angular/core';1071 1072 @Component({templateUrl: 'my-template.html'})1073 export class MyComponent {1074 @${queryType}('test') query: any;1075 }1076 `);1077 writeFile(`/my-template.html`, `1078 <foo #test></foo>1079 <comp [dir]="query.someProperty"></comp>1080 `);1081 runMigration();1082 expect(tree.readContent('/index.ts'))1083 .toContain(`@${queryType}('test', { static: true }) query: any;`);1084 });1085 it('should not mark query as static if template has template reference with same name', () => {1086 writeFile('/index.ts', `1087 import {Component, ${queryType}} from '@angular/core';1088 1089 @Component({templateUrl: 'my-template.html'})1090 export class MyComponent {1091 @${queryType}('test') query: any;1092 }1093 `);1094 writeFile(`/my-template.html`, `1095 <foo #test></foo>1096 <same-name #query></same-name>1097 <!-- In that case the "query" from the component cannot be referenced. -->1098 <comp [dir]="query"></comp>1099 `);1100 runMigration();1101 expect(tree.readContent('/index.ts'))1102 .toContain(`@${queryType}('test', { static: false }) query: any;`);1103 });1104 it('should not mark query as static if template has property read with query name but different receiver',1105 () => {1106 writeFile('/index.ts', `1107 import {Component, ${queryType}} from '@angular/core';1108 1109 @Component({templateUrl: 'my-template.html'})1110 export class MyComponent {1111 myObject: {someProp: any};1112 @${queryType}('test') someProp: any;1113 }1114 `);1115 // This test ensures that we don't accidentally treat template property reads1116 // which do not refer to the query of the component instance, but have the same1117 // "render3Ast.PropertyRead" name, as references to the query declaration.1118 writeFile(`/my-template.html`, `1119 <foo #test></foo>1120 <comp [dir]="myObject.someProp"></comp>1121 `);1122 runMigration();1123 expect(tree.readContent('/index.ts'))1124 .toContain(`@${queryType}('test', { static: false }) someProp: any;`);1125 });1126 it('should ignore queries accessed within <ng-template> element', () => {1127 writeFile('/index.ts', `1128 import {Component, ${queryType}} from '@angular/core';1129 1130 @Component({templateUrl: 'my-template.html'})1131 export class MyComponent {1132 @${queryType}('test') query: any;1133 }1134 `);1135 writeFile(`/my-template.html`, `1136 <foo #test></foo>1137 1138 <ng-template>1139 <my-comp [myInput]="query"></my-comp>1140 </ng-template>1141 `);1142 runMigration();1143 expect(tree.readContent('/index.ts'))1144 .toContain(`@${queryType}('test', { static: false }) query: any;`);1145 });1146 it('should detect inherited queries used in templates', () => {1147 writeFile('/index.ts', `1148 import {Component, ${queryType}} from '@angular/core';1149 1150 export class ParentClass {1151 @${queryType}('test') query: any;1152 }1153 1154 @Component({templateUrl: 'my-template.html'})1155 export class MyComponent extends ParentClass {}1156 `);1157 writeFile(`/my-template.html`, `1158 <foo #test></foo>1159 <my-comp [myInput]="query"></my-comp>1160 `);1161 runMigration();1162 expect(tree.readContent('/index.ts'))1163 .toContain(`@${queryType}('test', { static: true }) query: any;`);1164 });1165 it('should properly handle multiple tsconfig files', () => {1166 writeFile('/src/index.ts', `1167 import {Component, ${queryType}} from '@angular/core';1168 1169 @Component({template: '<span #test></span>'})1170 export class MyComp {1171 private @${queryType}('test') query: any;1172 }1173 `);1174 writeFile('/src/tsconfig.json', JSON.stringify({1175 compilerOptions: {1176 lib: ['es2015'],1177 }1178 }));1179 // The migration runs for "/tsconfig.json" and "/src/tsconfig.json" which both1180 // contain the "src/index.ts" file. This test ensures that we don't incorrectly1181 // apply the code transformation multiple times with outdated offsets.1182 runMigration();1183 expect(tree.readContent('/src/index.ts'))1184 .toContain(`@${queryType}('test', { static: false }) query: any;`);1185 });1186 }...

Full Screen

Full Screen

missing_injectable_migration_spec.ts

Source:missing_injectable_migration_spec.ts Github

copy

Full Screen

...74 export class TestClass {}75 `);76 await runMigration();77 expect(warnOutput.length).toBe(0);78 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class MyService/);79 expect(tree.readContent('/index.ts'))80 .toMatch(/@Injectable\(\)\s+export class MySecondService/);81 expect(tree.readContent('/index.ts'))82 .toContain(`{ Component, Injectable } from '@angular/core`);83 });84 });85 function createTests(86 type: 'NgModule'|'Directive'|'Component', propName: 'providers'|'viewProviders') {87 it(`should migrate type provider in ${type}`, async () => {88 writeFile('/index.ts', `89 import {${type}} from '@angular/core';90 export class MyService {}91 @${type}({${propName}: [MyService]})92 export class TestClass {}93 `);94 await runMigration();95 expect(warnOutput.length).toBe(0);96 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class MyService/);97 expect(tree.readContent('/index.ts'))98 .toContain(`{ ${type}, Injectable } from '@angular/core`);99 });100 it(`should migrate object literal provider in ${type} to explicit value provider`, async () => {101 writeFile('/index.ts', `102 import {${type}} from '@angular/core';103 export class MyService {}104 @${type}({${propName}: [{provide: MyService}]})105 export class TestClass {}106 `);107 await runMigration();108 expect(warnOutput.length).toBe(0);109 expect(tree.readContent('/index.ts')).toMatch(/@angular\/core';\s+export class MyService/);110 expect(tree.readContent('/index.ts'))111 .toContain(`${propName}: [{ provide: MyService, useValue: undefined }]`);112 expect(tree.readContent('/index.ts')).toContain(`{${type}} from '@angular/core`);113 });114 it(`should migrate object literal provider with forwardRef in ${type}`, async () => {115 writeFile('/index.ts', `116 import {${type}, forwardRef} from '@angular/core';117 @${type}({${propName}: [forwardRef(() => MyService)]})118 export class TestClass {}119 export class MyService {}120 `);121 await runMigration();122 expect(warnOutput.length).toBe(0);123 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class MyService/);124 expect(tree.readContent('/index.ts'))125 .toContain(`{ ${type}, forwardRef, Injectable } from '@angular/core`);126 });127 it(`should not migrate object literal provider with "useValue" in ${type}`, async () => {128 writeFile('/index.ts', `129 import {${type}} from '@angular/core';130 export class MyService {}131 @${type}({${propName}: [{provide: MyService, useValue: null }]})132 export class TestClass {}133 `);134 await runMigration();135 expect(warnOutput.length).toBe(0);136 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');137 });138 it(`should not migrate provider with "useClass" and "deps" in ${type}`, async () => {139 writeFile('/index.ts', `140 import {${type}} from '@angular/core';141 export class MyService {}142 @${type}({${propName}: [{provide: MyService, deps: []}]})143 export class TestClass {}144 `);145 await runMigration();146 expect(warnOutput.length).toBe(0);147 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');148 });149 it(`should not migrate object literal provider with "useFactory" in ${type}`, async () => {150 writeFile('/index.ts', `151 import {${type}} from '@angular/core';152 export class MyService {}153 @${type}({${propName}: [{provide: MyService, useFactory: () => null }]})154 export class TestClass {}155 `);156 await runMigration();157 expect(warnOutput.length).toBe(0);158 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');159 });160 it(`should not migrate object literal provider with "useExisting" in ${type}`, async () => {161 writeFile('/index.ts', `162 import {${type}} from '@angular/core';163 export class MyService {}164 export class MyToken {}165 @${type}({${propName}: [166 {provide: MyService: useValue: null},167 {provide: MyToken, useExisting: MyService},168 ]})169 export class TestClass {}170 `);171 await runMigration();172 expect(warnOutput.length).toBe(0);173 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');174 });175 it(`should migrate object literal provider with "useClass" in ${type}`, async () => {176 writeFile('/index.ts', `177 import {${type}} from '@angular/core';178 export class MyService {}179 export class MyToken {}180 @${type}({${propName}: [{provide: MyToken, useClass: MyService}]})181 export class TestClass {}182 `);183 await runMigration();184 expect(warnOutput.length).toBe(0);185 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class MyService/);186 expect(tree.readContent('/index.ts')).toMatch(/MyService {}\s+export class MyToken/);187 expect(tree.readContent('/index.ts'))188 .toContain(`{ ${type}, Injectable } from '@angular/core`);189 });190 it(`should not migrate references for providers with "useExisting" in ${type}, but migrate ` +191 `existing token if declared in other ${type}`,192 async () => {193 writeFile('/index.ts', `194 import {${type}} from '@angular/core';195 export class MyService {}196 export class MyToken {}197 @${type}({198 ${propName}: [199 {provide: MyToken, useExisting: MyService},200 ],201 })202 export class TestClass {}203 `);204 writeFile('/other.ts', `205 import {${type} from '@angular/core';206 import {MyService} from './index';207 export @${type}({208 ${propName}: [{provide: MyService, useClass: MyService}],209 })210 export class OtherClass {}211 `);212 await runMigration();213 expect(warnOutput.length).toBe(0);214 expect(tree.readContent('/index.ts'))215 .toMatch(/@angular\/core';\s+@Injectable\(\)\s+export class MyService/);216 expect(tree.readContent('/index.ts')).toMatch(/MyService {}\s+export class MyToken/);217 });218 it('should not migrate provider which is already decorated with @Injectable', async () => {219 writeFile('/index.ts', `220 import {Injectable, ${type}} from '@angular/core';221 @Injectable()222 export class MyService {}223 @${type}({${propName}: [MyService]})224 export class TestClass {}225 `);226 await runMigration();227 expect(warnOutput.length).toBe(0);228 expect(tree.readContent('/index.ts'))229 .toMatch(/@angular\/core';\s+@Injectable\(\)\s+export class MyService/);230 });231 it('should not migrate provider which is already decorated with @Directive', async () => {232 writeFile('/index.ts', `233 import {Directive, ${type}} from '@angular/core';234 @Directive()235 export class MyService {}236 @${type}({${propName}: [MyService]})237 export class TestClass {}238 `);239 await runMigration();240 expect(warnOutput.length).toBe(0);241 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');242 });243 it('should not migrate provider which is already decorated with @Component', async () => {244 writeFile('/index.ts', `245 import {Component, ${type}} from '@angular/core';246 @Component()247 export class MyService {}248 @${type}({${propName}: [MyService]})249 export class TestClass {}250 `);251 await runMigration();252 expect(warnOutput.length).toBe(0);253 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');254 });255 it('should not migrate provider which is already decorated with @Pipe', async () => {256 writeFile('/index.ts', `257 import {Pipe, ${type}} from '@angular/core';258 @Pipe()259 export class MyService {}260 @${type}({${propName}: [MyService]})261 export class TestClass {}262 `);263 await runMigration();264 expect(warnOutput.length).toBe(0);265 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');266 });267 it('should not migrate provider which is already decorated with @NgModule', async () => {268 const importedSymbols = type !== 'NgModule' ? ['NgModule', type] : ['NgModule'];269 writeFile('/index.ts', `270 import {${importedSymbols.join(', ')}} from '@angular/core';271 @NgModule()272 export class MyOtherModule {}273 @${type}({${propName}: [MyOtherModule]})274 export class TestClass {}275 `);276 await runMigration();277 expect(warnOutput.length).toBe(0);278 expect(tree.readContent('/index.ts')).not.toContain('@Injectable');279 });280 it(`should migrate multiple providers in same ${type}`, async () => {281 writeFile('/index.ts', `282 import {${type}} from '@angular/core';283 export class ServiceA {}284 export class ServiceB {}285 @${type}({${propName}: [ServiceA, ServiceB]})286 export class TestClass {}287 `);288 await runMigration();289 expect(warnOutput.length).toBe(0);290 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceA/);291 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceB/);292 expect(tree.readContent('/index.ts'))293 .toContain(`{ ${type}, Injectable } from '@angular/core`);294 });295 it(`should migrate multiple mixed providers in same ${type}`, async () => {296 writeFile('/index.ts', `297 import {${type}} from '@angular/core';298 export class ServiceA {}299 export class ServiceB {}300 export class ServiceC {}301 @${type}({302 ${propName}: [303 ServiceA,304 {provide: ServiceB},305 {provide: SomeToken, useClass: ServiceC},306 ]})307 export class TestClass {}308 `);309 await runMigration();310 expect(warnOutput.length).toBe(0);311 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceA/);312 expect(tree.readContent('/index.ts')).toMatch(/ServiceA {}\s+export class ServiceB/);313 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceC/);314 expect(tree.readContent('/index.ts'))315 .toContain(`{ ${type}, Injectable } from '@angular/core`);316 expect(tree.readContent('/index.ts'))317 .toContain(`{ provide: ServiceB, useValue: undefined },`);318 });319 it(`should migrate multiple nested providers in same ${type}`, async () => {320 writeFile('/index.ts', `321 import {${type}} from '@angular/core';322 export class ServiceA {}323 export class ServiceB {}324 export class ServiceC {}325 export class ServiceD {}326 @${type}({327 ${propName}: [328 ServiceA,329 [330 {provide: ServiceB, useClass: ServiceB},331 ServiceC,332 {provide: ServiceD},333 ],334 ]})335 export class TestClass {}336 `);337 await runMigration();338 expect(warnOutput.length).toBe(0);339 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceA/);340 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceB/);341 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceC/);342 expect(tree.readContent('/index.ts')).toMatch(/ServiceC {}\s+export class ServiceD/);343 expect(tree.readContent('/index.ts'))344 .toContain(`{ ${type}, Injectable } from '@angular/core`);345 expect(tree.readContent('/index.ts'))346 .toContain(`{ provide: ServiceD, useValue: undefined },`);347 });348 it('should migrate providers referenced through identifier', async () => {349 writeFile('/index.ts', `350 import {${type}} from '@angular/core';351 export class ServiceA {}352 export class ServiceB {}353 export class ServiceC {}354 const PROVIDERS = [355 ServiceA,356 ServiceB,357 // trailing comma is by intention to check if do not create358 // an invalid object literal.359 {provide: ServiceC, },360 ];361 @${type}({362 ${propName}: PROVIDERS,363 })364 export class TestClass {}365 `);366 await runMigration();367 expect(warnOutput.length).toBe(0);368 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceA/);369 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceB/);370 expect(tree.readContent('/index.ts')).toMatch(/ServiceB {}\s+export class ServiceC/);371 expect(tree.readContent('/index.ts'))372 .toContain(`{ ${type}, Injectable } from '@angular/core`);373 expect(tree.readContent('/index.ts'))374 .toContain(`{ provide: ServiceC, useValue: undefined },`);375 });376 it('should migrate providers created through static analyzable function call', async () => {377 writeFile('/index.ts', `378 import {${type}} from '@angular/core';379 export class ServiceA {}380 export class ServiceB {}381 export class ServiceC {}382 export function createProviders(x: any, b: any) {383 return [ServiceA, x, b]384 }385 @${type}({386 ${propName}: createProviders(ServiceB, {provide: ServiceC}),387 })388 export class TestClass {}389 `);390 await runMigration();391 expect(warnOutput.length).toBe(0);392 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceA/);393 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceB/);394 expect(tree.readContent('/index.ts')).toMatch(/ServiceB {}\s+export class ServiceC/);395 expect(tree.readContent('/index.ts'))396 .toContain(`{ ${type}, Injectable } from '@angular/core`);397 expect(tree.readContent('/index.ts'))398 .toContain(`ServiceB, { provide: ServiceC, useValue: undefined }),`);399 });400 it('should migrate providers which are computed through spread operator', async () => {401 writeFile('/index.ts', `402 import {${type}} from '@angular/core';403 export class ServiceA {}404 export class ServiceB {}405 export class ServiceC {}406 const otherServices = [ServiceB, {provide: ServiceC}];407 @${type}({408 ${propName}: [ServiceA, ...otherServices],409 })410 export class TestClass {}411 `);412 await runMigration();413 expect(warnOutput.length).toBe(0);414 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceA/);415 expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\s+export class ServiceB/);416 expect(tree.readContent('/index.ts')).toMatch(/ServiceB {}\s+export class ServiceC/);417 expect(tree.readContent('/index.ts'))418 .toContain(`{ ${type}, Injectable } from '@angular/core`);419 expect(tree.readContent('/index.ts'))420 .toContain(`ServiceB, { provide: ServiceC, useValue: undefined }];`);421 });422 it(`should migrate provider once if referenced in multiple ${type} definitions`, async () => {423 writeFile('/index.ts', `424 import {${type}} from '@angular/core';425 export class ServiceA {}426 @${type}({${propName}: [ServiceA]})427 export class TestClassA {}428 `);429 writeFile('/second.ts', `430 import {${type}} from '@angular/core';431 import {ServiceA} from './index';432 export class ServiceB {}433 @${type}({${propName}: [ServiceA, ServiceB]})434 export class TestClassB {}435 `);436 await runMigration();437 expect(warnOutput.length).toBe(0);438 expect(tree.readContent('/index.ts'))439 .toMatch(/@angular\/core';\s+@Injectable\(\)\s+export class ServiceA/);440 expect(tree.readContent('/index.ts'))441 .toContain(`{ ${type}, Injectable } from '@angular/core`);442 expect(tree.readContent('/second.ts')).toMatch(/@Injectable\(\)\s+export class ServiceB/);443 expect(tree.readContent('/second.ts'))444 .toContain(`{ ${type}, Injectable } from '@angular/core`);445 });446 it(`should only migrate empty object provider literal once if referenced multiple times ` +447 `in ${type} definitions`,448 async () => {449 writeFile('/provider.ts', `450 export class MyService {}451 export const PROVIDER = {provide: MyService};452 `);453 writeFile('/index.ts', `454 import {${type}} from '@angular/core';455 import {PROVIDER} from './provider';456 @${type}({${propName}: [PROVIDER]})457 export class TestClassA {}458 `);459 writeFile('/second.ts', `460 import {${type}} from '@angular/core';461 import {PROVIDER} from './provider';462 export class ServiceB {}463 @${type}({${propName}: [PROVIDER, ServiceB]})464 export class TestClassB {}465 `);466 await runMigration();467 expect(warnOutput.length).toBe(0);468 expect(tree.readContent('/provider.ts')).toMatch(/^\s+export class MyService {}/);469 expect(tree.readContent('/provider.ts'))470 .toContain(`const PROVIDER = { provide: MyService, useValue: undefined };`);471 });472 it('should create new import for @Injectable when migrating provider', async () => {473 writeFile('/index.ts', `474 import {${type}} from '@angular/core';475 import {MyService, MySecondService} from './service';476 @${type}({${propName}: [MyService, MySecondService]})477 export class TestClass {}478 `);479 writeFile('/service.ts', `export class MyService {}480 export class MySecondService {}481 `);482 await runMigration();483 expect(warnOutput.length).toBe(0);484 expect(tree.readContent('/service.ts')).toMatch(/@Injectable\(\)\s+export class MyService/);485 expect(tree.readContent('/service.ts'))486 .toMatch(/@Injectable\(\)\s+export class MySecondService/);487 expect(tree.readContent('/service.ts'))488 .toMatch(/import { Injectable } from "@angular\/core";/);489 });490 it('should re-use existing namespace import for importing @Injectable when migrating provider',491 async () => {492 writeFile('/index.ts', `493 import * as core from '@angular/core';494 export class MyService {495 constructor() {496 console.log(core.isDevMode());497 }498 }499 `);500 writeFile('/app.module.ts', `501 import {${type}} from '@angular/core';502 import {MyService} from './index';503 @${type}({${propName}: [MyService]})504 export class TestClass {}505 `);506 await runMigration();507 expect(warnOutput.length).toBe(0);508 expect(tree.readContent('/index.ts'))509 .toMatch(/@core.Injectable\(\)\s+export class MyService/);510 });511 it('should warn if a referenced individual provider could not be resolved', async () => {512 writeFile('/index.ts', `513 import {${type}} from '@angular/core';514 @${type}({${propName}: [NotPresent]})515 export class TestClass {}516 `);517 await runMigration();518 const providerSourceTextColumn = 15 + type.length + propName.length;519 expect(warnOutput.length).toBe(1);520 expect(warnOutput[0]).toMatch(/\s+index\.ts@4:.+Provider is not statically analyzable./);521 expect(warnOutput[0]).toContain(`4:${providerSourceTextColumn}:`);522 });523 it(`should warn if ${propName} value could not be resolved`, async () => {524 writeFile('/index.ts', `525 import {${type}} from '@angular/core';526 @${type}({${propName}: NOT_ANALYZABLE)527 export class TestClass {}528 `);529 await runMigration();530 const propValueSourceTextColumn = 14 + type.length + propName.length;531 expect(warnOutput.length).toBe(1);532 expect(warnOutput[0]).toMatch(/\s+index\.ts@4:.+Providers.*not statically analyzable./);533 expect(warnOutput[0]).toContain(`4:${propValueSourceTextColumn}:`);534 });535 it(`should not throw if an empty @${type} is analyzed`, async () => {536 writeFile('/index.ts', `537 import {${type}} from '@angular/core';538 @${type}()539 export class MyModule {}540 `);541 try {542 await runMigration();543 } catch (e) {544 fail(e);545 }546 expect(warnOutput.length).toBe(0);547 });548 it('should create new import for injectable after full end of last import statement',549 async () => {550 writeFile('/index.ts', `551 import {${type}} from '@angular/core';552 import {MyService} from './service';553 @${type}({${propName}: [MyService]})554 export class TestClass {}555 `);556 writeFile('/service.ts', `557 import * as a from 'a';558 import * as a from 'b'; // some comment559 export class MyService {}560 `);561 await runMigration();562 expect(warnOutput.length).toBe(0);563 expect(tree.readContent('/service.ts'))564 .toMatch(/@Injectable\(\)\s+export class MyService/);565 expect(tree.readContent('/service.ts'))566 .toMatch(/'b'; \/\/ some comment\s+import { Injectable } from "@angular\/core";/);567 });568 it('should create new import at source file start with trailing new-line', async () => {569 writeFile('/index.ts', `570 import {${type}} from '@angular/core';571 import {MyService} from './service';572 @${type}({${propName}: [MyService]})573 export class TestClass {}574 `);575 writeFile('/service.ts', `/* @license */576 export class MyService {}577 `);578 await runMigration();579 expect(warnOutput.length).toBe(0);580 expect(tree.readContent('/service.ts'))581 .toMatch(582 /^import { Injectable } from "@angular\/core";\s+\/\* @license \*\/\s+@Injectable\(\)\s+export class MyService/);583 });584 it('should remove @Inject decorator for providers which are migrated', async () => {585 writeFile('/index.ts', `586 import {${type}} from '@angular/core';587 import {MyService} from './service';588 @${type}({${propName}: [MyService]})589 export class TestClass {}590 `);591 writeFile('/service.ts', `592 import {Inject} from '@angular/core';593 @Inject()594 export class MyService {}595 `);596 await runMigration();597 expect(warnOutput.length).toBe(0);598 expect(tree.readContent('/service.ts'))599 .toMatch(/core';\s+@Injectable\(\)\s+export class MyService/);600 // "inject" import will be preserved. We don't want to bother with detecting601 // if the import is unused or not. We leave this up to the developers.602 expect(tree.readContent('/service.ts'))603 .toMatch(/import { Inject, Injectable } from '@angular\/core';/);604 });605 it('should not migrate provider classes in library type definitions', async () => {606 writeFile('/node_modules/my-lib/index.d.ts', `607 export declare class MyService {}608 `);609 writeFile('/index.ts', `610 import {MyService} from 'my-lib';611 import {Pipe, ${type}} from '@angular/core';612 @${type}({${propName}: [MyService]})613 export class TestClass {}614 `);615 await runMigration();616 expect(warnOutput.length).toBe(0);617 expect(tree.readContent('/node_modules/my-lib/index.d.ts')).not.toContain('@Injectable');618 });619 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.readContent('test.js');3var strykerParent = require('stryker-parent');4strykerParent.readContent('test.js');5var strykerParent = require('stryker-parent');6strykerParent.readContent('test.js');7var strykerParent = require('stryker-parent');8strykerParent.readContent('test.js');9var strykerParent = require('stryker-parent');10strykerParent.readContent('test.js');11var strykerParent = require('stryker-parent');12strykerParent.readContent('test.js');13var strykerParent = require('stryker-parent');14strykerParent.readContent('test.js');15var strykerParent = require('stryker-parent');16strykerParent.readContent('test.js');17var strykerParent = require('stryker-parent');18strykerParent.readContent('test.js');19var strykerParent = require('stryker-parent');20strykerParent.readContent('test.js');21var strykerParent = require('stryker-parent');22strykerParent.readContent('test.js');23var strykerParent = require('stryker-parent');24strykerParent.readContent('test.js');25var strykerParent = require('stryker-parent');26strykerParent.readContent('test

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2console.log(strykerParent.readContent('stryker.conf.js'));3const strykerParent = require('stryker-parent');4console.log(strykerParent.readContent('stryker.conf.js'));5const strykerParent = require('stryker-parent');6console.log(strykerParent.readContent('stryker.conf.js'));7const strykerParent = require('stryker-parent');8console.log(strykerParent.readContent('stryker.conf.js'));9const strykerParent = require('stryker-parent');10console.log(strykerParent.readContent('stryker.conf.js'));11const strykerParent = require('stryker-parent');12console.log(strykerParent.readContent('stryker.conf.js'));13const strykerParent = require('stryker-parent');14console.log(strykerParent.readContent('stryker.conf.js'));15const strykerParent = require('stryker-parent');16console.log(strykerParent.readContent('stryker.conf.js'));17const strykerParent = require('stryker-parent');18console.log(strykerParent.readContent('stryker.conf.js'));19const strykerParent = require('stryker-parent');20console.log(strykerParent.readContent('stryker.conf.js'));21const strykerParent = require('stryker-parent');22console.log(strykerParent.readContent('stryker.conf.js'));23const strykerParent = require('stryker-parent');24console.log(strykerParent.readContent('stryker.conf.js'));

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.readContent('test.txt', 'utf8', function (err, content) {3 if (err) {4 console.log(err);5 } else {6 console.log(content);7 }8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2strykerParent.readContent('package.json', function (err, content) {3 if (err) {4 console.log('Error reading file', err);5 }6 else {7 console.log('Read content', content);8 }9});10{11 "scripts": {12 },13 "repository": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2strykerParent.readContent('package.json', (err, content) => {3});4const strykerParent = require('stryker-parent');5strykerParent.readContent('package.json', (err, content) => {6});7const strykerParent = require('stryker-parent');8strykerParent.readContent('package.json', (err, content) => {9});10const strykerParent = require('stryker-parent');11strykerParent.readContent('package.json', (err, content) => {12});13const strykerParent = require('stryker-parent');14strykerParent.readContent('package.json', (err, content) => {15});16const strykerParent = require('stryker-parent');17strykerParent.readContent('package.json', (err, content) => {18});19const strykerParent = require('stryker-parent');20strykerParent.readContent('package.json', (err, content) => {21});22const strykerParent = require('stryker-parent');23strykerParent.readContent('package.json', (err, content) => {24});25const strykerParent = require('stryker-parent');26strykerParent.readContent('package.json', (err, content) => {27});

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var fileContent = strykerParent.readContent('file.txt');3console.log('Hello world!');4module.exports = function (config) {5 config.set({6 });7};8{9 "scripts": {10 },11 "devDependencies": {12 }13}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful