All files / wdio-allure-reporter/src utils.js

100% Statements 18/18
100% Branches 17/17
100% Functions 6/6
100% Lines 15/15

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                    4x 10x 2x     8x 4x     4x 4x                 9x               30x               4x 2x                 4x 9x 4x   5x    
import process from 'process'
import CompoundError from './compoundError'
import { testStatuses, mochaEachHooks } from './constants'
 
/**
 * Get allure test status by TestStat object
 * @param test {Object} - TestStat object
 * @param config {Object} - wdio config object
 * @private
 */
export const getTestStatus = (test, config) => {
    if (config.framework === 'jasmine') {
        return testStatuses.FAILED
    }
 
    if (test.error.name) {
        return test.error.name === 'AssertionError' ? testStatuses.FAILED : testStatuses.BROKEN
    }
 
    const stackTrace = test.error.stack.trim()
    return stackTrace.startsWith('AssertionError') ? testStatuses.FAILED : testStatuses.BROKEN
 
}
 
/**
 * Check is object is empty
 * @param object {Object}
 * @private
 */
export const isEmpty = (object) => !object || Object.keys(object).length === 0
 
/**
 * Is mocha beforeEach / afterEach hook
 * @param title {String} - hook title
 * @returns {boolean}
 * @private
 */
export const isMochaEachHooks = title => mochaEachHooks.some(hook => title.includes(hook))
 
/**
 * Call reporter
 * @param {string} event  - event name
 * @param {Object} msg - event payload
 * @private
 */
export const tellReporter = (event, msg = {}) => {
    process.emit(event, msg)
}
 
/**
 * Properly format error from different test runners
 * @param {Object} test - TestStat object
 * @returns {Object} - error object
 * @private
 */
export const getErrorFromFailedTest = (test) => {
    if (test.errors && Array.isArray(test.errors)) {
        return test.errors.length === 1 ? test.errors[0] : new CompoundError(...test.errors)
    }
    return test.error
}