@skills17/karma-helpers
Advanced tools
Comparing version 1.1.0 to 1.2.0
"use strict"; | ||
var _path = _interopRequireDefault(require("path")); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _util = _interopRequireDefault(require("util")); | ||
@@ -7,2 +11,4 @@ | ||
var _uniqid = _interopRequireDefault(require("uniqid")); | ||
var _taskConfig = _interopRequireDefault(require("@skills17/task-config")); | ||
@@ -40,2 +46,3 @@ | ||
* Print test failures with specific error messages | ||
* | ||
* @param results Test results | ||
@@ -58,3 +65,3 @@ */ | ||
result.log.forEach(log => { | ||
console.error(` ${_chalk.default.red(formatError(log).split('\n').join('\n '))}`); | ||
console.error(` ${_chalk.default.red(formatError(log).trim().split('\n').join('\n '))}\n`); | ||
}); | ||
@@ -65,2 +72,26 @@ } | ||
/** | ||
* Stores a test run in the local history | ||
* | ||
* @param config Task config | ||
* @param testRun Test run | ||
*/ | ||
const storeTestRun = (config, testRun) => { | ||
const historyDir = _path.default.resolve(config.getProjectRoot(), '.history'); | ||
const historyFile = _path.default.resolve(historyDir, `${(0, _uniqid.default)()}.json`); // create history dir if it doesn't exist | ||
if (!_fs.default.existsSync(historyDir)) { | ||
_fs.default.mkdirSync(historyDir); | ||
} // write history file | ||
_fs.default.writeFileSync(historyFile, JSON.stringify({ | ||
time: Math.round(new Date().getTime() / 1000), | ||
...testRun.toJSON() | ||
}, undefined, 2)); | ||
}; | ||
/** | ||
* Create a new reporter | ||
@@ -74,11 +105,10 @@ * | ||
const reporter = function Skills17Reporter(logger, formatError) { | ||
const task = new _taskConfig.default(); | ||
task.loadFromFileSync(); | ||
const config = new _taskConfig.default(); | ||
config.loadFromFileSync(); | ||
const testRun = {}; | ||
const errors = {}; | ||
const testFailures = {}; | ||
const logs = {}; // create a new test run for each browser | ||
const testFailures = {}; // create a new test run for each browser | ||
this.onBrowserStart = function onBrowserStart(browser) { | ||
testRun[browser.id] = task.createTestRun(); | ||
testRun[browser.id] = config.createTestRun(); | ||
}; // save single test result | ||
@@ -88,3 +118,3 @@ | ||
this.onSpecComplete = function onSpecComplete(browser, result) { | ||
testRun[browser.id].recordTest(concatTestName(result), isExtraTest(result), result.success); // display error messages | ||
testRun[browser.id].recordTest(concatTestName(result), result.description, isExtraTest(result), result.success); // display error messages | ||
@@ -97,12 +127,3 @@ if (!result.success) { | ||
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 | ||
@@ -125,8 +146,6 @@ | ||
this.onBrowserLog = (browser, log, type) => { | ||
if (!logs[browser.id]) { | ||
logs[browser.id] = []; | ||
if (!json) { | ||
const message = typeof log === 'string' ? log : _util.default.inspect(log, false, undefined, true); | ||
console.error(`[console.${type.toLowerCase()}] ${message.split('\n').join('\n ')}`); | ||
} | ||
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 | ||
@@ -142,3 +161,3 @@ | ||
if (json) { | ||
console.log(JSON.stringify(testRun[browser.id], undefined, 2)); | ||
console.log(`\n${JSON.stringify(testRun[browser.id], undefined, 2)}`); | ||
} else { | ||
@@ -150,2 +169,6 @@ printTestFailures(formatError, testFailures[browser.id]); | ||
} | ||
if (config.isLocalHistoryEnabled()) { | ||
storeTestRun(config, testRun[browser.id]); | ||
} | ||
}; | ||
@@ -152,0 +175,0 @@ }; |
{ | ||
"name": "@skills17/karma-helpers", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Provides some karma helpers for usage in a skills competition environment.", | ||
@@ -36,2 +36,4 @@ "main": "lib/index.js", | ||
"@types/jest": "^26.0.20", | ||
"@types/rimraf": "^3.0.0", | ||
"@types/uniqid": "^5.2.0", | ||
"@typescript-eslint/eslint-plugin": "^4.13.0", | ||
@@ -53,2 +55,3 @@ "@typescript-eslint/parser": "^4.13.0", | ||
"prettier": "^2.2.1", | ||
"rimraf": "^3.0.2", | ||
"strip-ansi": "^6.0.0", | ||
@@ -58,5 +61,6 @@ "typescript": "^4.1.3" | ||
"dependencies": { | ||
"@skills17/task-config": "^1.3.4", | ||
"@skills17/test-result-printer": "^1.0.3", | ||
"chalk": "^4.1.0" | ||
"@skills17/task-config": "^2.0.1", | ||
"@skills17/test-result-printer": "^2.0.2", | ||
"chalk": "^4.1.0", | ||
"uniqid": "^5.3.0" | ||
}, | ||
@@ -63,0 +67,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
17259
265
5
26
1
1
+ Addeduniqid@^5.3.0
+ Added@skills17/task-config@2.2.1(transitive)
+ Added@skills17/test-result@2.1.0(transitive)
+ Added@skills17/test-result-printer@2.2.0(transitive)
+ Addeduniqid@5.4.0(transitive)
- Removed@skills17/task-config@1.3.4(transitive)
- Removed@skills17/test-result@1.0.2(transitive)
- Removed@skills17/test-result-printer@1.0.3(transitive)
Updated@skills17/task-config@^2.0.1