Skip to content

Commit f8f3ebc

Browse files
authored
fix(launcher): Only markCaptured browsers that are launched. (#3047)
This is a regression in 2.0.3: if karma server is started and a users browser attached, the launch throws
1 parent 333e7d4 commit f8f3ebc

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/launcher.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ function Launcher (server, emitter, injector) {
173173

174174
this.markCaptured = (id) => {
175175
const browser = getBrowserById(id)
176-
browser.markCaptured()
177-
log.debug(`${browser.name} (id ${browser.id}) captured in ${(Date.now() - lastStartTime) / 1000} secs`)
176+
if (browser) {
177+
browser.markCaptured()
178+
log.debug(`${browser.name} (id ${browser.id}) captured in ${(Date.now() - lastStartTime) / 1000} secs`)
179+
}
178180
}
179181

180182
emitter.on('exit', this.killAll)

test/unit/launcher.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ describe('launcher', () => {
306306
})
307307
})
308308

309+
describe('markCaptured', () => {
310+
it('should not fail if an un-launched browser attaches', () => {
311+
expect(() => l.markCaptured('not-a-thing')).to.not.throw()
312+
})
313+
})
314+
309315
describe('onExit', () => {
310316
it('should kill all browsers', (done) => {
311317
l.launch(['Fake', 'Fake'], 1)

0 commit comments

Comments
 (0)