Tiny, but fully loaded test-runner.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

74 lines
2.8 KiB

"use strict";
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var toXML = require('jsontoxml');
var _require = require('../util/nodeutils'),
clear = _require.clear;
var escapeXML = function escapeXML(str) {
return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
};
var toJSON = function toJSON(resultsArray) {
return {
testsuites: resultsArray.map(function (results) {
var name = results.name,
count = results.count,
success = results.success,
failures = results.failures,
skipped = results.skipped;
return {
name: 'testsuite',
attrs: {
name: escapeXML(name),
tests: count,
success: success.length,
failures: failures.length,
skipped: skipped.length,
timestamp: new Date().toUTCString(),
time: results.duration / 1000 || 0
},
children: results.reduce(function (acc, r) {
var reason = r.reason ? r.reason.stack || r.reason : '';
var content = r.status !== 'ok' && {
name: r.status === 'skip' ? 'skipped' : 'failure',
text: escapeXML(reason)
};
acc.push(_objectSpread({
name: 'testcase',
attrs: {
name: escapeXML(r.description),
time: r.duration / 1000 || 0
}
}, _typeof(content) === 'object' && {
children: [content]
}));
return acc;
}, [])
};
})
};
};
var convert = function convert(results) {
return toXML(toJSON(results), {
xmlHeader: {
standalone: true
}
});
};
var xunit = function xunit(runner) {
return runner.on("end", function (results) {
return clear(), console.log(convert([results]));
});
};
module.exports = xunit;
module.exports.convert = convert;