Skip to content

Commit

Permalink
fix: remove circular reference in Browser
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cexbrayat authored and lusarz committed Jul 11, 2018
1 parent 850a90b commit 518cb11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ class Browser {
return this.name
}

toJSON () {
return {
id: this.id,
fullName: this.fullName,
name: this.name,
state: this.state,
lastResult: this.lastResult,
disconnectsCount: this.disconnectsCount,
noActivityTimeout: this.noActivityTimeout,
disconnectDelay: this.disconnectDelay
}
}

onKarmaError (error) {
if (this.isReady()) {
return
Expand Down
8 changes: 8 additions & 0 deletions test/unit/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe('Browser', () => {
expect(browser.fullName).to.equal(fullName)
})

it('should serialize to JSON', () => {
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'
browser = new Browser('id', fullName, collection, emitter, socket)
emitter.browser = browser
const json = JSON.stringify(browser)
expect(json).to.contain(fullName)
})

describe('init', () => {
it('should emit "browser_register"', () => {
const spyRegister = sinon.spy()
Expand Down

0 comments on commit 518cb11

Please sign in to comment.