Skip to content

Commit 518cb11

Browse files
cexbrayatlusarz
authored andcommitted
fix: remove circular reference in Browser
After migrating the the `browser.js` file to ES2015, the `Browser` class has now fields with circular references (like `emitter`), which breaks the Karma JSON reporters available starting with Karma 2.0.1. This commit removes the circular dependencies by adding a `toJSON()` method to the `Browser` class, which produces a similar result to the browser object before the migration. Fixes #3075
1 parent 850a90b commit 518cb11

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/browser.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ class Browser {
6262
return this.name
6363
}
6464

65+
toJSON () {
66+
return {
67+
id: this.id,
68+
fullName: this.fullName,
69+
name: this.name,
70+
state: this.state,
71+
lastResult: this.lastResult,
72+
disconnectsCount: this.disconnectsCount,
73+
noActivityTimeout: this.noActivityTimeout,
74+
disconnectDelay: this.disconnectDelay
75+
}
76+
}
77+
6578
onKarmaError (error) {
6679
if (this.isReady()) {
6780
return

test/unit/browser.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe('Browser', () => {
3232
expect(browser.fullName).to.equal(fullName)
3333
})
3434

35+
it('should serialize to JSON', () => {
36+
const fullName = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 ' + '(KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7'
37+
browser = new Browser('id', fullName, collection, emitter, socket)
38+
emitter.browser = browser
39+
const json = JSON.stringify(browser)
40+
expect(json).to.contain(fullName)
41+
})
42+
3543
describe('init', () => {
3644
it('should emit "browser_register"', () => {
3745
const spyRegister = sinon.spy()

0 commit comments

Comments
 (0)