diff --git a/.npmignore b/.npmignore index 7ca4e10e8..cbb83331c 100644 --- a/.npmignore +++ b/.npmignore @@ -3,10 +3,10 @@ tmp test -tasks +#tasks /tools/ docs -client +#client logo integration-tests @@ -16,8 +16,8 @@ Gruntfile.coffee credentials Karma.sublime-* -static/karma.src.js -static/karma.wrapper +#static/karma.src.js +#static/karma.wrapper test-results.xml thesis.pdf mocha-watch.sh diff --git a/lib/server.js b/lib/server.js index e79a2aa22..ed1e4ce79 100644 --- a/lib/server.js +++ b/lib/server.js @@ -147,6 +147,32 @@ class Server extends KarmaEventEmitter { return this._fileList ? this._fileList.changeFile(path) : Promise.resolve() } + emitExitAsync (code) { + const name = 'exit' + let pending = this.listeners(name).length + const deferred = helper.defer() + + function resolve () { + deferred.resolve(code) + } + + this.emit(name, (newCode) => { + if (newCode && typeof newCode === 'number') { + // Only update code if it is given and not zero + code = newCode + } + if (!--pending) { + resolve() + } + }) + + if (!pending) { + resolve() + } + + return deferred.promise + } + async _start (config, launcher, preprocess, fileList, capturedBrowsers, executor, done) { if (config.detached) { this._detach(config, done) @@ -356,21 +382,22 @@ class Server extends KarmaEventEmitter { } }) - let removeAllListenersDone = false - const removeAllListeners = () => { - if (removeAllListenersDone) { - return - } - removeAllListenersDone = true - webServer.removeAllListeners() - processWrapper.removeAllListeners() - done(code || 0) - } - - return this.emitAsync('exit').then(() => { + return this.emitExitAsync(code).then((code) => { return new Promise((resolve, reject) => { socketServer.sockets.removeAllListeners() socketServer.close() + + let removeAllListenersDone = false + const removeAllListeners = () => { + if (removeAllListenersDone) { + return + } + removeAllListenersDone = true + webServer.removeAllListeners() + processWrapper.removeAllListeners() + done(code || 0) + } + const closeTimeout = setTimeout(removeAllListeners, webServerCloseTimeout) webServer.close(() => {