From a2330ff2dbdb432b75b42f54af0af0cef7404ded Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Wed, 14 Mar 2018 00:17:09 -0700 Subject: [PATCH] fix(upgrade): propagate return value of resumeBootstrap (#22754) Fixes #22723 PR Close #22754 --- .../upgrade/src/dynamic/upgrade_adapter.ts | 3 ++- packages/upgrade/src/static/upgrade_module.ts | 2 +- packages/upgrade/test/dynamic/upgrade_spec.ts | 23 +++++++++++++++++++ .../static/integration/testability_spec.ts | 21 ++++++++++++++++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/packages/upgrade/src/dynamic/upgrade_adapter.ts b/packages/upgrade/src/dynamic/upgrade_adapter.ts index 00c52dff49..d41b49cf6b 100644 --- a/packages/upgrade/src/dynamic/upgrade_adapter.ts +++ b/packages/upgrade/src/dynamic/upgrade_adapter.ts @@ -389,8 +389,9 @@ export class UpgradeAdapter { const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap; windowAngular.resumeBootstrap = function() { windowAngular.resumeBootstrap = originalResumeBootstrap; - windowAngular.resumeBootstrap.apply(this, arguments); + const r = windowAngular.resumeBootstrap.apply(this, arguments); resolve(); + return r; }; } else { resolve(); diff --git a/packages/upgrade/src/static/upgrade_module.ts b/packages/upgrade/src/static/upgrade_module.ts index e93305e0df..7eb21efa3a 100644 --- a/packages/upgrade/src/static/upgrade_module.ts +++ b/packages/upgrade/src/static/upgrade_module.ts @@ -268,7 +268,7 @@ export class UpgradeModule { windowAngular.resumeBootstrap = function() { let args = arguments; windowAngular.resumeBootstrap = originalResumeBootstrap; - ngZone.run(() => { windowAngular.resumeBootstrap.apply(this, args); }); + return ngZone.run(() => windowAngular.resumeBootstrap.apply(this, args)); }; } } diff --git a/packages/upgrade/test/dynamic/upgrade_spec.ts b/packages/upgrade/test/dynamic/upgrade_spec.ts index a3e70858f7..159f05c4ae 100644 --- a/packages/upgrade/test/dynamic/upgrade_spec.ts +++ b/packages/upgrade/test/dynamic/upgrade_spec.ts @@ -2909,6 +2909,29 @@ withEachNg1Version(() => { }, 100); })); + it('should propagate return value of resumeBootstrap', fakeAsync(() => { + @NgModule({imports: [BrowserModule]}) + class MyNg2Module { + } + + const adapter: UpgradeAdapter = new UpgradeAdapter(MyNg2Module); + const ng1Module = angular.module('ng1', []); + let a1Injector: angular.IInjectorService|undefined; + ng1Module.run([ + '$injector', function($injector: angular.IInjectorService) { a1Injector = $injector; } + ]); + + const element = html('
'); + window.name = 'NG_DEFER_BOOTSTRAP!' + window.name; + + adapter.bootstrap(element, [ng1Module.name]).ready((ref) => { ref.dispose(); }); + + tick(100); + + const value = (window).angular.resumeBootstrap(); + expect(value).toBe(a1Injector); + })); + it('should wait for ng2 testability', async(() => { @NgModule({imports: [BrowserModule]}) class MyNg2Module { diff --git a/packages/upgrade/test/static/integration/testability_spec.ts b/packages/upgrade/test/static/integration/testability_spec.ts index 73d9712e54..3ceeb0ab9d 100644 --- a/packages/upgrade/test/static/integration/testability_spec.ts +++ b/packages/upgrade/test/static/integration/testability_spec.ts @@ -8,7 +8,7 @@ import {NgModule, Testability, destroyPlatform} from '@angular/core'; import {NgZone} from '@angular/core/src/zone/ng_zone'; -import {fakeAsync, tick} from '@angular/core/testing'; +import {fakeAsync, flush, tick} from '@angular/core/testing'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {UpgradeModule} from '@angular/upgrade/static'; @@ -48,6 +48,25 @@ withEachNg1Version(() => { expect(stayedInTheZone).toEqual(true); })); + it('should propagate return value of resumeBootstrap', fakeAsync(() => { + const ng1Module = angular.module('ng1', []); + let a1Injector: angular.IInjectorService|undefined; + ng1Module.run([ + '$injector', function($injector: angular.IInjectorService) { a1Injector = $injector; } + ]); + const element = html('
'); + window.name = 'NG_DEFER_BOOTSTRAP!' + window.name; + + bootstrap(platformBrowserDynamic(), Ng2Module, element, ng1Module); + + tick(100); + + const value = (window).angular.resumeBootstrap(); + expect(value).toBe(a1Injector); + + flush(); + })); + it('should wait for ng2 testability', fakeAsync(() => { const ng1Module = angular.module('ng1', []); const element = html('
');