From d2cfc6a719c4470457259a5eb979f16a7bef67ba Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Wed, 3 Jan 2018 10:45:09 +0100 Subject: [PATCH] build: activate render3 tests in CI (#21279) PR Close #21279 --- karma-js.conf.js | 1 - packages/core/src/render3/instructions.ts | 10 ++++++++++ packages/core/test/render3/component_spec.ts | 14 +++++++------- packages/core/test/render3/render_util.ts | 5 ++++- .../core/test/render3/renderer_factory_spec.ts | 6 +++--- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/karma-js.conf.js b/karma-js.conf.js index 50b812b9d6..4c5a80083f 100644 --- a/karma-js.conf.js +++ b/karma-js.conf.js @@ -58,7 +58,6 @@ module.exports = function(config) { 'dist/all/@angular/**/*node_only_spec.js', 'dist/all/@angular/benchpress/**', 'dist/all/@angular/compiler-cli/**', - 'dist/all/@angular/core/test/render3/**', 'dist/all/@angular/compiler/test/aot/**', 'dist/all/@angular/examples/**/e2e_test/*', 'dist/all/@angular/language-service/**', diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index 15862a9f2a..cd8f6b268d 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -264,6 +264,14 @@ export function createLNode( //// Render ////////////////////////// +/** + * Resets the application state. + */ +function resetApplicationState() { + isParent = false; + previousOrParentNode = null !; +} + /** * * @param host Existing node to render into. @@ -274,6 +282,7 @@ export function renderTemplate( hostNode: RElement, template: ComponentTemplate, context: T, providedRendererFactory: RendererFactory3, host: LElement | null): LElement { if (host == null) { + resetApplicationState(); rendererFactory = providedRendererFactory; host = createLNode( null, LNodeFlags.Element, hostNode, @@ -499,6 +508,7 @@ export function locateHostElement( * @param rNode Render host element. */ export function hostElement(rNode: RElement | null, def: ComponentDef) { + resetApplicationState(); createLNode( 0, LNodeFlags.Element, rNode, createViewState(-1, renderer, getTemplateStatic(def.template))); } diff --git a/packages/core/test/render3/component_spec.ts b/packages/core/test/render3/component_spec.ts index 1d54685d31..88c21aeea0 100644 --- a/packages/core/test/render3/component_spec.ts +++ b/packages/core/test/render3/component_spec.ts @@ -8,7 +8,7 @@ import {ViewEncapsulation} from '../../src/core'; import {D, E, T, b, defineComponent, e, markDirty, t} from '../../src/render3/index'; -import {createRendererType2} from '../../src/view'; +import {createRendererType2} from '../../src/view/index'; import {getRendererFactory2} from './imported_renderer2'; import {containerEl, renderComponent, requestAnimationFrame} from './render_util'; @@ -117,15 +117,15 @@ describe('encapsulation', () => { it('should encapsulate children, but not host nor grand children', () => { renderComponent(WrapperComponent, getRendererFactory2(document)); expect(containerEl.outerHTML) - .toEqual( - '
foobar
'); + .toMatch( + /
foobar<\/span><\/leaf><\/encapsulated><\/div>/); }); it('should encapsulate host', () => { renderComponent(EncapsulatedComponent, getRendererFactory2(document)); expect(containerEl.outerHTML) - .toEqual( - '
foobar
'); + .toMatch( + /
foobar<\/span><\/leaf><\/div>/); }); it('should encapsulate host and children with different attributes', () => { @@ -167,7 +167,7 @@ describe('encapsulation', () => { renderComponent(WrapperComponentWith, getRendererFactory2(document)); expect(containerEl.outerHTML) - .toEqual( - '
bar
'); + .toMatch( + /
bar<\/span><\/leaf><\/div>/); }); }); diff --git a/packages/core/test/render3/render_util.ts b/packages/core/test/render3/render_util.ts index d08b7808b3..0602cf0005 100644 --- a/packages/core/test/render3/render_util.ts +++ b/packages/core/test/render3/render_util.ts @@ -35,7 +35,10 @@ requestAnimationFrame.flush = function() { export function resetDOM() { requestAnimationFrame.queue = []; if (containerEl) { - document.body.removeChild(containerEl); + try { + document.body.removeChild(containerEl); + } catch (e) { + } } containerEl = document.createElement('div'); containerEl.setAttribute('host', ''); diff --git a/packages/core/test/render3/renderer_factory_spec.ts b/packages/core/test/render3/renderer_factory_spec.ts index dc5eadcadf..3640d91823 100644 --- a/packages/core/test/render3/renderer_factory_spec.ts +++ b/packages/core/test/render3/renderer_factory_spec.ts @@ -10,8 +10,8 @@ import {AnimationEvent} from '@angular/animations'; import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing'; import {RendererType2, ViewEncapsulation} from '../../src/core'; -import {D, E, L, T, b, defineComponent, detectChanges, e, p} from '../../src/render3'; -import {createRendererType2} from '../../src/view'; +import {D, E, L, T, b, defineComponent, detectChanges, e, p} from '../../src/render3/index'; +import {createRendererType2} from '../../src/view/index'; import {getAnimationRendererFactory2, getRendererFactory2} from './imported_renderer2'; import {containerEl, document, renderComponent, renderToHtml} from './render_util'; @@ -185,7 +185,7 @@ describe('animation renderer factory', () => { const factory = getAnimationRendererFactory2(document); const component = renderComponent(SomeComponentWithAnimation, factory); expect(containerEl.innerHTML) - .toEqual('
foo
'); + .toMatch(/
foo<\/div>/); component.exp = 'on'; detectChanges(component);