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

fix(time): report correct time since Jasmine v2.9.0 #197

Merged
merged 3 commits into from Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 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 @@ -234,7 +235,7 @@ function KarmaReporter (tc, jasmineEnv) {
}

this.specStarted = function (specResult) {
specResult.startTime = new _Date().getTime()
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
12 changes: 10 additions & 2 deletions test/adapter.spec.js
Expand Up @@ -253,6 +253,14 @@ describe('jasmine adapter', function () {
it('should report time for every spec', function () {
var counter = 3

function copySpecResult() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can just be

return spec.result.slice(0);

But in any case pass the spec as an arg to make it clearer.

var copy = {}
for(var i in spec.result) {
copy[i] = spec.result[i]
}
return copy
}

spyOn(Date.prototype, 'getTime').and.callFake(function () {
counter += 1
return counter
Expand All @@ -262,8 +270,8 @@ describe('jasmine adapter', function () {
expect(result.time).toBe(1) // 4 - 3
})

reporter.specStarted(spec.result)
reporter.specDone(spec.result)
reporter.specStarted(copySpecResult())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe reporter.specStarted(spec.result.slice(0))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will that work? spec.result is not an array type: TypeError: spec.result.slice is not a function.

We could do something like JSON.parse(JSON.stringify(spec.result)) (or an other way of cloning the result) if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I've changed it:

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

reporter.specDone(copySpecResult())

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