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

feat: Propagate errors thrown in afterAll blocks #162

Merged
merged 1 commit into from Mar 29, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/adapter.js
Expand Up @@ -170,6 +170,18 @@ function KarmaReporter (tc, jasmineEnv) {
return suite.description === 'Jasmine_TopLevel_Suite'
}

function handleGlobalErrors (result) {
if (result.failedExpectations && result.failedExpectations.length) {
var message = 'An error was thrown in afterAll'
var steps = result.failedExpectations
for (var i = 0, l = steps.length; i < l; i++) {
message += '\n' + formatFailedStep(steps[i])
}

tc.error(message)
}
}

/**
* Jasmine 2.0 dispatches the following events:
*
Expand All @@ -191,6 +203,10 @@ function KarmaReporter (tc, jasmineEnv) {

this.jasmineDone = function (result) {
result = result || {}

// Any errors in top-level afterAll blocks are given here.
handleGlobalErrors(result)

tc.complete({
order: result.order,
coverage: window.__coverage__
Expand All @@ -210,6 +226,10 @@ function KarmaReporter (tc, jasmineEnv) {
return
}

// Any errors in afterAll blocks are given here, except for top-level
// afterAll blocks.
handleGlobalErrors(result)

currentSuite = currentSuite.parent
}

Expand Down
17 changes: 17 additions & 0 deletions test/adapter.spec.js
Expand Up @@ -145,6 +145,23 @@ describe('jasmine adapter', function () {
expect(karma.result).toHaveBeenCalled()
})

it('should report errors in afterAll blocks', function () {
spyOn(karma, 'complete')
spyOn(karma, 'error')

var result = {
failedExpectations: []
}

reporter.jasmineDone(result)
expect(karma.error).not.toHaveBeenCalled()

result.failedExpectations.push({})

reporter.jasmineDone(result)
expect(karma.error).toHaveBeenCalled()
})

it('should report executedExpectCount as sum of passed and failed expectations', function () {
karma.result.and.callFake(function (result) {
expect(result.executedExpectationsCount).toBe(2)
Expand Down