Skip to content

Commit 3127a2b

Browse files
AlexCannonballRafaelGSS
authored andcommitted
test_runner: fix line feed escaping in JUnit
Replaces line feed characters with the correct character reference in XML attribute values. PR-URL: #60274 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent a6ac8bd commit 3127a2b

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎lib/internal/test_runner/reporter/junit.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const inspectOptions = { __proto__: null, colors: false, breakLength: Infinity }
1919
constHOSTNAME=hostname();
2020

2121
functionescapeAttribute(s=''){
22-
returnescapeContent(RegExpPrototypeSymbolReplace(/"/g,RegExpPrototypeSymbolReplace(/\n/g,s,''),'&quot;'));
22+
returnescapeContent(RegExpPrototypeSymbolReplace(/"/g,RegExpPrototypeSymbolReplace(/\n/g,s,'&#10;'),'&quot;'));
2323
}
2424

2525
functionescapeContent(s=''){
26-
returnRegExpPrototypeSymbolReplace(/</g,RegExpPrototypeSymbolReplace(/&/g,s,'&amp;'),'&lt;');
26+
returnRegExpPrototypeSymbolReplace(/</g,RegExpPrototypeSymbolReplace(/(&)(?!#\d{1,7};)/g,s,'&amp;'),'&lt;');
2727
}
2828

2929
functionescapeComment(s=''){
@@ -137,7 +137,7 @@ module.exports = async function* junitReporter(source) {
137137
__proto__: null,
138138
nesting: event.data.nesting+1,
139139
tag: 'failure',
140-
attrs: {__proto__: null,type: error?.failureType||error?.code,message: error?.message??''},
140+
attrs: {__proto__: null,type: error?.failureType||error?.code,message: error?.message.trim()??''},
141141
children: [inspectWithNoCustomRetry(error,inspectOptions)],
142142
});
143143
currentTest.failures=1;

‎test/fixtures/test-runner/output/junit_reporter.snapshot‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
}
102102
</failure>
103103
</testcase>
104-
<testcasename="async assertion fail"time="*"classname="test"file="*"failure="Expected values to be strictly equal:true !== false">
105-
<failuretype="testCodeFailure"message="Expected values to be strictly equal:true !== false">
104+
<testcasename="async assertion fail"time="*"classname="test"file="*"failure="Expected values to be strictly equal:&#10;&#10;true !== false&#10;">
105+
<failuretype="testCodeFailure"message="Expected values to be strictly equal:&#10;&#10;true !== false">
106106
[Error [ERR_TEST_FAILURE]: Expected values to be strictly equal:
107107

108108
true !== false
@@ -316,8 +316,8 @@ Error [ERR_TEST_FAILURE]: thrown from callback async throw
316316
[Error [ERR_TEST_FAILURE]: customized] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: customized }
317317
</failure>
318318
</testcase>
319-
<testcasename="custom inspect symbol that throws fail"time="*"classname="test"file="*"failure="{ foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]}">
320-
<failuretype="testCodeFailure"message="{ foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]}">
319+
<testcasename="custom inspect symbol that throws fail"time="*"classname="test"file="*"failure="{&#10; foo: 1,&#10; Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]&#10;}">
320+
<failuretype="testCodeFailure"message="{&#10; foo: 1,&#10; Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]&#10;}">
321321
[Error [ERR_TEST_FAILURE]: {
322322
foo: 1,
323323
Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]
@@ -413,8 +413,8 @@ Error [ERR_TEST_FAILURE]: bar
413413
}
414414
</failure>
415415
</testcase>
416-
<testcasename="assertion errors display actual and expected properly"time="*"classname="test"file="*"failure="Expected values to be loosely deep-equal:{ bar: 1, baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, boo: [ 1 ], foo: 1}should loosely deep-equal{ baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, boo: [ 1 ], circular: &lt;ref *1> { bar: 2, c: [Circular *1] }}">
417-
<failuretype="testCodeFailure"message="Expected values to be loosely deep-equal:{ bar: 1, baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, boo: [ 1 ], foo: 1}should loosely deep-equal{ baz: { date: 1970-01-01T00:00:00.000Z, null: null, number: 1, string: 'Hello', undefined: undefined }, boo: [ 1 ], circular: &lt;ref *1> { bar: 2, c: [Circular *1] }}">
416+
<testcasename="assertion errors display actual and expected properly"time="*"classname="test"file="*"failure="Expected values to be loosely deep-equal:&#10;&#10;{&#10; bar: 1,&#10; baz: {&#10; date: 1970-01-01T00:00:00.000Z,&#10; null: null,&#10; number: 1,&#10; string: 'Hello',&#10; undefined: undefined&#10; },&#10; boo: [&#10; 1&#10; ],&#10; foo: 1&#10;}&#10;&#10;should loosely deep-equal&#10;&#10;{&#10; baz: {&#10; date: 1970-01-01T00:00:00.000Z,&#10; null: null,&#10; number: 1,&#10; string: 'Hello',&#10; undefined: undefined&#10; },&#10; boo: [&#10; 1&#10; ],&#10; circular: &lt;ref *1> {&#10; bar: 2,&#10; c: [Circular *1]&#10; }&#10;}">
417+
<failuretype="testCodeFailure"message="Expected values to be loosely deep-equal:&#10;&#10;{&#10; bar: 1,&#10; baz: {&#10; date: 1970-01-01T00:00:00.000Z,&#10; null: null,&#10; number: 1,&#10; string: 'Hello',&#10; undefined: undefined&#10; },&#10; boo: [&#10; 1&#10; ],&#10; foo: 1&#10;}&#10;&#10;should loosely deep-equal&#10;&#10;{&#10; baz: {&#10; date: 1970-01-01T00:00:00.000Z,&#10; null: null,&#10; number: 1,&#10; string: 'Hello',&#10; undefined: undefined&#10; },&#10; boo: [&#10; 1&#10; ],&#10; circular: &lt;ref *1> {&#10; bar: 2,&#10; c: [Circular *1]&#10; }&#10;}">
418418
[Error [ERR_TEST_FAILURE]: Expected values to be loosely deep-equal:
419419

420420
{

0 commit comments

Comments
 (0)