From 93ba3cbc27816b9ec92a48896f1a3b62ad8fbd7d Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Fri, 11 Nov 2016 15:51:32 -0800 Subject: [PATCH 1/2] fix: unbreak unit tests --- src/lib/core/overlay/overlay-ref.ts | 12 ++++++++++-- src/lib/core/overlay/overlay.ts | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib/core/overlay/overlay-ref.ts b/src/lib/core/overlay/overlay-ref.ts index 22d18db624c3..b427fa925d27 100644 --- a/src/lib/core/overlay/overlay-ref.ts +++ b/src/lib/core/overlay/overlay-ref.ts @@ -1,3 +1,4 @@ +import {NgZone} from '@angular/core'; import {PortalHost, Portal} from '../portal/portal'; import {OverlayState} from './overlay-state'; import {Observable} from 'rxjs/Observable'; @@ -15,7 +16,8 @@ export class OverlayRef implements PortalHost { constructor( private _portalHost: PortalHost, private _pane: HTMLElement, - private _state: OverlayState) { } + private _state: OverlayState, + private _ngZone: NgZone) { } attach(portal: Portal): any { if (this._state.hasBackdrop) { @@ -124,7 +126,13 @@ export class OverlayRef implements PortalHost { // If the backdrop doesn't have a transition, the `transitionend` event won't fire. // In this case we make it unclickable and we try to remove it after a delay. backdropToDetach.style.pointerEvents = 'none'; - setTimeout(finishDetach, 500); + + // Run this outside the Angular zone because there's nothing that Angular cares about. + // If it were to run inside the Angular zone, every test that used Overlay would have to be + // either async or fakeAsync. + this._ngZone.runOutsideAngular(() => { + setTimeout(finishDetach, 500); + }); } } } diff --git a/src/lib/core/overlay/overlay.ts b/src/lib/core/overlay/overlay.ts index 00b3dae201b8..4310fc00c2c6 100644 --- a/src/lib/core/overlay/overlay.ts +++ b/src/lib/core/overlay/overlay.ts @@ -1,4 +1,4 @@ -import {ComponentFactoryResolver, Injectable, ApplicationRef, Injector} from '@angular/core'; +import {ComponentFactoryResolver, Injectable, ApplicationRef, Injector, NgZone} from '@angular/core'; import {OverlayState} from './overlay-state'; import {DomPortalHost} from '../portal/dom-portal-host'; import {OverlayRef} from './overlay-ref'; @@ -28,7 +28,8 @@ export class Overlay { private _componentFactoryResolver: ComponentFactoryResolver, private _positionBuilder: OverlayPositionBuilder, private _appRef: ApplicationRef, - private _injector: Injector) {} + private _injector: Injector, + private _ngZone: NgZone) {} /** * Creates an overlay. @@ -77,7 +78,7 @@ export class Overlay { * @returns {OverlayRef} */ private _createOverlayRef(pane: HTMLElement, state: OverlayState): OverlayRef { - return new OverlayRef(this._createPortalHost(pane), pane, state); + return new OverlayRef(this._createPortalHost(pane), pane, state, this._ngZone); } } From f6e7d264a70459cb8717b695bb0d0a55ab967557 Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Fri, 11 Nov 2016 15:52:10 -0800 Subject: [PATCH 2/2] Revert "chore(build): fix karma not exiting properly (#1741)" This reverts commit 77701cc1aee30886f2edf1dbd04046a48e845cf2. --- test/karma.config.ts | 1 - tools/gulp/tasks/unit-test.ts | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/karma.config.ts b/test/karma.config.ts index 8d35afc82e71..78d1452808ff 100644 --- a/test/karma.config.ts +++ b/test/karma.config.ts @@ -59,7 +59,6 @@ export function config(config) { colors: true, logLevel: config.LOG_INFO, autoWatch: true, - autoWatchBatchDelay: 500, sauceLabs: { testName: 'material2', diff --git a/tools/gulp/tasks/unit-test.ts b/tools/gulp/tasks/unit-test.ts index f537311944c0..7cfee833eb64 100644 --- a/tools/gulp/tasks/unit-test.ts +++ b/tools/gulp/tasks/unit-test.ts @@ -2,7 +2,7 @@ import gulp = require('gulp'); import path = require('path'); import gulpMerge = require('merge2'); -import {PROJECT_ROOT} from '../constants'; +import {PROJECT_ROOT, DIST_COMPONENTS_ROOT} from '../constants'; import {sequenceTask} from '../task_helpers'; const karma = require('karma'); @@ -48,10 +48,10 @@ gulp.task(':test:deps:inline', sequenceTask(':test:deps', ':inline-resources')); * * This task should be used when running unit tests locally. */ -gulp.task('test', [':test:watch'], () => { +gulp.task('test', [':test:watch'], (done: () => void) => { new karma.Server({ configFile: path.join(PROJECT_ROOT, 'test/karma.conf.js') - }).start(); + }, done).start(); }); /** @@ -59,9 +59,9 @@ gulp.task('test', [':test:watch'], () => { * * This task should be used when running tests on the CI server. */ -gulp.task('test:single-run', [':test:deps:inline'], () => { +gulp.task('test:single-run', [':test:deps:inline'], (done: () => void) => { new karma.Server({ configFile: path.join(PROJECT_ROOT, 'test/karma.conf.js'), singleRun: true - }).start(); + }, done).start(); });