Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | 2x 26x 26x 26x 26x 26x 26x 26x 26x 7x 7x 7x 7x 7x 6x 6x 6x 6x 6x 9x 1x 9x 6x 6x 6x 6x 6x 9x 9x 9x 9x 9x 9x 3x 3x 1x 1x 1x 3x 3x 3x 3x 34x 34x 7x 54x 7x 3x 4x 29x 4x 4x | const STACKTRACE_FILTER = /(node_modules(\/|\\)(\w+)*|@wdio\/sync\/(build|src)|- - - - -)/g
export default class JasmineReporter {
constructor (reporter, params) {
this.reporter = reporter
this.cid = params.cid
this.capabilities = params.capabilities
this.specs = params.specs
this.shouldCleanStack = typeof params.cleanStack === 'boolean' ? params.cleanStack : true
this.parent = []
this.failedCount = 0
this.startedTest = null
}
suiteStarted (suite) {
this.suiteStart = new Date()
suite.type = 'suite'
suite.start = new Date()
this.emit('suite:start', suite)
this.parent.push({
description: suite.description,
id: suite.id,
tests: 0
})
}
specStarted (test) {
this.testStart = new Date()
test.type = 'test'
test.start = new Date()
this.parent[this.parent.length - 1].tests++
this.emit('test:start', test)
}
specDone (test) {
/**
* excluded tests are treated as pending tests
*/
if (test.status === 'excluded') {
test.status = 'pending'
}
if (test.failedExpectations.length) {
let errors = test.failedExpectations
if (this.shouldCleanStack) {
errors = test.failedExpectations.map(x => this.cleanStack(x))
}
test.errors = errors
// We maintain the single error property for backwards compatibility with reporters
// However, any reporter wanting to make use of Jasmine's 'soft assertion' type expects
// should default to looking at 'errors' if they are available
test.error = errors[0]
}
const e = 'test:' + test.status.replace(/ed/, '')
test.type = 'test'
test.duration = new Date() - this.testStart
this.emit(e, test)
this.failedCount += test.status === 'failed' ? 1 : 0
this.emit('test:end', test)
}
suiteDone (suite) {
const parentSuite = this.parent[this.parent.length - 1]
/**
* in case there is a runtime error within one of the specs
* create an empty test to attach the error to it
*/
if (parentSuite.tests === 0 && suite.failedExpectations.length) {
const id = 'spec' + Math.random()
this.specStarted({
id,
description: '<unknown test>',
fullName: '<unknown test>',
start: Date.now()
})
this.specDone({
id,
description: '<unknown test>',
fullName: '<unknown test>',
failedExpectations: suite.failedExpectations,
start: Date.now(),
status: 'failed'
})
}
this.parent.pop()
suite.type = 'suite'
suite.duration = new Date() - this.suiteStart
this.emit('suite:end', suite)
}
emit (event, payload) {
let message = {
cid: this.cid,
uid: this.getUniqueIdentifier(payload),
event: event,
title: payload.description,
pending: payload.status === 'pending',
parent: this.parent.length ? this.getUniqueIdentifier(this.parent[this.parent.length - 1]) : null,
type: payload.type,
// We maintain the single error property for backwards compatibility with reporters
// However, any reporter wanting to make use of Jasmine's 'soft assertion' type expects
// should default to looking at 'errors' if they are available
error: payload.error,
errors: payload.errors,
duration: payload.duration || 0,
specs: this.specs,
start: payload.start,
}
this.reporter.emit(event, message)
}
getFailedCount () {
return this.failedCount
}
getUniqueIdentifier (target) {
return target.description + target.id
}
cleanStack (error) {
if (!error.stack) {
return error
}
let stack = error.stack.split('\n')
stack = stack.filter((line) => !line.match(STACKTRACE_FILTER))
error.stack = stack.join('\n')
return error
}
}
|