From 82cd0df2ee860d2e94e81a02b8eb9dff46433187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Fabja=C5=84czuk?= Date: Fri, 5 Feb 2016 20:04:25 +0100 Subject: [PATCH] feat(server): add 'listening' event with port number --- docs/dev/04-public-api.md | 7 +++++++ lib/server.js | 2 ++ test/unit/server.spec.js | 13 +++++++++++++ 3 files changed, 22 insertions(+) diff --git a/docs/dev/04-public-api.md b/docs/dev/04-public-api.md index d382bb9f6..c9bc02017 100644 --- a/docs/dev/04-public-api.md +++ b/docs/dev/04-public-api.md @@ -40,6 +40,13 @@ server.on('browser_register', function (browser) { }) ``` +### `listening` +**Arguments:** + +* `port`: Port number + +Begin accepting connections on the specified port. + ### `browser_register` **Arguments:** diff --git a/lib/server.js b/lib/server.js index 4c8084419..072af7028 100644 --- a/lib/server.js +++ b/lib/server.js @@ -160,6 +160,8 @@ Server.prototype._start = function (config, launcher, preprocess, fileList, webS self.log.info('Karma v%s server started at %s//%s:%s%s', constant.VERSION, config.protocol, config.hostname, config.port, config.urlRoot) + self.emit('listening', config.port) + if (config.browsers && config.browsers.length) { self._injector.invoke(launcher.launch, launcher).forEach(function (browserLauncher) { singleRunDoneBrowsers[browserLauncher.id] = false diff --git a/test/unit/server.spec.js b/test/unit/server.spec.js index e537aedcf..2082062d2 100644 --- a/test/unit/server.spec.js +++ b/test/unit/server.spec.js @@ -149,6 +149,19 @@ describe('server', () => { expect(mockConfig.port).to.be.equal(9877) }) + it('should emit a listening event once server begin accepting connections', () => { + server._start(mockConfig, mockLauncher, null, mockFileList, mockWebServer, browserCollection, mockSocketServer, mockExecutor, doneSpy) + + var listening = sinon.spy() + server.on('listening', listening) + + expect(listening).not.to.have.been.called + + fileListOnResolve() + + expect(listening).to.have.been.calledWith(9876) + }) + it('should emit a browsers_ready event once all the browsers are captured', () => { server._start(mockConfig, mockLauncher, null, mockFileList, mockWebServer, browserCollection, mockSocketServer, mockExecutor, doneSpy)