From 2bdf2feea70cd9657e82e1387be5f7d357857846 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Wed, 14 Jun 2017 11:00:03 +0100 Subject: [PATCH] test(aio): add async beforeEach to prevent Chrome disconnects Related to 3d5f520ff08f00f89f323f1ec3bcd1e0c3f38596 from #17405 --- aio/src/app/app.component.spec.ts | 5 +---- aio/src/test.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index c076632c38..86e9dac62a 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -59,12 +59,9 @@ describe('AppComponent', () => { describe('with proper DocViewer', () => { - // For reasons unknown, not using `done` (even calling it synchronously), - // causes Chrome (v58+) to often get disconnected (at least on Windows and Travis). - beforeEach(done => { + beforeEach(() => { createTestingModule('a/b'); initializeTest(); - done(); }); it('should create', () => { diff --git a/aio/src/test.ts b/aio/src/test.ts index 722acc0395..b545af8bab 100644 --- a/aio/src/test.ts +++ b/aio/src/test.ts @@ -42,6 +42,14 @@ getTestBed().initTestEnvironment( platformBrowserDynamicTesting() ); +// HACK: Chrome 59 disconnects if there are too many synchronous tests in a row +// because it appears to lock up the thread that communicates to Karma's socket +// This async beforeEach gets called on every spec and releases the JS thread long +// enough for the socket to continue to communicate. +// The downside is that it creates a minor performance penalty of around 10-15% +// increase in the time it takes to run out unit tests. +beforeEach((done) => done()); + declare var System: any; // Then we find all the tests. System.import('./test-specs.ts')