Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dist/client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ export default class Client {
this.client.onready = () => {
clearTimeout(connectionTimeout)
this._changeState(STATE_NOT_AUTHENTICATED)
// reject instead of leaving an unhandled rejection when the socket closes
// while CAPABILITY is pending (e.g. server greets and immediately drops the connection)
this.updateCapability()
.then(() => resolve(this._capability))
.catch(reject)
}

this.client.onerror = (err) => {
Expand Down
12 changes: 12 additions & 0 deletions src/client.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ describe('browserbox unit tests', () => {
expect(br._capability[1]).to.equal('capa2')
})
})

it('should reject when CAPABILITY fails after greeting', () => {
const err = new Error('Socket closed unexpectedly!')
br.client.connect.returns(Promise.resolve())
br.client.enqueueCommand.callsFake(() => Promise.reject(err))
setTimeout(() => br.client.onready(), 0)
return br.openConnection().then(() => {
throw new Error('should not resolve')
}, (e) => {
expect(e).to.equal(err)
})
})
})

describe('#connect', () => {
Expand Down