Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(time): report correct time since Jasmine v2.9.0 (#197)
* fix(time): report correct time since Jasmine v2.9.0

Time reporting broke since jasmine-core v2.9 because the reporter API
now receives copies of spec results instead of the real deal.
We cannot rely on the same object being passed around.

Fixes #196
  • Loading branch information
nicojs authored and johnjbarton committed Mar 28, 2018
1 parent c84316e commit 022ee04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/adapter.js
Expand Up @@ -161,6 +161,7 @@ function KarmaReporter (tc, jasmineEnv) {
// Save link on native Date object
// because user can mock it
var _Date = Date
var startTimeCurrentSpec = new _Date().getTime()

/**
* @param suite
Expand Down Expand Up @@ -233,8 +234,8 @@ function KarmaReporter (tc, jasmineEnv) {
currentSuite = currentSuite.parent
}

this.specStarted = function (specResult) {
specResult.startTime = new _Date().getTime()
this.specStarted = function () {
startTimeCurrentSpec = new _Date().getTime()
}

this.specDone = function (specResult) {
Expand All @@ -249,7 +250,7 @@ function KarmaReporter (tc, jasmineEnv) {
pending: specResult.status === 'pending',
success: specResult.failedExpectations.length === 0,
suite: [],
time: skipped ? 0 : new _Date().getTime() - specResult.startTime,
time: skipped ? 0 : new _Date().getTime() - startTimeCurrentSpec,
executedExpectationsCount: specResult.failedExpectations.length + specResult.passedExpectations.length
}

Expand Down
4 changes: 2 additions & 2 deletions test/adapter.spec.js
Expand Up @@ -262,8 +262,8 @@ describe('jasmine adapter', function () {
expect(result.time).toBe(1) // 4 - 3
})

reporter.specStarted(spec.result)
reporter.specDone(spec.result)
reporter.specStarted(Object.assign({}, spec.result))
reporter.specDone(Object.assign({}, spec.result))

expect(karma.result).toHaveBeenCalled()
})
Expand Down

0 comments on commit 022ee04

Please sign in to comment.