test(core): fix schematics calls to run synchronously (#34364)

Previously the calls to run the schematics were not being properly
or consistently awaited in the tests. While this currently does not
affect the tests' performance, this fix corrects the syntax and
adds stability for future changes.

PR Close #34364
This commit is contained in:
Adam Plumer 2019-12-12 00:06:34 -06:00 committed by Kara Erickson
parent 6e7ca05efc
commit 3255d2b197
8 changed files with 225 additions and 226 deletions

View File

@ -160,6 +160,6 @@ describe('dynamic queries migration', () => {
} }
function runMigration() { function runMigration() {
runner.runSchematicAsync('migration-v9-dynamic-queries', {}, tree).toPromise(); return runner.runSchematicAsync('migration-v9-dynamic-queries', {}, tree).toPromise();
} }
}); });

View File

@ -63,8 +63,8 @@ describe('Missing injectable migration', () => {
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
} }
async function runMigration() { function runMigration() {
await runner.runSchematicAsync('migration-v9-missing-injectable', {}, tree).toPromise(); return runner.runSchematicAsync('migration-v9-missing-injectable', {}, tree).toPromise();
} }
describe('NgModule', () => createTests('NgModule', 'providers')); describe('NgModule', () => createTests('NgModule', 'providers'));

View File

@ -230,6 +230,6 @@ describe('ModuleWithProviders migration', () => {
} }
function runMigration() { function runMigration() {
runner.runSchematicAsync('migration-v9-module-with-providers', {}, tree).toPromise(); return runner.runSchematicAsync('migration-v9-module-with-providers', {}, tree).toPromise();
} }
}); });

View File

@ -165,6 +165,6 @@ describe('move-document migration', () => {
} }
function runMigration() { function runMigration() {
runner.runSchematicAsync('migration-v8-move-document', {}, tree).toPromise(); return runner.runSchematicAsync('migration-v8-move-document', {}, tree).toPromise();
} }
}); });

View File

@ -100,8 +100,8 @@ describe('static-queries migration with template strategy', () => {
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
} }
async function runMigration() { function runMigration() {
await runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise(); return runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise();
} }
describe('ViewChild', () => { describe('ViewChild', () => {

View File

@ -172,8 +172,8 @@ describe('static-queries migration with usage strategy', () => {
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
} }
async function runMigration() { function runMigration() {
await runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise(); return runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise();
} }
function createQueryTests(queryType: 'ViewChild' | 'ContentChild') { function createQueryTests(queryType: 'ViewChild' | 'ContentChild') {

View File

@ -68,13 +68,12 @@ describe('Undecorated classes with DI migration', () => {
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents)); host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
} }
async function runMigration() { function runMigration() {
return runner.runSchematicAsync('migration-v9-undecorated-classes-with-di', {}, tree) return runner.runSchematicAsync('migration-v9-undecorated-classes-with-di', {}, tree)
.toPromise(); .toPromise();
} }
function function writeFakeAngular() {
writeFakeAngular() {
writeFile('/node_modules/@angular/core/index.d.ts', ` writeFile('/node_modules/@angular/core/index.d.ts', `
export declare class PipeTransform {} export declare class PipeTransform {}
export declare class NgZone {} export declare class NgZone {}

View File

@ -22,7 +22,7 @@ export function createMigrationCompilerHost(
const treeRelativePath = relative(basePath, fileName); const treeRelativePath = relative(basePath, fileName);
const fakeOutput = fakeRead ? fakeRead(treeRelativePath) : null; const fakeOutput = fakeRead ? fakeRead(treeRelativePath) : null;
const buffer = fakeOutput === null ? tree.read(treeRelativePath) : fakeOutput; const buffer = fakeOutput === null ? tree.read(treeRelativePath) : fakeOutput;
// Strip BOM as otherwise TSC methods (Ex: getWidth) will return an offset which // Strip BOM as otherwise TSC methods (Ex: getWidth) will return an offset,
// which breaks the CLI UpdateRecorder. // which breaks the CLI UpdateRecorder.
// See: https://github.com/angular/angular/pull/30719 // See: https://github.com/angular/angular/pull/30719
return buffer ? buffer.toString().replace(/^\uFEFF/, '') : undefined; return buffer ? buffer.toString().replace(/^\uFEFF/, '') : undefined;