@skills17/karma-helpers
Advanced tools
Comparing version 1.0.2 to 1.1.0
"use strict"; | ||
var _util = _interopRequireDefault(require("util")); | ||
var _chalk = _interopRequireDefault(require("chalk")); | ||
var _taskConfig = _interopRequireDefault(require("@skills17/task-config")); | ||
@@ -9,5 +13,12 @@ | ||
const concatTestName = result => { | ||
const suites = result.suite.filter(suite => suite !== 'Extra' && suite !== 'extra'); | ||
/* eslint-disable no-console */ | ||
/** | ||
* Concatenates the test name with its suites | ||
* | ||
* @param result Test result | ||
*/ | ||
const concatTestName = (result, includeExtra = false) => { | ||
const suites = includeExtra ? result.suite : result.suite.filter(suite => suite !== 'Extra' && suite !== 'extra'); | ||
if (suites.length === 0) { | ||
@@ -19,5 +30,41 @@ return result.description; | ||
}; | ||
/** | ||
* Check if the given test is an extra test | ||
* | ||
* @param result Test result | ||
*/ | ||
const isExtraTest = result => result.suite.includes('Extra') || result.suite.includes('extra'); | ||
/** | ||
* Print test failures with specific error messages | ||
* @param results Test results | ||
*/ | ||
const printTestFailures = (formatError, results) => { | ||
if (!results || results.length === 0) { | ||
return; | ||
} | ||
console.error(); | ||
console.error(_chalk.default.bold.underline.red('FAILED TESTS:')); | ||
console.error(); | ||
results.forEach(result => { | ||
console.error(` ${concatTestName(result, true)}`); | ||
if (result.log && Array.isArray(result.log)) { | ||
result.log.forEach(log => { | ||
console.error(` ${_chalk.default.red(formatError(log).split('\n').join('\n '))}`); | ||
}); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Create a new reporter | ||
* | ||
* @param json Whether the output should be in JSON | ||
*/ | ||
const Reporter = json => { | ||
@@ -28,3 +75,5 @@ const reporter = function Skills17Reporter(logger, formatError) { | ||
const testRun = {}; | ||
const errors = {}; // create a new test run for each browser | ||
const errors = {}; | ||
const testFailures = {}; | ||
const logs = {}; // create a new test run for each browser | ||
@@ -37,3 +86,20 @@ this.onBrowserStart = function onBrowserStart(browser) { | ||
this.onSpecComplete = function onSpecComplete(browser, result) { | ||
testRun[browser.id].recordTest(concatTestName(result), isExtraTest(result), result.success); | ||
testRun[browser.id].recordTest(concatTestName(result), isExtraTest(result), result.success); // display error messages | ||
if (!result.success) { | ||
if (!testFailures[browser.id]) { | ||
testFailures[browser.id] = []; | ||
} | ||
testFailures[browser.id].push(result); | ||
} // display console logs | ||
if (logs[browser.id] && logs[browser.id].length > 0 && !json) { | ||
console.error(); | ||
console.error(concatTestName(result, true)); | ||
logs[browser.id].forEach(log => console.error(` ${log.split('\n').join('\n ')}`)); | ||
} | ||
delete logs[browser.id]; | ||
}; // handle browser errors that do not allow execution of further tests | ||
@@ -46,3 +112,3 @@ | ||
error: formatError(error) | ||
}, undefined, 2)); // eslint-disable-line no-console | ||
}, undefined, 2)); | ||
} else { | ||
@@ -53,2 +119,12 @@ logger.create('skills17').error(`An unexpected error has occurred and tests cannot be executed.\n${formatError(error)}`); | ||
errors[browser.id] = true; | ||
}; // forward console.log statements | ||
this.onBrowserLog = (browser, log, type) => { | ||
if (!logs[browser.id]) { | ||
logs[browser.id] = []; | ||
} | ||
const message = typeof log === 'string' ? log : _util.default.inspect(log, false, undefined, true); | ||
logs[browser.id].push(`console.${type.toLowerCase()}: ${message}`); | ||
}; // print result when all tests have been executed | ||
@@ -64,10 +140,8 @@ | ||
if (json) { | ||
console.log(JSON.stringify(testRun[browser.id], undefined, 2)); // eslint-disable-line no-console | ||
console.log(JSON.stringify(testRun[browser.id], undefined, 2)); | ||
} else { | ||
console.log(); // eslint-disable-line no-console | ||
printTestFailures(formatError, testFailures[browser.id]); | ||
console.log(); | ||
const printer = new _testResultPrinter.default(testRun[browser.id]); | ||
printer.print({ | ||
printFooter: false | ||
}); | ||
printer.print(); | ||
} | ||
@@ -74,0 +148,0 @@ }; |
{ | ||
"name": "@skills17/karma-helpers", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Provides some karma helpers for usage in a skills competition environment.", | ||
@@ -57,3 +57,4 @@ "main": "lib/index.js", | ||
"@skills17/task-config": "^1.3.4", | ||
"@skills17/test-result-printer": "^1.0.3" | ||
"@skills17/test-result-printer": "^1.0.3", | ||
"chalk": "^4.1.0" | ||
}, | ||
@@ -60,0 +61,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16547
249
4
+ Addedchalk@^4.1.0