Skip to content

Commit

Permalink
feat(server): add 'listening' event with port number
Browse files Browse the repository at this point in the history
  • Loading branch information
karol-f committed Feb 12, 2016
1 parent 19dd824 commit 82cd0df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/dev/04-public-api.md
Expand Up @@ -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:**

Expand Down
2 changes: 2 additions & 0 deletions lib/server.js
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/unit/server.spec.js
Expand Up @@ -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)

Expand Down

0 comments on commit 82cd0df

Please sign in to comment.