@ -47,7 +47,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should remove the options object from a dynamic ViewChild query that only has one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ViewChild } from '@angular/core';
|
||||
|
||||
@ -62,7 +62,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should remove the options object from a dynamic ContentChild query that only has one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild } from '@angular/core';
|
||||
|
||||
@ -77,7 +77,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should only remove the `static` flag from a ViewChild query if it has more than one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ViewChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -93,7 +93,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should only remove the `static` flag from a ContentChild query if it has more than one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -108,7 +108,7 @@ describe('dynamic queries migration', () => {
|
||||
.toContain(`@ContentChild('child', { read: ElementRef }) child: ElementRef;`);
|
||||
});
|
||||
|
||||
it('should not change static ViewChild queries', async() => {
|
||||
it('should not change static ViewChild queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ViewChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -123,7 +123,7 @@ describe('dynamic queries migration', () => {
|
||||
.toContain(`@ViewChild('child', { read: ElementRef, static: true }) child: ElementRef;`);
|
||||
});
|
||||
|
||||
it('should not change static ContentChild queries', async() => {
|
||||
it('should not change static ContentChild queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -138,7 +138,7 @@ describe('dynamic queries migration', () => {
|
||||
.toContain(`@ContentChild('child', { static: true, read: ElementRef }) child: ElementRef;`);
|
||||
});
|
||||
|
||||
it('should migrate dynamic queries on a setter', async() => {
|
||||
it('should migrate dynamic queries on a setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild, ViewChild } from '@angular/core';
|
||||
|
||||
|
@ -17,7 +17,7 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -31,7 +31,7 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'dynamic-queries': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -41,7 +41,9 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag dynamic queries', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -172,5 +174,4 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
expect(content).toContain(`@ContentChild('child') set child(c: any) {}`);
|
||||
expect(content).toContain(`@ViewChild('otherChild') set otherChild(c: any) {}`);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -12,7 +12,6 @@ import * as shx from 'shelljs';
|
||||
import {Configuration, Linter} from 'tslint';
|
||||
|
||||
describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
|
||||
/**
|
||||
* Path to the static-query schematic rules directory. The path needs to be resolved through
|
||||
* the Bazel runfiles, because on Windows runfiles are not symlinked into the working directory.
|
||||
@ -23,7 +22,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -41,7 +40,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'explicit-query-timing': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -32,7 +32,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'no-missing-injectable': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -42,7 +42,9 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
describe('NgModule', () => createTests('NgModule', 'providers'));
|
||||
describe('Directive', () => createTests('Directive', 'providers'));
|
||||
@ -77,7 +79,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
});
|
||||
|
||||
function createTests(
|
||||
type: 'NgModule' | 'Directive' | 'Component', propName: 'providers' | 'viewProviders') {
|
||||
type: 'NgModule'|'Directive'|'Component', propName: 'providers'|'viewProviders') {
|
||||
it('should create proper failures for missing injectable providers', () => {
|
||||
writeFile('index.ts', `
|
||||
import { ${type} } from '@angular/core';
|
||||
@ -266,6 +268,4 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
.toMatch(/import { Inject, Injectable } from '@angular\/core';/);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 noTemplateVariableAssignment TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -34,7 +34,7 @@ describe('Google3 noTemplateVariableAssignment TSLint rule', () => {
|
||||
Configuration.parseConfigFile({rules: {'no-template-variable-assignment': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
// We need to declare the Angular symbols we're testing for, otherwise type checking won't work.
|
||||
@ -46,7 +46,7 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'renderer-to-renderer2': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -56,7 +56,9 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag Renderer imports and typed nodes', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -223,8 +225,8 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
runTSLint(true);
|
||||
const content = getFile('index.ts');
|
||||
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g) !.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererSetElementAttributeHelper\(/g) !.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g)!.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererSetElementAttributeHelper\(/g)!.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should insert helpers after the user\'s code', () => {
|
||||
@ -410,5 +412,4 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
// Expect the `setInfo` method to only contain whitespace.
|
||||
expect(content).toMatch(/setInfo\(\) \{\s+\}/);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
});
|
||||
@ -33,7 +33,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -43,7 +43,9 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag undecorated classes with decorated fields', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -97,8 +99,9 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
expect(getFile('/index.ts')).toContain(`import { Directive, Input } from '@angular/core';`);
|
||||
});
|
||||
|
||||
it('should not generate conflicting imports there is a different `Directive` symbol', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should not generate conflicting imports there is a different `Directive` symbol',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { HostBinding } from '@angular/core';
|
||||
|
||||
export class Directive {
|
||||
@ -111,12 +114,12 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
}
|
||||
`);
|
||||
|
||||
runTSLint(true);
|
||||
const fileContent = getFile('/index.ts');
|
||||
expect(fileContent)
|
||||
.toContain(`import { HostBinding, Directive as Directive_1 } from '@angular/core';`);
|
||||
expect(fileContent).toMatch(/@Directive_1\(\)\s+export class MyLibrarySharedBaseClass/);
|
||||
});
|
||||
runTSLint(true);
|
||||
const fileContent = getFile('/index.ts');
|
||||
expect(fileContent)
|
||||
.toContain(`import { HostBinding, Directive as Directive_1 } from '@angular/core';`);
|
||||
expect(fileContent).toMatch(/@Directive_1\(\)\s+export class MyLibrarySharedBaseClass/);
|
||||
});
|
||||
|
||||
it('should add @Directive to undecorated classes that have @Input', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -250,7 +253,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
expect(getFile('/index.ts')).toContain(`@Directive()\nexport class Base {`);
|
||||
});
|
||||
|
||||
it('should add @Directive to undecorated derived classes of a migrated class', async() => {
|
||||
it('should add @Directive to undecorated derived classes of a migrated class', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Input, Directive, NgModule } from '@angular/core';
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {computeLineStartsMap, getLineAndCharacterFromPosition} from '../utils/line_mappings';
|
||||
|
||||
describe('line mappings', () => {
|
||||
|
||||
it('should properly compute line starts',
|
||||
() => {
|
||||
expect(computeLineStartsMap(`
|
||||
|
@ -76,7 +76,7 @@ describe('Missing injectable migration', () => {
|
||||
|
||||
it('should migrate all providers defined in "viewProviders" and "providers" in the ' +
|
||||
'same component',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -102,8 +102,8 @@ describe('Missing injectable migration', () => {
|
||||
});
|
||||
|
||||
function createTests(
|
||||
type: 'NgModule' | 'Directive' | 'Component', propName: 'providers' | 'viewProviders') {
|
||||
it(`should migrate type provider in ${type}`, async() => {
|
||||
type: 'NgModule'|'Directive'|'Component', propName: 'providers'|'viewProviders') {
|
||||
it(`should migrate type provider in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -121,7 +121,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ ${type}, Injectable } from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should migrate object literal provider in ${type} to explicit value provider`, async() => {
|
||||
it(`should migrate object literal provider in ${type} to explicit value provider`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -140,7 +140,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`{${type}} from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should migrate object literal provider with forwardRef in ${type}`, async() => {
|
||||
it(`should migrate object literal provider with forwardRef in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}, forwardRef} from '@angular/core';
|
||||
|
||||
@ -158,7 +158,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ ${type}, forwardRef, Injectable } from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should not migrate object literal provider with "useValue" in ${type}`, async() => {
|
||||
it(`should not migrate object literal provider with "useValue" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -174,7 +174,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should not migrate provider with "useClass" and "deps" in ${type}`, async() => {
|
||||
it(`should not migrate provider with "useClass" and "deps" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -190,7 +190,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should not migrate object literal provider with "useFactory" in ${type}`, async() => {
|
||||
it(`should not migrate object literal provider with "useFactory" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -206,7 +206,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should not migrate object literal provider with "useExisting" in ${type}`, async() => {
|
||||
it(`should not migrate object literal provider with "useExisting" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -226,7 +226,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should migrate object literal provider with "useClass" in ${type}`, async() => {
|
||||
it(`should migrate object literal provider with "useClass" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -248,7 +248,7 @@ describe('Missing injectable migration', () => {
|
||||
|
||||
it(`should not migrate references for providers with "useExisting" in ${type}, but migrate ` +
|
||||
`existing token if declared in other ${type}`,
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -281,7 +281,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toMatch(/MyService {}\s+export class MyToken/);
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Injectable', async() => {
|
||||
it('should not migrate provider which is already decorated with @Injectable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Injectable, ${type}} from '@angular/core';
|
||||
|
||||
@ -299,7 +299,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/@angular\/core';\s+@Injectable\(\)\s+export class MyService/);
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Directive', async() => {
|
||||
it('should not migrate provider which is already decorated with @Directive', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Directive, ${type}} from '@angular/core';
|
||||
|
||||
@ -316,7 +316,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Component', async() => {
|
||||
it('should not migrate provider which is already decorated with @Component', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${type}} from '@angular/core';
|
||||
|
||||
@ -333,7 +333,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Pipe', async() => {
|
||||
it('should not migrate provider which is already decorated with @Pipe', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Pipe, ${type}} from '@angular/core';
|
||||
|
||||
@ -350,7 +350,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should migrate multiple providers in same ${type}`, async() => {
|
||||
it(`should migrate multiple providers in same ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -370,7 +370,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ ${type}, Injectable } from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should migrate multiple mixed providers in same ${type}`, async() => {
|
||||
it(`should migrate multiple mixed providers in same ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -399,7 +399,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ provide: ServiceB, useValue: undefined },`);
|
||||
});
|
||||
|
||||
it(`should migrate multiple nested providers in same ${type}`, async() => {
|
||||
it(`should migrate multiple nested providers in same ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -433,7 +433,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ provide: ServiceD, useValue: undefined },`);
|
||||
});
|
||||
|
||||
it('should migrate providers referenced through identifier', async() => {
|
||||
it('should migrate providers referenced through identifier', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -467,7 +467,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ provide: ServiceC, useValue: undefined },`);
|
||||
});
|
||||
|
||||
it('should migrate providers created through static analyzable function call', async() => {
|
||||
it('should migrate providers created through static analyzable function call', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -497,7 +497,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`ServiceB, { provide: ServiceC, useValue: undefined }),`);
|
||||
});
|
||||
|
||||
it('should migrate providers which are computed through spread operator', async() => {
|
||||
it('should migrate providers which are computed through spread operator', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -525,7 +525,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`ServiceB, { provide: ServiceC, useValue: undefined }];`);
|
||||
});
|
||||
|
||||
it(`should migrate provider once if referenced in multiple ${type} definitions`, async() => {
|
||||
it(`should migrate provider once if referenced in multiple ${type} definitions`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -559,7 +559,7 @@ describe('Missing injectable migration', () => {
|
||||
|
||||
it(`should only migrate empty object provider literal once if referenced multiple times ` +
|
||||
`in ${type} definitions`,
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/provider.ts', `
|
||||
export class MyService {}
|
||||
|
||||
@ -592,7 +592,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`const PROVIDER = { provide: MyService, useValue: undefined };`);
|
||||
});
|
||||
|
||||
it('should create new import for @Injectable when migrating provider', async() => {
|
||||
it('should create new import for @Injectable when migrating provider', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService, MySecondService} from './service';
|
||||
@ -617,7 +617,7 @@ describe('Missing injectable migration', () => {
|
||||
});
|
||||
|
||||
it('should re-use existing namespace import for importing @Injectable when migrating provider',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import * as core from '@angular/core';
|
||||
|
||||
@ -643,7 +643,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/@core.Injectable\(\)\s+export class MyService/);
|
||||
});
|
||||
|
||||
it('should warn if a referenced individual provider could not be resolved', async() => {
|
||||
it('should warn if a referenced individual provider could not be resolved', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -659,7 +659,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(warnOutput[0]).toContain(`4:${providerSourceTextColumn}:`);
|
||||
});
|
||||
|
||||
it(`should warn if ${propName} value could not be resolved`, async() => {
|
||||
it(`should warn if ${propName} value could not be resolved`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -675,7 +675,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(warnOutput[0]).toContain(`4:${propValueSourceTextColumn}:`);
|
||||
});
|
||||
|
||||
it(`should not throw if an empty @${type} is analyzed`, async() => {
|
||||
it(`should not throw if an empty @${type} is analyzed`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -693,7 +693,7 @@ describe('Missing injectable migration', () => {
|
||||
});
|
||||
|
||||
it('should create new import for injectable after full end of last import statement',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService} from './service';
|
||||
@ -718,7 +718,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/'b'; \/\/ some comment\s+import { Injectable } from "@angular\/core";/);
|
||||
});
|
||||
|
||||
it('should create new import at source file start with trailing new-line', async() => {
|
||||
it('should create new import at source file start with trailing new-line', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService} from './service';
|
||||
@ -739,7 +739,7 @@ describe('Missing injectable migration', () => {
|
||||
/^import { Injectable } from "@angular\/core";\s+\/\* @license \*\/\s+@Injectable\(\)\s+export class MyService/);
|
||||
});
|
||||
|
||||
it('should remove @Inject decorator for providers which are migrated', async() => {
|
||||
it('should remove @Inject decorator for providers which are migrated', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService} from './service';
|
||||
@ -766,7 +766,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/import { Inject, Injectable } from '@angular\/core';/);
|
||||
});
|
||||
|
||||
it('should not migrate provider classes in library type definitions', async() => {
|
||||
it('should not migrate provider classes in library type definitions', async () => {
|
||||
writeFile('/node_modules/my-lib/index.d.ts', `
|
||||
export declare class MyService {}
|
||||
`);
|
||||
|
@ -46,7 +46,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
shx.rm('-r', tmpDirPath);
|
||||
});
|
||||
|
||||
it('should add generic type for function return', async() => {
|
||||
it('should add generic type for function return', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule, ModuleWithProviders} from '@angular/core';
|
||||
|
||||
@ -69,7 +69,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for function return; external file', async() => {
|
||||
it('should add generic type for function return; external file', async () => {
|
||||
writeFile('/module.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -96,7 +96,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for function return without explicit type', async() => {
|
||||
it('should add generic type for function return without explicit type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -119,7 +119,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for const variable', async() => {
|
||||
it('should add generic type for const variable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {ModuleWithProviders, NgModule} from '@angular/core';
|
||||
|
||||
@ -140,7 +140,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for const variable without explicit type', async() => {
|
||||
it('should add generic type for const variable without explicit type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -161,7 +161,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should not add generic type for const variable with invalid base object', async() => {
|
||||
it('should not add generic type for const variable with invalid base object', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -182,7 +182,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for const variables and functions with incomplete type', async() => {
|
||||
it('should add generic type for const variables and functions with incomplete type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {ModuleWithProviders, NgModule} from '@angular/core';
|
||||
|
||||
@ -214,7 +214,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain(`ModuleWithProviders `);
|
||||
});
|
||||
|
||||
it('should not add generic type for const variables without initialization', async() => {
|
||||
it('should not add generic type for const variables without initialization', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {ModuleWithProviders} from '@angular/core';
|
||||
|
||||
|
@ -47,7 +47,7 @@ describe('move-document migration', () => {
|
||||
});
|
||||
|
||||
describe('move-document', () => {
|
||||
it('should properly apply import replacement', async() => {
|
||||
it('should properly apply import replacement', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
`);
|
||||
@ -73,7 +73,7 @@ describe('move-document migration', () => {
|
||||
expect(content).not.toContain(`import {DOCUMENT} from '@angular/platform-browser';`);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import', async() => {
|
||||
it('should properly apply import replacement with existing import', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
import {someImport} from '@angular/common';
|
||||
@ -96,7 +96,7 @@ describe('move-document migration', () => {
|
||||
expect(contentReverse).not.toContain(`import {DOCUMENT} from '@angular/platform-browser';`);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import w/ comments', async() => {
|
||||
it('should properly apply import replacement with existing import w/ comments', async () => {
|
||||
writeFile('/index.ts', `
|
||||
/**
|
||||
* this is a comment
|
||||
@ -115,7 +115,7 @@ describe('move-document migration', () => {
|
||||
expect(content).toMatch(/.*this is a comment.*/);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing and redundant imports', async() => {
|
||||
it('should properly apply import replacement with existing and redundant imports', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
import {anotherImport} from '@angular/platform-browser-dynamic';
|
||||
@ -131,7 +131,7 @@ describe('move-document migration', () => {
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import and leave original import',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT, anotherImport} from '@angular/platform-browser';
|
||||
import {someImport} from '@angular/common';
|
||||
@ -145,7 +145,7 @@ describe('move-document migration', () => {
|
||||
expect(content).toContain(`import { anotherImport } from '@angular/platform-browser';`);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import and alias', async() => {
|
||||
it('should properly apply import replacement with existing import and alias', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT as doc, anotherImport} from '@angular/platform-browser';
|
||||
import {someImport} from '@angular/common';
|
||||
|
@ -13,13 +13,14 @@ import {getProjectTsConfigPaths} from '../utils/project_tsconfig_paths';
|
||||
describe('project tsconfig paths', () => {
|
||||
let testTree: UnitTestTree;
|
||||
|
||||
beforeEach(() => { testTree = new UnitTestTree(new HostTree()); });
|
||||
beforeEach(() => {
|
||||
testTree = new UnitTestTree(new HostTree());
|
||||
});
|
||||
|
||||
it('should detect build tsconfig path inside of angular.json file', () => {
|
||||
testTree.create('/my-custom-config.json', '');
|
||||
testTree.create('/angular.json', JSON.stringify({
|
||||
projects:
|
||||
{my_name: {architect: {build: {options: {tsConfig: './my-custom-config.json'}}}}}
|
||||
projects: {my_name: {architect: {build: {options: {tsConfig: './my-custom-config.json'}}}}}
|
||||
}));
|
||||
|
||||
expect(getProjectTsConfigPaths(testTree).buildPaths).toEqual(['my-custom-config.json']);
|
||||
@ -57,8 +58,7 @@ describe('project tsconfig paths', () => {
|
||||
it('should detect test tsconfig path inside of .angular.json file', () => {
|
||||
testTree.create('/my-test-config.json', '');
|
||||
testTree.create('/.angular.json', JSON.stringify({
|
||||
projects:
|
||||
{with_tests: {architect: {test: {options: {tsConfig: './my-test-config.json'}}}}}
|
||||
projects: {with_tests: {architect: {test: {options: {tsConfig: './my-test-config.json'}}}}}
|
||||
}));
|
||||
|
||||
expect(getProjectTsConfigPaths(testTree).testPaths).toEqual(['my-test-config.json']);
|
||||
|
@ -52,7 +52,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('import renaming', () => {
|
||||
it('should change Renderer imports to Renderer2', async() => {
|
||||
it('should change Renderer imports to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -67,7 +67,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`import { Component, Renderer2 } from '@angular/core';`);
|
||||
});
|
||||
|
||||
it('should change aliased Renderer imports to Renderer2', async() => {
|
||||
it('should change aliased Renderer imports to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer as RenamedRenderer, Component } from '@angular/core';
|
||||
|
||||
@ -82,7 +82,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`import { Component, Renderer2 as RenamedRenderer } from '@angular/core';`);
|
||||
});
|
||||
|
||||
it('should not change Renderer imports if they are not from @angular/core', async() => {
|
||||
it('should not change Renderer imports if they are not from @angular/core', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Component } from '@angular/core';
|
||||
import { Renderer } from './my-renderer';
|
||||
@ -102,7 +102,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('type renaming', () => {
|
||||
it('should change type of constructor parameter from Renderer to Renderer2', async() => {
|
||||
it('should change type of constructor parameter from Renderer to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -117,7 +117,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('constructor(element: ElementRef, renderer: Renderer2)');
|
||||
});
|
||||
|
||||
it('should change type of method parameter from Renderer to Renderer2', async() => {
|
||||
it('should change type of method parameter from Renderer to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -134,7 +134,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('disable(renderer: Renderer2, element: HTMLElement, isDisabled: boolean)');
|
||||
});
|
||||
|
||||
it('should change type of property declarations', async() => {
|
||||
it('should change type of property declarations', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -148,7 +148,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain('public renderer: Renderer2;');
|
||||
});
|
||||
|
||||
it('should change type of properties initialized via the constructor', async() => {
|
||||
it('should change type of properties initialized via the constructor', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -163,7 +163,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('constructor(element: ElementRef, private _renderer: Renderer2)');
|
||||
});
|
||||
|
||||
it('should change the type of something that was cast to Renderer', async() => {
|
||||
it('should change the type of something that was cast to Renderer', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -184,7 +184,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(content).toContain(`renderer.setStyle(element.nativeElement, 'color', 'red');`);
|
||||
});
|
||||
|
||||
it('should not rename types called Renderer that do not come from Angular', async() => {
|
||||
it('should not rename types called Renderer that do not come from Angular', async () => {
|
||||
// Write a dummy renderer file so type checking picks it up.
|
||||
writeFile('/my-renderer.ts', `export abstract class Renderer {}`);
|
||||
|
||||
@ -203,7 +203,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('constructor(element: ElementRef, renderer: Renderer)');
|
||||
});
|
||||
|
||||
it('should rename inside single-line forwardRef', async() => {
|
||||
it('should rename inside single-line forwardRef', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef, forwardRef, Inject } from '@angular/core';
|
||||
|
||||
@ -221,7 +221,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`constructor(@Inject(forwardRef(() => Renderer2)) private _renderer: Renderer2)`);
|
||||
});
|
||||
|
||||
it('should rename inside multi-line forwardRef', async() => {
|
||||
it('should rename inside multi-line forwardRef', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef, forwardRef, Inject } from '@angular/core';
|
||||
|
||||
@ -238,11 +238,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(content).toContain(
|
||||
`constructor(@Inject(forwardRef(() => { return Renderer2; })) private _renderer: Renderer2) {}`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('helper insertion', () => {
|
||||
it('should only declare each helper once per file', async() => {
|
||||
it('should only declare each helper once per file', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -260,11 +259,11 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
const content = tree.readContent('/index.ts');
|
||||
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createElement.');
|
||||
});
|
||||
|
||||
it('should insert helpers after the user\'s code', async() => {
|
||||
it('should insert helpers after the user\'s code', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -287,7 +286,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(contentAfterSeparator).toContain('function __ngRendererCreateElementHelper(');
|
||||
});
|
||||
|
||||
it('should be able to handle multiple helpers per file', async() => {
|
||||
it('should be able to handle multiple helpers per file', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -314,15 +313,15 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
const content = tree.readContent('/index.ts');
|
||||
|
||||
expect(content.match(/function __ngRendererCreateTextHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateTextHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createElement.');
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createText.');
|
||||
expect(content.match(/function __ngRendererCreateTemplateAnchorHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateTemplateAnchorHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createTemplateAnchor.');
|
||||
});
|
||||
|
||||
it('should create the __ngRendererSplitNamespaceHelper', async() => {
|
||||
it('should create the __ngRendererSplitNamespaceHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -347,7 +346,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`));
|
||||
});
|
||||
|
||||
it('should declare our custom any type', async() => {
|
||||
it('should declare our custom any type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -365,11 +364,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
type AnyDuringRendererMigration = any;
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('setElementProperty migration', () => {
|
||||
it('should migrate setElementProperty calls', async() => {
|
||||
it('should migrate setElementProperty calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -390,7 +388,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setText migration', () => {
|
||||
it('should migrate setText calls', async() => {
|
||||
it('should migrate setText calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -412,7 +410,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('listenGlobal migration', () => {
|
||||
it('should migrate listenGlobal calls', async() => {
|
||||
it('should migrate listenGlobal calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -433,7 +431,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('selectRootElement migration', () => {
|
||||
it('should migrate selectRootElement calls', async() => {
|
||||
it('should migrate selectRootElement calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -454,7 +452,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setElementClass migration', () => {
|
||||
it('should migrate calls with inline isAdd value', async() => {
|
||||
it('should migrate calls with inline isAdd value', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -479,7 +477,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`this._renderer.removeClass(this._element.nativeElement, className);`);
|
||||
});
|
||||
|
||||
it('should migrate calls with variable isAdd value', async() => {
|
||||
it('should migrate calls with variable isAdd value', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -503,7 +501,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setElementStyle migration', () => {
|
||||
it('should migrate calls with two arguments to a removeStyle call', async() => {
|
||||
it('should migrate calls with two arguments to a removeStyle call', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -522,7 +520,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`this._renderer.removeStyle(this._element.nativeElement, 'color');`);
|
||||
});
|
||||
|
||||
it('should migrate calls with static third arguments to a setStyle call', async() => {
|
||||
it('should migrate calls with static third arguments to a setStyle call', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -552,7 +550,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
it('should migrate calls with null or undefined value for last argument to a removeStyle call',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -575,7 +573,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`this._renderer.removeStyle(this._element.nativeElement, 'background-color');`);
|
||||
});
|
||||
|
||||
it('should migrate calls with a variable third argument', async() => {
|
||||
it('should migrate calls with a variable third argument', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -597,7 +595,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
it('should migrate calls with a variable third argument whose value can be inferred',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -625,7 +623,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setElementAttribute migration', () => {
|
||||
it('should migrate to calls to the __ngRendererSetElementAttributeHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererSetElementAttributeHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -651,7 +649,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'__ngRendererSetElementAttributeHelper(this._renderer, this._element.nativeElement, name);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererSetElementAttributeHelper', async() => {
|
||||
it('should declare the __ngRendererSetElementAttributeHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -680,12 +678,11 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
expect(content).toContain(stripWhitespace('function __ngRendererSplitNamespaceHelper('));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('invokeElementMethod migration', () => {
|
||||
it('should migrate calls to a direct method call if the method name and arguments are static',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -710,7 +707,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
it('should migrate calls to a property access if the method name or arguments are dynamic',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -738,7 +735,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`(this._element.nativeElement as any)['otherMethod'].apply(this._element.nativeElement, args);`);
|
||||
});
|
||||
|
||||
it('should handle calls without an `args` array', async() => {
|
||||
it('should handle calls without an `args` array', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -761,7 +758,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setBindingDebugInfo migration', () => {
|
||||
it('should drop calls to setBindingDebugInfo', async() => {
|
||||
it('should drop calls to setBindingDebugInfo', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -783,7 +780,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('createViewRoot migration', () => {
|
||||
it('should replace createViewRoot calls with a reference to the first argument', async() => {
|
||||
it('should replace createViewRoot calls with a reference to the first argument', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -806,7 +803,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('createElement migration', () => {
|
||||
it('should migrate to calls to the __ngRendererCreateElementHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererCreateElementHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -833,7 +830,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'return __ngRendererCreateElementHelper(this._renderer, this._element.nativeElement, nodeName);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererCreateElementHelper', async() => {
|
||||
it('should declare the __ngRendererCreateElementHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -862,11 +859,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
expect(content).toContain(stripWhitespace('function __ngRendererSplitNamespaceHelper('));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('createText migration', () => {
|
||||
it('should migrate to calls to the __ngRendererCreateTextHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererCreateTextHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -893,7 +889,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'return __ngRendererCreateTextHelper(this._renderer, this._element.nativeElement, value);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererCreateTextHelper', async() => {
|
||||
it('should declare the __ngRendererCreateTextHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -917,11 +913,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('createTemplateAnchor migration', () => {
|
||||
it('should migrate to calls to the __ngRendererCreateTemplateAnchorHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererCreateTemplateAnchorHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -947,7 +942,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'return __ngRendererCreateTemplateAnchorHelper(this._renderer, this._element.nativeElement);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererCreateTemplateAnchorHelper', async() => {
|
||||
it('should declare the __ngRendererCreateTemplateAnchorHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -971,11 +966,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('projectNodes migration', () => {
|
||||
it('should migrate to calls to the __ngRendererProjectNodesHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererProjectNodesHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -997,7 +991,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'__ngRendererProjectNodesHelper(this._renderer, this._element.nativeElement, nodesToProject);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererProjectNodesHelper', async() => {
|
||||
it('should declare the __ngRendererProjectNodesHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1019,11 +1013,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('animate migration', () => {
|
||||
it('should migrate to calls to the __ngRendererAnimateHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererAnimateHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1043,7 +1036,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain('__ngRendererAnimateHelper();');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererAnimateHelper', async() => {
|
||||
it('should declare the __ngRendererAnimateHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1063,11 +1056,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('destroyView migration', () => {
|
||||
it('should migrate to calls to the __ngRendererDestroyViewHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererDestroyViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1088,7 +1080,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('__ngRendererDestroyViewHelper(this._renderer, allNodes);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererDestroyViewHelper', async() => {
|
||||
it('should declare the __ngRendererDestroyViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1116,7 +1108,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('detachView migration', () => {
|
||||
it('should migrate to calls to the __ngRendererDetachViewHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererDetachViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -1137,7 +1129,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('__ngRendererDetachViewHelper(this._renderer, rootNodes);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererDetachViewHelper', async() => {
|
||||
it('should declare the __ngRendererDetachViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -1166,7 +1158,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('attachViewAfter migration', () => {
|
||||
it('should migrate to calls to the __ngRendererAttachViewAfterHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererAttachViewAfterHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1188,7 +1180,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'__ngRendererAttachViewAfterHelper(this._renderer, this._element.nativeElement, rootNodes);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererAttachViewAfterHelper', async() => {
|
||||
it('should declare the __ngRendererAttachViewAfterHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -1225,5 +1217,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
return runner.runSchematicAsync('migration-v9-renderer-to-renderer2', {}, tree).toPromise();
|
||||
}
|
||||
|
||||
function stripWhitespace(contents: string) { return contents.replace(/\s/g, ''); }
|
||||
function stripWhitespace(contents: string) {
|
||||
return contents.replace(/\s/g, '');
|
||||
}
|
||||
});
|
||||
|
@ -61,7 +61,9 @@ describe('static-queries migration with template strategy', () => {
|
||||
shx.rm('-r', tmpDirPath);
|
||||
});
|
||||
|
||||
function writeFakeAngular() { writeFile('/node_modules/@angular/core/index.d.ts', ``); }
|
||||
function writeFakeAngular() {
|
||||
writeFile('/node_modules/@angular/core/index.d.ts', ``);
|
||||
}
|
||||
|
||||
function writeFakeLibrary(selectorName = 'my-lib-selector') {
|
||||
writeFile('/node_modules/my-lib/index.d.ts', `export * from './public-api';`);
|
||||
@ -105,8 +107,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
}
|
||||
|
||||
describe('ViewChild', () => {
|
||||
|
||||
it('should detect queries selecting elements through template reference', async() => {
|
||||
it('should detect queries selecting elements through template reference', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -135,7 +136,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myStaticButton', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting ng-template as static', async() => {
|
||||
it('should detect queries selecting ng-template as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -158,7 +159,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myTmpl', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting ng-template as static (BOM)', async() => {
|
||||
it('should detect queries selecting ng-template as static (BOM)', async () => {
|
||||
writeFile('/index.ts', `\uFEFF
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -181,8 +182,9 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myTmpl', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting component view providers through string token', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should detect queries selecting component view providers through string token',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
@ -211,22 +213,22 @@ describe('static-queries migration with template strategy', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile(`/my-tmpl.html`, `
|
||||
writeFile(`/my-tmpl.html`, `
|
||||
<span myDirective></span>
|
||||
<ng-template>
|
||||
<span myDirective2></span>
|
||||
</ng-template>
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token-2', { static: false }) query2: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token-2', { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting component view providers using class token', async() => {
|
||||
it('should detect queries selecting component view providers using class token', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -270,7 +272,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild(MyService2, { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting component', async() => {
|
||||
it('should detect queries selecting component', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
import {HomeComponent, HomeComponent2} from './home-comp';
|
||||
@ -316,7 +318,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild(HomeComponent2, { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting third-party component', async() => {
|
||||
it('should detect queries selecting third-party component', async () => {
|
||||
writeFakeLibrary();
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
@ -341,9 +343,10 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild(MyLibComponent, { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting third-party component with multiple selectors', async() => {
|
||||
writeFakeLibrary('a-selector, test-selector');
|
||||
writeFile('/index.ts', `
|
||||
it('should detect queries selecting third-party component with multiple selectors',
|
||||
async () => {
|
||||
writeFakeLibrary('a-selector, test-selector');
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
import {MyLibComponent} from 'my-lib';
|
||||
|
||||
@ -356,20 +359,20 @@ describe('static-queries migration with template strategy', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/my-tmpl.html', `
|
||||
writeFile('/my-tmpl.html', `
|
||||
<a-selector>Match 1</a-selector>
|
||||
<ng-template>
|
||||
<test-selector>Match 2</test-selector>
|
||||
</ng-template>
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild(MyLibComponent, { static: false }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild(MyLibComponent, { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries within structural directive', async() => {
|
||||
it('should detect queries within structural directive', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -399,7 +402,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef2', { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect inherited queries', async() => {
|
||||
it('should detect inherited queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -424,7 +427,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries declared on setter', async() => {
|
||||
it('should detect queries declared on setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -448,7 +451,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toMatch(/@ViewChild\('myRef', { static: true }\)\s+set query/);
|
||||
});
|
||||
|
||||
it('should detect queries declared on getter', async() => {
|
||||
it('should detect queries declared on getter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -473,7 +476,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toMatch(/@ViewChild\('myRef', { static: true }\)\s+get query/);
|
||||
});
|
||||
|
||||
it('should add a todo if a query is not declared in any component', async() => {
|
||||
it('should add a todo if a query is not declared in any component', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild, SomeToken} from '@angular/core';
|
||||
|
||||
@ -493,7 +496,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
/^⮑ {3}index.ts@5:11:.+could not be determined.+not declared in any component/);
|
||||
});
|
||||
|
||||
it('should add a todo if a query is used multiple times with different timing', async() => {
|
||||
it('should add a todo if a query is used multiple times with different timing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -523,7 +526,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
|
||||
it('should be able to migrate an application with type checking failure which ' +
|
||||
'does not affect analysis',
|
||||
async() => {
|
||||
async () => {
|
||||
// Fakes the `@angular/package` by creating a `ViewChild` decorator
|
||||
// function that requires developers to specify the "static" flag.
|
||||
writeFile('/node_modules/@angular/core/index.d.ts', `
|
||||
@ -565,7 +568,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
|
||||
it('should be able to migrate applications with template type checking failure ' +
|
||||
'which does not affect analysis',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule, Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -596,7 +599,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should notify user if project has syntax errors which can affect analysis', async() => {
|
||||
it('should notify user if project has syntax errors which can affect analysis', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -630,7 +633,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should gracefully exit migration if queries could not be analyzed', async() => {
|
||||
it('should gracefully exit migration if queries could not be analyzed', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -650,7 +653,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(errorOutput[0]).toMatch(/Cannot determine the module for class MyComp/);
|
||||
});
|
||||
|
||||
it('should gracefully exit migration if AOT compiler throws exception', async() => {
|
||||
it('should gracefully exit migration if AOT compiler throws exception', async () => {
|
||||
writeFile('/my-component.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -691,7 +694,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(errorOutput[0]).toMatch(/^TypeError: Cannot read property 'module' of undefined/);
|
||||
});
|
||||
|
||||
it('should add a todo for content queries which are not detectable', async() => {
|
||||
it('should add a todo for content queries which are not detectable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ContentChild} from '@angular/core';
|
||||
|
||||
@ -713,7 +716,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toMatch(/^⮑ {3}index.ts@6:11: Content queries cannot be migrated automatically\./);
|
||||
});
|
||||
|
||||
it('should add a todo if query options cannot be migrated inline', async() => {
|
||||
it('should add a todo if query options cannot be migrated inline', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -738,7 +741,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(warnOutput[0]).toMatch(/Please manually set the query timing to.*static: true/);
|
||||
});
|
||||
|
||||
it('should not normalize stylesheets which are referenced in component', async() => {
|
||||
it('should not normalize stylesheets which are referenced in component', async () => {
|
||||
writeFile('sub_dir/index.ts', `
|
||||
import {Component, NgModule, ContentChild} from '@angular/core';
|
||||
|
||||
@ -765,7 +768,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(console.error).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('should always use the test migration strategy for test tsconfig files', async() => {
|
||||
it('should always use the test migration strategy for test tsconfig files', async () => {
|
||||
writeFile('/src/tsconfig.spec.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
experimentalDecorators: true,
|
||||
@ -812,7 +815,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not fall back to test strategy if selected strategy fails', async() => {
|
||||
it('should not fall back to test strategy if selected strategy fails', async () => {
|
||||
writeFile('/src/tsconfig.spec.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
experimentalDecorators: true,
|
||||
|
@ -63,7 +63,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
describe('ViewChild', () => {
|
||||
createQueryTests('ViewChild');
|
||||
|
||||
it('should mark view queries used in "ngAfterContentInit" as static', async() => {
|
||||
it('should mark view queries used in "ngAfterContentInit" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -83,7 +83,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@ViewChild('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark view queries used in "ngAfterContentChecked" as static', async() => {
|
||||
it('should mark view queries used in "ngAfterContentChecked" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -107,7 +107,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
describe('ContentChild', () => {
|
||||
createQueryTests('ContentChild');
|
||||
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static', async() => {
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ContentChild} from '@angular/core';
|
||||
|
||||
@ -127,7 +127,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@ContentChild('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static (BOM)', async() => {
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static (BOM)', async () => {
|
||||
writeFile('/index.ts', `\uFEFF
|
||||
import {Component, ContentChild} from '@angular/core';
|
||||
|
||||
@ -147,7 +147,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@ContentChild('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark content queries used in "ngAfterContentChecked" as static', async() => {
|
||||
it('should not mark content queries used in "ngAfterContentChecked" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ContentChild} from '@angular/core';
|
||||
|
||||
@ -176,8 +176,8 @@ describe('static-queries migration with usage strategy', () => {
|
||||
return runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise();
|
||||
}
|
||||
|
||||
function createQueryTests(queryType: 'ViewChild' | 'ContentChild') {
|
||||
it('should mark queries as dynamic', async() => {
|
||||
function createQueryTests(queryType: 'ViewChild'|'ContentChild') {
|
||||
it('should mark queries as dynamic', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -200,7 +200,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('dynamic', { static: false }) dynamic: any`);
|
||||
});
|
||||
|
||||
it('should mark queries used in "ngOnChanges" as static', async() => {
|
||||
it('should mark queries used in "ngOnChanges" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -220,7 +220,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries used in "ngOnInit" as static', async() => {
|
||||
it('should mark queries used in "ngOnInit" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -240,7 +240,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries used in "ngDoCheck" as static', async() => {
|
||||
it('should mark queries used in "ngDoCheck" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -260,7 +260,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should keep existing query options when updating timing', async() => {
|
||||
it('should keep existing query options when updating timing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -280,7 +280,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { /* test */ read: null, static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should add a todo for queries declared on setter', async() => {
|
||||
it('should add a todo for queries declared on setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -300,7 +300,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toMatch(/index.ts@6:11: Queries defined on accessors cannot be analyzed.$/);
|
||||
});
|
||||
|
||||
it('should add a todo for queries declared on getter', async() => {
|
||||
it('should add a todo for queries declared on getter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -321,7 +321,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toMatch(/index.ts@6:11: Queries defined on accessors cannot be analyzed.$/);
|
||||
});
|
||||
|
||||
it('should not overwrite existing explicit query timing', async() => {
|
||||
it('should not overwrite existing explicit query timing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -337,7 +337,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', {static: /* untouched */ someVal}) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries used in deep method chain', async() => {
|
||||
it('should detect queries used in deep method chain', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -372,7 +372,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should properly exit if recursive function is analyzed', async() => {
|
||||
it('should properly exit if recursive function is analyzed', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -396,7 +396,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries used in newly instantiated classes', async() => {
|
||||
it('should detect queries used in newly instantiated classes', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -435,7 +435,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries used in parenthesized new expressions', async() => {
|
||||
it('should detect queries used in parenthesized new expressions', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -461,7 +461,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries in lifecycle hook with string literal name', async() => {
|
||||
it('should detect queries in lifecycle hook with string literal name', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -481,7 +481,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries within nested inheritance', async() => {
|
||||
it('should detect static queries within nested inheritance', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -506,7 +506,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used within input setters', async() => {
|
||||
it('should detect static queries used within input setters', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Input, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -528,7 +528,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect inputs defined in metadata', async() => {
|
||||
it('should detect inputs defined in metadata', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -554,7 +554,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect aliased inputs declared in metadata', async() => {
|
||||
it('should detect aliased inputs declared in metadata', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -577,7 +577,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark query as static if query is used in non-input setter', async() => {
|
||||
it('should not mark query as static if query is used in non-input setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -597,7 +597,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect input decorator on setter', async() => {
|
||||
it('should detect input decorator on setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Input, Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -622,7 +622,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect setter inputs in derived classes', async() => {
|
||||
it('should detect setter inputs in derived classes', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -647,7 +647,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should properly detect static query in external derived class', async() => {
|
||||
it('should properly detect static query in external derived class', async () => {
|
||||
writeFile('/src/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -680,7 +680,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in promises as static', async() => {
|
||||
it('should not mark queries used in promises as static', async () => {
|
||||
writeFile('/es2015.dom.d.ts', `
|
||||
interface PromiseConstructor {
|
||||
resolve(): Promise;
|
||||
@ -735,7 +735,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should handle function callbacks which statically access queries', async() => {
|
||||
it('should handle function callbacks which statically access queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -764,7 +764,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
});
|
||||
|
||||
it('should handle class instantiations with specified callbacks that access queries',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {External} from './external';
|
||||
@ -794,7 +794,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should handle nested functions with arguments from parent closure', async() => {
|
||||
it('should handle nested functions with arguments from parent closure', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -823,7 +823,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in setTimeout as static', async() => {
|
||||
it('should not mark queries used in setTimeout as static', async () => {
|
||||
writeFile('/lib.dom.d.ts', `declare function setTimeout(cb: Function);`);
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
@ -859,7 +859,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query3: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in "addEventListener" as static', async() => {
|
||||
it('should not mark queries used in "addEventListener" as static', async () => {
|
||||
writeFile('/lib.dom.d.ts', `
|
||||
interface HTMLElement {
|
||||
addEventListener(cb: Function);
|
||||
@ -888,7 +888,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in "requestAnimationFrame" as static', async() => {
|
||||
it('should not mark queries used in "requestAnimationFrame" as static', async () => {
|
||||
writeFile('/lib.dom.d.ts', `declare function requestAnimationFrame(cb: Function);`);
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ElementRef, ${queryType}} from '@angular/core';
|
||||
@ -913,8 +913,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries used in immediately-invoked function expression as static', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should mark queries used in immediately-invoked function expression as static',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@Component({template: '<span #test></span>'})
|
||||
@ -934,15 +935,15 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used in external function-like declaration', async() => {
|
||||
it('should detect static queries used in external function-like declaration', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {externalFn} from './external';
|
||||
@ -971,7 +972,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used through getter property access', async() => {
|
||||
it('should detect static queries used through getter property access', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -995,7 +996,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used through external getter access', async() => {
|
||||
it('should detect static queries used through external getter access', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {External} from './external';
|
||||
@ -1033,8 +1034,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries as static if a value is assigned to accessor property', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should not mark queries as static if a value is assigned to accessor property',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@Component({template: '<span #test></span>'})
|
||||
@ -1052,13 +1054,13 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries as static if non-input setter uses query', async() => {
|
||||
it('should mark queries as static if non-input setter uses query', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1083,7 +1085,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should check setter and getter when using compound assignment', async() => {
|
||||
it('should check setter and getter when using compound assignment', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1111,7 +1113,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should check getters when using comparison operator in binary expression', async() => {
|
||||
it('should check getters when using comparison operator in binary expression', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1136,7 +1138,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should check derived abstract class methods', async() => {
|
||||
it('should check derived abstract class methods', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1172,7 +1174,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries accessed through deep abstract class method', async() => {
|
||||
it('should detect queries accessed through deep abstract class method', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1204,7 +1206,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries accessed through abstract property getter', async() => {
|
||||
it('should detect queries accessed through abstract property getter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1230,7 +1232,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries accessed through abstract property setter', async() => {
|
||||
it('should detect queries accessed through abstract property setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1257,8 +1259,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect query usage in abstract class methods accessing inherited query', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should detect query usage in abstract class methods accessing inherited query',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
export abstract class RootBaseClass {
|
||||
@ -1287,13 +1290,13 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect query usage within component template', async() => {
|
||||
it('should detect query usage within component template', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1314,8 +1317,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect query usage with nested property read within component template', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should detect query usage with nested property read within component template',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@Component({templateUrl: 'my-template.html'})
|
||||
@ -1324,19 +1328,19 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
writeFile(`/my-template.html`, `
|
||||
writeFile(`/my-template.html`, `
|
||||
<foo #test></foo>
|
||||
<comp [dir]="query.someProperty"></comp>
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark query as static if template has template reference with same name',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1360,7 +1364,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
});
|
||||
|
||||
it('should not mark query as static if template has property read with query name but different receiver',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1385,7 +1389,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) someProp: any;`);
|
||||
});
|
||||
|
||||
it('should ignore queries accessed within <ng-template> element', async() => {
|
||||
it('should ignore queries accessed within <ng-template> element', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1409,7 +1413,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect inherited queries used in templates', async() => {
|
||||
it('should detect inherited queries used in templates', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1433,7 +1437,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
});
|
||||
|
||||
it('should mark queries which could be accessed statically within third-party calls as ambiguous',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {thirdPartySync} from 'my-lib';
|
||||
@ -1458,18 +1462,18 @@ describe('static-queries migration with usage strategy', () => {
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`@${queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
.toContain(`@${
|
||||
queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`@${queryType}('test', /* TODO: check static flag */ { static: true }) query2: any;`);
|
||||
.toContain(`@${
|
||||
queryType}('test', /* TODO: check static flag */ { static: true }) query2: any;`);
|
||||
expect(warnOutput.length).toBe(2);
|
||||
expect(warnOutput[0]).toContain('Query timing is ambiguous.');
|
||||
expect(warnOutput[1]).toContain('Query timing is ambiguous.');
|
||||
});
|
||||
|
||||
it('should mark queries which could be accessed statically within third-party new expressions as ambiguous',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {ThirdParty} from 'my-lib';
|
||||
@ -1493,15 +1497,15 @@ describe('static-queries migration with usage strategy', () => {
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`@${queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
.toContain(`@${
|
||||
queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
expect(warnOutput.length).toBe(1);
|
||||
expect(warnOutput[0])
|
||||
.toContain(
|
||||
'Query timing is ambiguous. Please check if the query can be marked as dynamic');
|
||||
});
|
||||
|
||||
it('should properly handle multiple tsconfig files', async() => {
|
||||
it('should properly handle multiple tsconfig files', async () => {
|
||||
writeFile('/src/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1526,7 +1530,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should support function call with default parameter value', async() => {
|
||||
it('should support function call with default parameter value', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
|
@ -62,7 +62,7 @@ describe('template variable assignment migration', () => {
|
||||
return runner.runSchematicAsync('migration-v8-template-local-variables', {}, tree).toPromise();
|
||||
}
|
||||
|
||||
it('should warn for two-way data binding variable assignment', async() => {
|
||||
it('should warn for two-way data binding variable assignment', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -78,7 +78,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput[0]).toMatch(/^⮑ {3}index.ts@5:69: Found assignment/);
|
||||
});
|
||||
|
||||
it('should warn for two-way data binding assigning to "as" variable', async() => {
|
||||
it('should warn for two-way data binding assigning to "as" variable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -100,7 +100,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput).toMatch(/^⮑ {3}tmpl.html@3:31: Found assignment/);
|
||||
});
|
||||
|
||||
it('should warn for bound event assignments to "as" variable', async() => {
|
||||
it('should warn for bound event assignments to "as" variable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -124,7 +124,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput[1]).toMatch(/^⮑ {3}sub_dir\/tmpl.html@4:25: Found assignment/);
|
||||
});
|
||||
|
||||
it('should warn for bound event assignments to template "let" variables', async() => {
|
||||
it('should warn for bound event assignments to template "let" variables', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -148,7 +148,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput[1]).toMatch(/^⮑ {3}sub_dir\/tmpl.html@4:25: Found assignment/);
|
||||
});
|
||||
|
||||
it('should not warn for bound event assignments to component property', async() => {
|
||||
it('should not warn for bound event assignments to component property', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -166,7 +166,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
it('should not warn for bound event assignments to template variable object property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -186,7 +186,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
it('should not warn for property writes with template variable name but different receiver',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -211,7 +211,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should warn for template variable assignments in expression conditional', async() => {
|
||||
it('should warn for template variable assignments in expression conditional', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -236,7 +236,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
it('should not warn for property writes with template variable name but different scope',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -259,7 +259,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
|
||||
it('should not throw an error if a detected template fails parsing', async() => {
|
||||
it('should not throw an error if a detected template fails parsing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -276,7 +276,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should be able to report multiple templates within the same source file', async() => {
|
||||
it('should be able to report multiple templates within the same source file', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
|
@ -83,7 +83,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
`);
|
||||
}
|
||||
|
||||
it('should print a failure message base class is declared through type definition', async() => {
|
||||
it('should print a failure message base class is declared through type definition', async () => {
|
||||
writeFile('/node_modules/my-lib/package.json', JSON.stringify({
|
||||
version: '0.0.0',
|
||||
main: './index.js',
|
||||
@ -121,7 +121,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
'dependency injection. Please manually fix the following failures');
|
||||
});
|
||||
|
||||
it('should add @Directive() decorator to extended base class', async() => {
|
||||
it('should add @Directive() decorator to extended base class', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -149,8 +149,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toMatch(/@Directive\(\)\nexport class BaseClass2 {/);
|
||||
});
|
||||
|
||||
it('not decorated base class multiple times if extended multiple times', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('not decorated base class multiple times if extended multiple times', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
export class BaseClass {
|
||||
@ -169,7 +169,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
@Directive()
|
||||
export class BaseClass {
|
||||
@ -177,7 +177,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should add @Injectable() decorator to extended base class', async() => {
|
||||
it('should add @Injectable() decorator to extended base class', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Injectable, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -197,8 +197,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
|
||||
it('should not decorate base class for decorated pipe', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not decorate base class for decorated pipe', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule, Pipe, PipeTransform} from '@angular/core';
|
||||
|
||||
@Pipe({name: 'test'})
|
||||
@ -213,13 +213,13 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput.length).toBe(0);
|
||||
expect(warnOutput.length).toBe(0);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Pipe({name: 'test'})
|
||||
export class MyPipe extends PipeTransform {}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class if no constructor is inherited', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not decorate base class if no constructor is inherited', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule, Directive} from '@angular/core';
|
||||
|
||||
export class BaseClassWithoutCtor {
|
||||
@ -238,7 +238,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
export class BaseClassWithoutCtor {
|
||||
someUnrelatedProp = true;
|
||||
@ -252,8 +252,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should not decorate base class if directive/component/provider defines a constructor',
|
||||
async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, Injectable, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
export class BaseClass {
|
||||
@ -284,15 +284,15 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
export class BaseClass {
|
||||
constructor(zone: NgZone) {}
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class if it already has decorator', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not decorate base class if it already has decorator', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, Directive, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@Directive({selector: 'base-class'})
|
||||
@ -312,13 +312,13 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
@Directive({selector: 'base-class'})
|
||||
export class BaseClass {`);
|
||||
});
|
||||
|
||||
it('should add a comment if the base class is declared through type definition', async() => {
|
||||
it('should add a comment if the base class is declared through type definition', async () => {
|
||||
writeFile('/node_modules/my-lib/package.json', JSON.stringify({
|
||||
version: '0.0.0',
|
||||
main: './index.js',
|
||||
@ -332,7 +332,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, Injectable, NgModule} from '@angular/core';
|
||||
import {SuperBaseClass} from 'my-lib';
|
||||
|
||||
@ -365,42 +365,42 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive()
|
||||
export class BaseClass extends SuperBaseClass {
|
||||
// TODO: add explicit constructor
|
||||
}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Injectable()
|
||||
export class BaseClass2 extends SuperBaseClass {
|
||||
// TODO: add explicit constructor
|
||||
}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive()
|
||||
export class PassThroughClass extends BaseClass {}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends PassThroughClass {}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent3 extends SuperBaseClass {
|
||||
// TODO: add explicit constructor
|
||||
}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Injectable()
|
||||
export class MyService extends BaseClass2 {}`);
|
||||
});
|
||||
|
||||
it('should not add a comment if the base class is declared through type definition but is' +
|
||||
'decorated',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFakeLibrary();
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -413,14 +413,14 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends BaseComponent {}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class in typings if it misses an explicit constructor', async() => {
|
||||
it('should not decorate base class in typings if it misses an explicit constructor', async () => {
|
||||
writeFakeLibrary();
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseDirective} from 'my-lib';
|
||||
|
||||
@ -433,16 +433,16 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends BaseDirective {}`);
|
||||
expect(tree.readContent('/node_modules/my-lib/public-api.d.ts')).not.toContain('@Directive');
|
||||
});
|
||||
|
||||
it('should detect decorated classes by respecting summary files', async() => {
|
||||
it('should detect decorated classes by respecting summary files', async () => {
|
||||
writeSummaryOnlyThirdPartyLibrary();
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -457,12 +457,12 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(warnOutput.length).toBe(0);
|
||||
expect(errorOutput.length).toBe(0);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends BaseComponent {}`);
|
||||
});
|
||||
|
||||
it('should decorate all undecorated directives of inheritance chain', async() => {
|
||||
it('should decorate all undecorated directives of inheritance chain', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -486,7 +486,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
.toMatch(/}\s+@Directive\(\)\nexport class BaseClass extends SuperBaseClass {/);
|
||||
});
|
||||
|
||||
it('should decorate all undecorated providers of inheritance chain', async() => {
|
||||
it('should decorate all undecorated providers of inheritance chain', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Injectable, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -511,7 +511,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should properly update import if @Directive can be accessed through existing namespace import',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
import {BaseClass} from './base';
|
||||
@ -537,7 +537,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should properly update existing import with aliased specifier if identifier is already used',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
import {Directive} from './third_party_directive';
|
||||
@ -561,7 +561,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should properly create new import with aliased specifier if identifier is already used',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
import {BaseClass} from './base';
|
||||
@ -590,8 +590,9 @@ describe('Undecorated classes with DI migration', () => {
|
||||
.toContain(`{ Directive as Directive_1 } from "@angular/core";`);
|
||||
});
|
||||
|
||||
it('should use existing aliased import of @Directive instead of creating new import', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should use existing aliased import of @Directive instead of creating new import',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseClass} from './base';
|
||||
|
||||
@ -602,7 +603,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/base.ts', `
|
||||
writeFile('/base.ts', `
|
||||
import {Directive as AliasedDir, NgZone} from '@angular/core';
|
||||
|
||||
export class BaseClass {
|
||||
@ -610,15 +611,14 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/base.ts')).toMatch(/@AliasedDir\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
expect(tree.readContent('/base.ts')).toMatch(/@AliasedDir\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
|
||||
describe('decorator copying', async() => {
|
||||
|
||||
it('should be able to copy the "templateUrl" field', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
describe('decorator copying', async () => {
|
||||
it('should be able to copy the "templateUrl" field', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -628,7 +628,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Directive, NgModule} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
@ -645,7 +645,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { NgModule, Directive } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive({
|
||||
selector: 'my-dir',
|
||||
templateUrl: './my-dir.html'
|
||||
@ -653,8 +653,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy the "styleUrls" field', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should be able to copy the "styleUrls" field', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -664,7 +664,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Directive, NgModule} from '@angular/core';
|
||||
|
||||
/** my comment */
|
||||
@ -680,7 +680,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@Directive({
|
||||
@ -690,8 +690,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy @Pipe decorator', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should be able to copy @Pipe decorator', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BasePipe} from './lib/base';
|
||||
|
||||
@ -701,7 +701,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Pipe, NgModule} from '@angular/core';
|
||||
|
||||
@Pipe({name: 'my-pipe-name'})
|
||||
@ -715,16 +715,16 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { NgModule, Pipe } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Pipe({ name: 'my-pipe-name' })
|
||||
export class MyPipe extends BasePipe {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy decorator in same source file', async() => {
|
||||
it('should be able to copy decorator in same source file', async () => {
|
||||
writeFile(
|
||||
'/node_modules/@angular/cdk/table/index.d.ts',
|
||||
`export declare const CDK_TABLE_TEMPLATE = '';`);
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule, Component} from '@angular/core';
|
||||
import {CDK_TABLE_TEMPLATE} from '@angular/cdk/table';
|
||||
|
||||
@ -748,7 +748,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: CDK_TABLE_TEMPLATE,
|
||||
@ -757,8 +757,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to create new imports for copied identifier references', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should be able to create new imports for copied identifier references', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -772,7 +772,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
'/node_modules/@angular/cdk/table/index.d.ts',
|
||||
`export declare const CDK_TABLE_TEMPLATE = '';`);
|
||||
writeFile('/styles.ts', `export const STYLE_THROUGH_VAR = 'external';`);
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {CDK_TABLE_TEMPLATE as tableTmpl} from '@angular/cdk/table';
|
||||
import {STYLE_THROUGH_VAR} from '../styles';
|
||||
@ -798,7 +798,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
.toContain(`import { STYLE_THROUGH_VAR } from "./styles";`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { BaseClass, LOCAL_STYLE } from './lib/base';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: CDK_TABLE_TEMPLATE,
|
||||
@ -807,8 +807,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should copy decorator once if directive is referenced multiple times', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should copy decorator once if directive is referenced multiple times', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -818,7 +818,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/second-module.ts', dedent `
|
||||
writeFile('/second-module.ts', dedent`
|
||||
import {NgModule, Directive} from '@angular/core';
|
||||
import {MyComp} from './index';
|
||||
|
||||
@ -829,7 +829,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MySecondModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
@ -844,7 +844,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@Component({
|
||||
@ -854,8 +854,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should create aliased imports to avoid collisions for referenced identifiers', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should create aliased imports to avoid collisions for referenced identifiers', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -869,7 +869,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
export const MY_TEMPLATE = '';
|
||||
@ -888,7 +888,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { BaseClass, MY_TEMPLATE as MY_TEMPLATE_1 } from './lib/base';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: MY_TEMPLATE_1
|
||||
@ -896,8 +896,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should add comment for metadata fields which cannot be copied', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should add comment for metadata fields which cannot be copied', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -907,7 +907,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule, Document} from '@angular/core';
|
||||
|
||||
// this variable cannot be imported automatically.
|
||||
@ -926,7 +926,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: '',
|
||||
@ -940,8 +940,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should add comment for metadata fields which are added through spread operator',
|
||||
async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -951,7 +951,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
export const metadataThroughVar = {
|
||||
@ -971,7 +971,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: '',
|
||||
@ -984,10 +984,10 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy fields specified through shorthand assignment', async() => {
|
||||
it('should be able to copy fields specified through shorthand assignment', async () => {
|
||||
writeFile('/hello.css', '');
|
||||
writeFile('/my-tmpl.html', '');
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -999,7 +999,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
writeFile('/lib/hello.css', '');
|
||||
writeFile('/lib/my-tmpl.html', '');
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
export const host = {};
|
||||
@ -1022,7 +1022,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { BaseClass, templateUrl, host } from './lib/base';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
templateUrl,
|
||||
@ -1036,10 +1036,10 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should serialize metadata from base class without source code', async() => {
|
||||
it('should serialize metadata from base class without source code', async () => {
|
||||
writeFakeLibrary();
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseComponent, BasePipe} from 'my-lib';
|
||||
|
||||
@ -1061,7 +1061,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`import { NgModule, ChangeDetectionStrategy, ViewEncapsulation, NG_VALIDATORS, Component, Pipe } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
selector: "comp-selector",
|
||||
@ -1077,7 +1077,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
})
|
||||
export class PassThrough extends BaseComponent {}`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
selector: "comp-selector",
|
||||
@ -1093,7 +1093,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
})
|
||||
export class MyComp extends PassThrough {}`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Pipe({
|
||||
pure: true,
|
||||
name: "external-pipe-name"
|
||||
@ -1101,12 +1101,12 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyPipe extends BasePipe {}`);
|
||||
});
|
||||
|
||||
it('should serialize metadata with external references from class without source code', async() => {
|
||||
it('should serialize metadata with external references from class without source code', async () => {
|
||||
writeFakeLibrary({useImportedTemplate: true});
|
||||
writeFile(
|
||||
'/node_modules/@angular/cdk/table/index.d.ts',
|
||||
`export declare const CDK_TABLE_TEMPLATE = 'Template of CDK Table.';`);
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -1121,7 +1121,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`import { NgModule, ChangeDetectionStrategy, ViewEncapsulation, NG_VALIDATORS, Component } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
selector: "comp-selector",
|
||||
@ -1140,10 +1140,10 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should not throw if metadata from base class without source code is not serializable',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFakeLibrary({insertInvalidReference: true});
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -1159,8 +1159,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput[0]).toMatch(/Could not resolve non-existent/);
|
||||
});
|
||||
|
||||
it('should not create imports for identifiers resolving to target source file', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not create imports for identifiers resolving to target source file', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -1175,7 +1175,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export {LOCAL_NAME as PUBLIC_NAME};
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Directive, NgModule} from '@angular/core';
|
||||
import {SHARED_TEMPLATE_URL, PUBLIC_NAME} from '..';
|
||||
|
||||
@ -1194,7 +1194,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { NgModule, Directive } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive({
|
||||
selector: 'my-dir',
|
||||
template: SHARED_TEMPLATE_URL,
|
||||
@ -1388,7 +1388,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}));
|
||||
}
|
||||
|
||||
it('should not run for test tsconfig files', async() => {
|
||||
it('should not run for test tsconfig files', async () => {
|
||||
writeFile('/src/tsconfig.spec.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
lib: ['es2015'],
|
||||
@ -1429,8 +1429,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
describe('diagnostics', async() => {
|
||||
it('should gracefully exit migration if project fails with structural diagnostic', async() => {
|
||||
describe('diagnostics', async () => {
|
||||
it('should gracefully exit migration if project fails with structural diagnostic', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@ -1455,28 +1455,29 @@ describe('Undecorated classes with DI migration', () => {
|
||||
'TypeScript program failures');
|
||||
});
|
||||
|
||||
it('should gracefully exit migration if project fails with syntactical diagnostic', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should gracefully exit migration if project fails with syntactical diagnostic',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} /* missing "from" */ '@angular/core';
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(warnOutput.length).toBe(1);
|
||||
expect(warnOutput[0])
|
||||
.toMatch(/project "tsconfig.json" has syntactical errors which could cause/);
|
||||
expect(errorOutput.length).toBe(1);
|
||||
expect(errorOutput[0]).toMatch(/error TS1005: 'from' expected/);
|
||||
expect(infoOutput.join(' '))
|
||||
.toContain(
|
||||
'Some project targets could not be analyzed due to ' +
|
||||
'TypeScript program failures');
|
||||
});
|
||||
expect(warnOutput.length).toBe(1);
|
||||
expect(warnOutput[0])
|
||||
.toMatch(/project "tsconfig.json" has syntactical errors which could cause/);
|
||||
expect(errorOutput.length).toBe(1);
|
||||
expect(errorOutput[0]).toMatch(/error TS1005: 'from' expected/);
|
||||
expect(infoOutput.join(' '))
|
||||
.toContain(
|
||||
'Some project targets could not be analyzed due to ' +
|
||||
'TypeScript program failures');
|
||||
});
|
||||
|
||||
// Regression test for: https://github.com/angular/angular/issues/34985.
|
||||
it('should be able to migrate libraries with multiple source files and flat-module ' +
|
||||
'options set',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/tsconfig.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
lib: ['es2015'],
|
||||
@ -1507,7 +1508,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/test.ts')).toMatch(/@Injectable\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
|
||||
it('should not throw if resources could not be read', async() => {
|
||||
it('should not throw if resources could not be read', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@ -1529,7 +1530,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should not throw if tsconfig references non-existent source file', async() => {
|
||||
it('should not throw if tsconfig references non-existent source file', async () => {
|
||||
writeFile('/tsconfig.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
lib: ['es2015'],
|
||||
|
Reference in New Issue
Block a user