Skip to content

Commit 175f2d8

Browse files
authored
chore: fix unit broken unit tests and CI not running them (#1834)
* fix: unbreak unit tests * Revert "chore(build): fix karma not exiting properly (#1741)" This reverts commit 77701cc.
1 parent d0f4c3e commit 175f2d8

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

src/lib/core/overlay/overlay-ref.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {NgZone} from '@angular/core';
12
import {PortalHost, Portal} from '../portal/portal';
23
import {OverlayState} from './overlay-state';
34
import {Observable} from 'rxjs/Observable';
@@ -15,7 +16,8 @@ export class OverlayRef implements PortalHost {
1516
constructor(
1617
private _portalHost: PortalHost,
1718
private _pane: HTMLElement,
18-
private _state: OverlayState) { }
19+
private _state: OverlayState,
20+
private _ngZone: NgZone) { }
1921

2022
attach(portal: Portal<any>): any {
2123
if (this._state.hasBackdrop) {
@@ -124,7 +126,13 @@ export class OverlayRef implements PortalHost {
124126
// If the backdrop doesn't have a transition, the `transitionend` event won't fire.
125127
// In this case we make it unclickable and we try to remove it after a delay.
126128
backdropToDetach.style.pointerEvents = 'none';
127-
setTimeout(finishDetach, 500);
129+
130+
// Run this outside the Angular zone because there's nothing that Angular cares about.
131+
// If it were to run inside the Angular zone, every test that used Overlay would have to be
132+
// either async or fakeAsync.
133+
this._ngZone.runOutsideAngular(() => {
134+
setTimeout(finishDetach, 500);
135+
});
128136
}
129137
}
130138
}

src/lib/core/overlay/overlay.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ComponentFactoryResolver, Injectable, ApplicationRef, Injector} from '@angular/core';
1+
import {ComponentFactoryResolver, Injectable, ApplicationRef, Injector, NgZone} from '@angular/core';
22
import {OverlayState} from './overlay-state';
33
import {DomPortalHost} from '../portal/dom-portal-host';
44
import {OverlayRef} from './overlay-ref';
@@ -28,7 +28,8 @@ export class Overlay {
2828
private _componentFactoryResolver: ComponentFactoryResolver,
2929
private _positionBuilder: OverlayPositionBuilder,
3030
private _appRef: ApplicationRef,
31-
private _injector: Injector) {}
31+
private _injector: Injector,
32+
private _ngZone: NgZone) {}
3233

3334
/**
3435
* Creates an overlay.
@@ -77,7 +78,7 @@ export class Overlay {
7778
* @returns {OverlayRef}
7879
*/
7980
private _createOverlayRef(pane: HTMLElement, state: OverlayState): OverlayRef {
80-
return new OverlayRef(this._createPortalHost(pane), pane, state);
81+
return new OverlayRef(this._createPortalHost(pane), pane, state, this._ngZone);
8182
}
8283
}
8384

test/karma.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export function config(config) {
5959
colors: true,
6060
logLevel: config.LOG_INFO,
6161
autoWatch: true,
62-
autoWatchBatchDelay: 500,
6362

6463
sauceLabs: {
6564
testName: 'material2',

tools/gulp/tasks/unit-test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import gulp = require('gulp');
22
import path = require('path');
33
import gulpMerge = require('merge2');
44

5-
import {PROJECT_ROOT} from '../constants';
5+
import {PROJECT_ROOT, DIST_COMPONENTS_ROOT} from '../constants';
66
import {sequenceTask} from '../task_helpers';
77

88
const karma = require('karma');
@@ -48,20 +48,20 @@ gulp.task(':test:deps:inline', sequenceTask(':test:deps', ':inline-resources'));
4848
*
4949
* This task should be used when running unit tests locally.
5050
*/
51-
gulp.task('test', [':test:watch'], () => {
51+
gulp.task('test', [':test:watch'], (done: () => void) => {
5252
new karma.Server({
5353
configFile: path.join(PROJECT_ROOT, 'test/karma.conf.js')
54-
}).start();
54+
}, done).start();
5555
});
5656

5757
/**
5858
* Runs the unit tests once with inlined resources (html, css). Does not watch for changes.
5959
*
6060
* This task should be used when running tests on the CI server.
6161
*/
62-
gulp.task('test:single-run', [':test:deps:inline'], () => {
62+
gulp.task('test:single-run', [':test:deps:inline'], (done: () => void) => {
6363
new karma.Server({
6464
configFile: path.join(PROJECT_ROOT, 'test/karma.conf.js'),
6565
singleRun: true
66-
}).start();
66+
}, done).start();
6767
});

0 commit comments

Comments
 (0)