diff --git a/packages/angular_devkit/build_angular/package.json b/packages/angular_devkit/build_angular/package.json index 498ac49eedce..e699262781d7 100644 --- a/packages/angular_devkit/build_angular/package.json +++ b/packages/angular_devkit/build_angular/package.json @@ -77,7 +77,7 @@ "jquery": "^3.3.1", "jasmine-core": "~2.8.0", "jasmine-spec-reporter": "~4.2.1", - "karma": "~3.0.0", + "karma": "~3.1.1", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.0", "karma-jasmine": "~1.1.0", diff --git a/packages/angular_devkit/build_angular/src/karma/index.ts b/packages/angular_devkit/build_angular/src/karma/index.ts index 3479edf21f68..ef3f17acd508 100644 --- a/packages/angular_devkit/build_angular/src/karma/index.ts +++ b/packages/angular_devkit/build_angular/src/karma/index.ts @@ -108,15 +108,14 @@ export class KarmaBuilder implements Builder { // Complete the observable once the Karma server returns. const karmaServer = new karma.Server(karmaOptions, () => obs.complete()); - karmaServer.start(); + const karmaStartPromise = karmaServer.start(); // Cleanup, signal Karma to exit. return () => { - // Karma does not seem to have a way to exit the server gracefully. - // See https://github.com/karma-runner/karma/issues/2867#issuecomment-369912167 - // TODO: make a PR for karma to add `karmaServer.close(code)`, that - // calls `disconnectBrowsers(code);` - // karmaServer.close(); + // Karma only has the `stop` method start with 3.1.1, so we must defensively check. + if (karmaServer.stop && typeof karmaServer.stop === 'function') { + return karmaStartPromise.then(() => karmaServer.stop()); + } }; })), ); diff --git a/packages/angular_devkit/build_angular/test/karma/rebuilds_spec_large.ts b/packages/angular_devkit/build_angular/test/karma/rebuilds_spec_large.ts index 494823bf121a..6d08de627625 100644 --- a/packages/angular_devkit/build_angular/test/karma/rebuilds_spec_large.ts +++ b/packages/angular_devkit/build_angular/test/karma/rebuilds_spec_large.ts @@ -10,64 +10,18 @@ import { runTargetSpec } from '@angular-devkit/architect/testing'; import { debounceTime, take, tap } from 'rxjs/operators'; import { host, karmaTargetSpec } from '../utils'; - -// Karma watch mode is currently bugged: -// - errors print a huge stack trace -// - karma does not have a way to close the server -// gracefully (https://github.com/karma-runner/karma/issues/3149) -// TODO: fix these before 6.0 final. -xdescribe('Karma Builder watch mode', () => { +describe('Karma Builder watch mode', () => { beforeEach(done => host.initialize().toPromise().then(done, done.fail)); afterEach(done => host.restore().toPromise().then(done, done.fail)); - it('works', (done) => { + it('works', async () => { const overrides = { watch: true }; - runTargetSpec(host, karmaTargetSpec, overrides).pipe( + const res = await runTargetSpec(host, karmaTargetSpec, overrides).pipe( debounceTime(500), tap((buildEvent) => expect(buildEvent.success).toBe(true)), take(1), - ).toPromise().then(done, done.fail); - }, 30000); - - it('recovers from compilation failures in watch mode', (done) => { - const overrides = { watch: true }; - let buildNumber = 0; - - runTargetSpec(host, karmaTargetSpec, overrides).pipe( - debounceTime(500), - tap((buildEvent) => { - buildNumber += 1; - switch (buildNumber) { - case 1: - // Karma run should succeed. - // Add a compilation error. - expect(buildEvent.success).toBe(true); - host.writeMultipleFiles({ - 'src/app/app.component.spec.ts': '

definitely not typescript

', - }); - break; - - case 2: - // Karma run should fail due to compilation error. Fix it. - expect(buildEvent.success).toBe(false); - host.writeMultipleFiles({ 'src/foo.spec.ts': '' }); - break; - - case 3: - // Karma run should succeed again. - expect(buildEvent.success).toBe(true); - break; - - default: - break; - } - }), - take(3), - ).toPromise().then(done, done.fail); - }, 30000); + ).toPromise(); - it('does not rebuild when nothing changed', (done) => { - // Start the server in watch mode, wait for the first build to finish, touch - // test.js without changing it, wait 5s then exit unsuscribe, verify only one event was emitted. + expect(res).toEqual({ success: true }); }, 30000); }); diff --git a/yarn.lock b/yarn.lock index dce6f3949ebd..8954881a1391 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4999,10 +4999,10 @@ karma-source-map-support@1.3.0: dependencies: source-map-support "^0.5.5" -karma@~3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/karma/-/karma-3.0.0.tgz#6da83461a8a28d8224575c3b5b874e271b4730c3" - integrity sha512-ZTjyuDXVXhXsvJ1E4CnZzbCjSxD6sEdzEsFYogLuZM0yqvg/mgz+O+R1jb0J7uAQeuzdY8kJgx6hSNXLwFuHIQ== +karma@~3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/karma/-/karma-3.1.1.tgz#94c8edd20fb9597ccde343326da009737fb0423a" + integrity sha512-NetT3wPCQMNB36uiL9LLyhrOt8SQwrEKt0xD3+KpTCfm0VxVyUJdPL5oTq2Ic5ouemgL/Iz4wqXEbF3zea9kQQ== dependencies: bluebird "^3.3.0" body-parser "^1.16.1"