playwright-trx-reporter
Version:
TRX reporter for playwright
42 lines (41 loc) • 1.75 kB
JavaScript
;
/// copy the following from playwright repo:
Object.defineProperty(exports, "__esModule", { value: true });
exports.escape = exports.stripAnsiEscapes = exports.prepareErrorStack = void 0;
function prepareErrorStack(stack) {
const lines = stack.split('\n');
let firstStackLine = lines.findIndex((line) => line.startsWith(' at '));
if (firstStackLine === -1) {
firstStackLine = lines.length;
}
const message = lines.slice(0, firstStackLine).join('\n');
const stackLines = lines.slice(firstStackLine);
// !!!!!!! we did not get the real location for now, it's fine
let location;
return { message, stackLines, location };
}
exports.prepareErrorStack = prepareErrorStack;
// See https://en.wikipedia.org/wiki/Valid_characters_in_XML
const discouragedXMLCharacters = /[\u0001-\u0008\u000b-\u000c\u000e-\u001f\u007f-\u0084\u0086-\u009f]/g;
const ansiRegex = new RegExp('([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))', 'g');
function stripAnsiEscapes(str) {
return str.replace(ansiRegex, '');
}
exports.stripAnsiEscapes = stripAnsiEscapes;
function escape(text, stripANSIControlSequences, isCharacterData) {
if (stripANSIControlSequences) {
text = stripAnsiEscapes(text);
}
if (isCharacterData) {
text = `<![CDATA[${text.replace(/]]>/g, ']]>')}]]>`;
}
else {
const escapeRe = /[&"'<>]/g;
text = text.replace(escapeRe, (c) => ({
'&': '&', '"': '"', "'": ''', '<': '<', '>': '>',
}[c]));
}
text = text.replace(discouragedXMLCharacters, '');
return text;
}
exports.escape = escape;