mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(junit reporter): add option to force usage of CDATA sections for content in XML elements (#12744)
Co-authored-by: Sergio Freire <sergio.freire@xpand-it.com>
This commit is contained in:
parent
531bdb2493
commit
d193bd64c4
@ -201,10 +201,14 @@ const discouragedXMLCharacters = /[\u0001-\u0008\u000b-\u000c\u000e-\u001f\u007f
|
||||
function escape(text: string, stripANSIControlSequences: boolean, isCharacterData: boolean): string {
|
||||
if (stripANSIControlSequences)
|
||||
text = stripAnsiEscapes(text);
|
||||
const escapeRe = isCharacterData ? /[&<]/g : /[&"<>]/g;
|
||||
text = text.replace(escapeRe, c => ({ '&': '&', '"': '"', '<': '<', '>': '>' }[c]!));
|
||||
if (isCharacterData)
|
||||
text = text.replace(/]]>/g, ']]>');
|
||||
|
||||
if (isCharacterData) {
|
||||
text = '<![CDATA[' + text.replace(/]]>/g, ']]>') + ']]>';
|
||||
} else {
|
||||
const escapeRe = /[&"'<>]/g;
|
||||
text = text.replace(escapeRe, c => ({ '&': '&', '"': '"', "'": ''', '<': '<', '>': '>' }[c]!));
|
||||
}
|
||||
|
||||
text = text.replace(discouragedXMLCharacters, '');
|
||||
return text;
|
||||
}
|
||||
|
@ -141,6 +141,28 @@ test('should render stdout without ansi escapes', async ({ runInlineTest }) => {
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test('should render, by default, character data as CDATA sections', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'playwright.config.ts': `
|
||||
module.exports = {
|
||||
reporter: [ ['junit'] ],
|
||||
};
|
||||
`,
|
||||
'a.test.ts': `
|
||||
const { test } = pwt;
|
||||
test('one', async ({}) => {
|
||||
process.stdout.write('Hello world &"\\'<>]]>');
|
||||
});
|
||||
`,
|
||||
}, { reporter: '' });
|
||||
const xml = parseXML(result.output);
|
||||
const testcase = xml['testsuites']['testsuite'][0]['testcase'][0];
|
||||
expect(testcase['system-out'].length).toBe(1);
|
||||
expect(testcase['system-out'][0].trim()).toBe('Hello world &"\'<>]]>');
|
||||
expect(result.output).toContain(`<system-out>\n<![CDATA[Hello world &"\'<>]]>]]>\n</system-out>`);
|
||||
expect(result.exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test('should render skipped', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'a.test.js': `
|
||||
|
Loading…
x
Reference in New Issue
Block a user