From b5e6319fa9a6f82b210f25ce44dc9fa7142b3fad Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 18 Feb 2016 13:51:20 -0800 Subject: [PATCH] feat(core): add more debug APIs to inspect the application form a browser Adds `window.getAllAngularRootElements()` Adds `ng.coreTokens.ApplicationRef` Adds `ng.coreTokens.Ngzone` Closes #7045 Closes #7161 --- modules/angular2/src/core/testability/testability.ts | 2 ++ modules/angular2/src/facade/lang.ts | 1 + modules/angular2/src/platform/browser/testability.ts | 2 ++ modules/angular2/src/platform/dom/debug/ng_probe.ts | 5 ++++- modules/angular2/test/public_api_spec.ts | 1 + tools/public_api_guard/public_api_spec.ts | 1 + 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/core/testability/testability.ts b/modules/angular2/src/core/testability/testability.ts index f8cb22bf47..d15690d15a 100644 --- a/modules/angular2/src/core/testability/testability.ts +++ b/modules/angular2/src/core/testability/testability.ts @@ -118,6 +118,8 @@ export class TestabilityRegistry { getAllTestabilities(): Testability[] { return MapWrapper.values(this._applications); } + getAllRootElements(): any[] { return MapWrapper.keys(this._applications); } + findTestabilityInTree(elem: Node, findInAncestors: boolean = true): Testability { return _testabilityGetter.findTestabilityInTree(this, elem, findInAncestors); } diff --git a/modules/angular2/src/facade/lang.ts b/modules/angular2/src/facade/lang.ts index b1dd056830..eee138d4fc 100644 --- a/modules/angular2/src/facade/lang.ts +++ b/modules/angular2/src/facade/lang.ts @@ -24,6 +24,7 @@ export interface BrowserNodeGlobal { Zone: ZoneLikeConstructor; getAngularTestability: Function; getAllAngularTestabilities: Function; + getAllAngularRootElements: Function; frameworkStabilizers: Array; setTimeout: Function; clearTimeout: Function; diff --git a/modules/angular2/src/platform/browser/testability.ts b/modules/angular2/src/platform/browser/testability.ts index 5d1a637779..7b45856a20 100644 --- a/modules/angular2/src/platform/browser/testability.ts +++ b/modules/angular2/src/platform/browser/testability.ts @@ -49,6 +49,8 @@ export class BrowserGetTestability implements GetTestability { return testabilities.map((testability) => { return new PublicTestability(testability); }); }; + global.getAllAngularRootElements = () => registry.getAllRootElements(); + var whenAllStable = (callback) => { var testabilities = global.getAllAngularTestabilities(); var count = testabilities.length; diff --git a/modules/angular2/src/platform/dom/debug/ng_probe.ts b/modules/angular2/src/platform/dom/debug/ng_probe.ts index 61bc6b9e71..6087a4d06c 100644 --- a/modules/angular2/src/platform/dom/debug/ng_probe.ts +++ b/modules/angular2/src/platform/dom/debug/ng_probe.ts @@ -3,11 +3,13 @@ import {Injectable, provide, Provider} from 'angular2/src/core/di'; import {DOM} from 'angular2/src/platform/dom/dom_adapter'; import {DebugNode, getDebugNode} from 'angular2/src/core/debug/debug_node'; import {DomRootRenderer} from 'angular2/src/platform/dom/dom_renderer'; -import {RootRenderer} from 'angular2/core'; +import {RootRenderer, NgZone, ApplicationRef} from 'angular2/core'; import {DebugDomRootRenderer} from 'angular2/src/core/debug/debug_renderer'; +const CORE_TOKENS = CONST_EXPR({'ApplicationRef': ApplicationRef, 'NgZone': NgZone}); const INSPECT_GLOBAL_NAME = 'ng.probe'; +const CORE_TOKENS_GLOBAL_NAME = 'ng.coreTokens'; /** * Returns a {@link DebugElement} for the given native DOM element, or @@ -27,6 +29,7 @@ function _createConditionalRootRenderer(rootRenderer) { function _createRootRenderer(rootRenderer) { DOM.setGlobalVar(INSPECT_GLOBAL_NAME, inspectNativeElement); + DOM.setGlobalVar(CORE_TOKENS_GLOBAL_NAME, CORE_TOKENS); return new DebugDomRootRenderer(rootRenderer); } diff --git a/modules/angular2/test/public_api_spec.ts b/modules/angular2/test/public_api_spec.ts index 65627df495..7fb93690b0 100644 --- a/modules/angular2/test/public_api_spec.ts +++ b/modules/angular2/test/public_api_spec.ts @@ -1308,6 +1308,7 @@ var NG_CORE = [ 'TestabilityRegistry', 'TestabilityRegistry.findTestabilityInTree()', 'TestabilityRegistry.getAllTestabilities()', + 'TestabilityRegistry.getAllRootElements()', 'TestabilityRegistry.getTestability()', 'TestabilityRegistry.registerApplication()', 'GetTestability:dart', diff --git a/tools/public_api_guard/public_api_spec.ts b/tools/public_api_guard/public_api_spec.ts index c48bae6755..09a0e044c6 100644 --- a/tools/public_api_guard/public_api_spec.ts +++ b/tools/public_api_guard/public_api_spec.ts @@ -440,6 +440,7 @@ const CORE = [ 'TestabilityRegistry.constructor()', 'TestabilityRegistry.findTestabilityInTree(elem:Node, findInAncestors:boolean):Testability', 'TestabilityRegistry.getAllTestabilities():Testability[]', + 'TestabilityRegistry.getAllRootElements():any[]', 'TestabilityRegistry.getTestability(elem:any):Testability', 'TestabilityRegistry.registerApplication(token:any, testability:Testability):any', 'TrackByFn',