Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary nulling out of suites #110

Merged
merged 1 commit into from
Dec 1, 2016
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
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ var JUnitReporter = function (baseReporterDecorator, config, logger, helper, for
return (useBrowserName ? browserName : '') + (pkgName ? pkgName + '.' : '') + result.suite[0]
}

// "run_start" - a test run is beginning for all browsers
this.onRunStart = function (browsers) {
suites = Object.create(null)

// TODO(vojta): remove once we don't care about Karma 0.10
browsers.forEach(initializeXmlForBrowser)
}

// "browser_start" - a test run is beginning in _this_ browser
this.onBrowserStart = function (browser) {
initializeXmlForBrowser(browser)
}

// "browser_complete" - a test run has completed in _this_ browser
this.onBrowserComplete = function (browser) {
var suite = suites[browser.id]
var result = browser.lastResult
Expand All @@ -134,8 +137,8 @@ var JUnitReporter = function (baseReporterDecorator, config, logger, helper, for
writeXmlForBrowser(browser)
}

// "run_complete" - a test run has completed on all browsers
this.onRunComplete = function () {
suites = null
allMessages.length = 0
}

Expand Down
26 changes: 26 additions & 0 deletions test/reporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,30 @@ describe('JUnit reporter', function () {
// never pass a null value to XMLAttribute via xmlbuilder attr()
expect(reporter.onBrowserComplete.bind(reporter, badBrowserResult)).not.to.throw(Error)
})

it('should safely handle test re-runs triggered by watchers', function () {
var fakeBrowser = {
id: 'Android_4_1_2',
name: 'Android',
fullName: 'Android 4.1.2',
lastResult: {
error: false,
total: 1,
failed: 0,
netTime: 10 * 1000
}
}

reporter.onRunStart([ fakeBrowser ])
reporter.onBrowserStart(fakeBrowser)

// When a watcher triggers a second test run, onRunStart() for the second
// run gets triggered, followed by onRunComplete() from the first test run.
reporter.onRunStart([ fakeBrowser ])
reporter.onRunComplete()

reporter.onBrowserStart(fakeBrowser)
reporter.onBrowserComplete(fakeBrowser)
reporter.onRunComplete()
})
})