Skip to content

Commit 0df94ba

Browse files
committed
feat: pr comments fixed
1 parent 2879fc7 commit 0df94ba

7 files changed

Lines changed: 192 additions & 468 deletions

File tree

doc/api/test.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,6 @@ it.todo('should do the thing', { expectFailure: true }, () => {
277277

278278
## Flaky tests
279279

280-
<!-- YAML
281-
added:
282-
- REPLACEME
283-
-->
284-
285280
This flag causes a test or suite to be re-run a number of times until it
286281
either passes or has not passed after the final re-try.
287282

@@ -3437,7 +3432,7 @@ Emitted when a test is enqueued for execution.
34373432
* `testNumber` {number} The ordinal number of the test.
34383433
* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called
34393434
* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called
3440-
* `flakyRetriedCount` {number|undefined} The number of retries taken for a
3435+
* `retryCount` {number|undefined} The number of retries taken for a
34413436
flaky test. Present when a test is marked as flaky.
34423437

34433438
Emitted when a test fails.
@@ -3467,7 +3462,7 @@ The corresponding execution ordered event is `'test:complete'`.
34673462
* `testNumber` {number} The ordinal number of the test.
34683463
* `todo` {string|boolean|undefined} Present if [`context.todo`][] is called
34693464
* `skip` {string|boolean|undefined} Present if [`context.skip`][] is called
3470-
* `flakyRetriedCount` {number|undefined} The number of retries taken for a
3465+
* `retryCount` {number|undefined} The number of retries taken for a
34713466
flaky test. Present when a test is marked as flaky and passed after retries.
34723467

34733468
Emitted when a test passes.

lib/internal/test_runner/reporter/dot.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use strict';
2-
const { ArrayPrototypePush, MathMax } = primordials;
2+
const {
3+
ArrayPrototypePush,
4+
MathMax,
5+
} = primordials;
36
const colors = require('internal/util/colors');
47
const { formatTestReport } = require('internal/test_runner/reporter/utils');
58

@@ -9,7 +12,7 @@ module.exports = async function* dot(source) {
912
const failedTests = [];
1013
for await (const { type, data } of source) {
1114
if (type === 'test:pass') {
12-
if (data.flakyRetriedCount > 0) {
15+
if (data.retryCount > 0) {
1316
yield `${colors.yellow}F${colors.reset}`;
1417
} else {
1518
yield `${colors.green}.${colors.reset}`;

lib/internal/test_runner/reporter/junit.js

Lines changed: 27 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,15 @@ const {
1515
const { inspectWithNoCustomRetry } = require('internal/errors');
1616
const { hostname } = require('os');
1717

18-
const inspectOptions = {
19-
__proto__: null,
20-
colors: false,
21-
breakLength: Infinity,
22-
};
18+
const inspectOptions = { __proto__: null, colors: false, breakLength: Infinity };
2319
const HOSTNAME = hostname();
2420

2521
function escapeAttribute(s = '') {
26-
return escapeContent(
27-
RegExpPrototypeSymbolReplace(
28-
/"/g,
29-
RegExpPrototypeSymbolReplace(/\n/g, s, '&#10;'),
30-
'&quot;',
31-
),
32-
);
22+
return escapeContent(RegExpPrototypeSymbolReplace(/"/g, RegExpPrototypeSymbolReplace(/\n/g, s, '&#10;'), '&quot;'));
3323
}
3424

3525
function escapeContent(s = '') {
36-
return RegExpPrototypeSymbolReplace(
37-
/</g,
38-
RegExpPrototypeSymbolReplace(/(&)(?!#\d{1,7};)/g, s, '&amp;'),
39-
'&lt;',
40-
);
26+
return RegExpPrototypeSymbolReplace(/</g, RegExpPrototypeSymbolReplace(/(&)(?!#\d{1,7};)/g, s, '&amp;'), '&lt;');
4127
}
4228

4329
function escapeComment(s = '') {
@@ -48,42 +34,31 @@ function treeToXML(tree) {
4834
if (typeof tree === 'string') {
4935
return `${escapeContent(tree)}\n`;
5036
}
51-
const { tag, attrs, nesting, children, comment } = tree;
37+
const {
38+
tag, attrs, nesting, children, comment,
39+
} = tree;
5240
const indent = StringPrototypeRepeat('\t', nesting + 1);
5341
if (comment) {
5442
return `${indent}<!-- ${escapeComment(comment)} -->\n`;
5543
}
5644
const attrsString = ArrayPrototypeJoin(
5745
ArrayPrototypeMap(
5846
ObjectEntries(attrs),
59-
({ 0: key, 1: value }) => `${key}="${escapeAttribute(String(value))}"`,
60-
),
61-
' ',
62-
);
47+
({ 0: key, 1: value }) => `${key}="${escapeAttribute(String(value))}"`),
48+
' ');
6349
if (!children?.length) {
6450
return `${indent}<${tag} ${attrsString}/>\n`;
6551
}
66-
const childrenString = ArrayPrototypeJoin(
67-
ArrayPrototypeMap(children ?? [], treeToXML),
68-
'',
69-
);
52+
const childrenString = ArrayPrototypeJoin(ArrayPrototypeMap(children ?? [], treeToXML), '');
7053
return `${indent}<${tag} ${attrsString}>\n${childrenString}${indent}</${tag}>\n`;
7154
}
7255

7356
function isFailure(node) {
74-
return (
75-
(node?.children &&
76-
ArrayPrototypeSome(node.children, (c) => c.tag === 'failure')) ||
77-
node?.attrs?.failures
78-
);
57+
return (node?.children && ArrayPrototypeSome(node.children, (c) => c.tag === 'failure')) || node?.attrs?.failures;
7958
}
8059

8160
function isSkipped(node) {
82-
return (
83-
(node?.children &&
84-
ArrayPrototypeSome(node.children, (c) => c.tag === 'skipped')) ||
85-
node?.attrs?.skipped
86-
);
61+
return (node?.children && ArrayPrototypeSome(node.children, (c) => c.tag === 'skipped')) || node?.attrs?.skipped;
8762
}
8863

8964
module.exports = async function* junitReporter(source) {
@@ -118,42 +93,25 @@ module.exports = async function* junitReporter(source) {
11893
case 'test:pass':
11994
case 'test:fail': {
12095
if (!currentSuite) {
121-
startTest({
122-
__proto__: null,
123-
data: { __proto__: null, name: 'root', nesting: 0 },
124-
});
96+
startTest({ __proto__: null, data: { __proto__: null, name: 'root', nesting: 0 } });
12597
}
126-
if (
127-
currentSuite.attrs.name !== event.data.name ||
128-
currentSuite.nesting !== event.data.nesting
129-
) {
98+
if (currentSuite.attrs.name !== event.data.name ||
99+
currentSuite.nesting !== event.data.nesting) {
130100
startTest(event);
131101
}
132102
const currentTest = currentSuite;
133103
if (currentSuite?.nesting === event.data.nesting) {
134104
currentSuite = currentSuite.parent;
135105
}
136-
currentTest.attrs.time = NumberPrototypeToFixed(
137-
event.data.details.duration_ms / 1000,
138-
6,
139-
);
140-
const nonCommentChildren = ArrayPrototypeFilter(
141-
currentTest.children,
142-
(c) => c.comment == null,
143-
);
106+
currentTest.attrs.time = NumberPrototypeToFixed(event.data.details.duration_ms / 1000, 6);
107+
const nonCommentChildren = ArrayPrototypeFilter(currentTest.children, (c) => c.comment == null);
144108
if (nonCommentChildren.length > 0) {
145109
currentTest.tag = 'testsuite';
146110
currentTest.attrs.disabled = 0;
147111
currentTest.attrs.errors = 0;
148112
currentTest.attrs.tests = nonCommentChildren.length;
149-
currentTest.attrs.failures = ArrayPrototypeFilter(
150-
currentTest.children,
151-
isFailure,
152-
).length;
153-
currentTest.attrs.skipped = ArrayPrototypeFilter(
154-
currentTest.children,
155-
isSkipped,
156-
).length;
113+
currentTest.attrs.failures = ArrayPrototypeFilter(currentTest.children, isFailure).length;
114+
currentTest.attrs.skipped = ArrayPrototypeFilter(currentTest.children, isSkipped).length;
157115
currentTest.attrs.hostname = HOSTNAME;
158116
} else {
159117
currentTest.tag = 'testcase';
@@ -163,29 +121,17 @@ module.exports = async function* junitReporter(source) {
163121
}
164122
if (event.data.skip) {
165123
ArrayPrototypePush(currentTest.children, {
166-
__proto__: null,
167-
nesting: event.data.nesting + 1,
168-
tag: 'skipped',
169-
attrs: {
170-
__proto__: null,
171-
type: 'skipped',
172-
message: event.data.skip,
173-
},
124+
__proto__: null, nesting: event.data.nesting + 1, tag: 'skipped',
125+
attrs: { __proto__: null, type: 'skipped', message: event.data.skip },
174126
});
175127
}
176128
if (event.data.todo) {
177129
ArrayPrototypePush(currentTest.children, {
178-
__proto__: null,
179-
nesting: event.data.nesting + 1,
180-
tag: 'skipped',
181-
attrs: {
182-
__proto__: null,
183-
type: 'todo',
184-
message: event.data.todo,
185-
},
130+
__proto__: null, nesting: event.data.nesting + 1, tag: 'skipped',
131+
attrs: { __proto__: null, type: 'todo', message: event.data.todo },
186132
});
187133
}
188-
if (event.data.flakyRetriedCount > 0) {
134+
if (event.data.retryCount > 0) {
189135
ArrayPrototypePush(currentTest.children, {
190136
__proto__: null,
191137
nesting: event.data.nesting + 1,
@@ -199,7 +145,7 @@ module.exports = async function* junitReporter(source) {
199145
attrs: {
200146
__proto__: null,
201147
name: 'flaky',
202-
value: `${event.data.flakyRetriedCount} retries`,
148+
value: `${event.data.retryCount} retries`,
203149
},
204150
},
205151
],
@@ -211,11 +157,7 @@ module.exports = async function* junitReporter(source) {
211157
__proto__: null,
212158
nesting: event.data.nesting + 1,
213159
tag: 'failure',
214-
attrs: {
215-
__proto__: null,
216-
type: error?.failureType || error?.code,
217-
message: error?.message.trim() ?? '',
218-
},
160+
attrs: { __proto__: null, type: error?.failureType || error?.code, message: error?.message.trim() ?? '' },
219161
children: [inspectWithNoCustomRetry(error, inspectOptions)],
220162
});
221163
currentTest.failures = 1;
@@ -227,13 +169,10 @@ module.exports = async function* junitReporter(source) {
227169
case 'test:diagnostic': {
228170
const parent = currentSuite?.children ?? roots;
229171
ArrayPrototypePush(parent, {
230-
__proto__: null,
231-
nesting: event.data.nesting,
232-
comment: event.data.message,
172+
__proto__: null, nesting: event.data.nesting, comment: event.data.message,
233173
});
234174
break;
235-
}
236-
default:
175+
} default:
237176
break;
238177
}
239178
}

lib/internal/test_runner/reporter/tap.js

Lines changed: 16 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,26 @@ const kDefaultIndent = ' '; // 4 spaces
1919
const kFrameStartRegExp = /^ {4}at /;
2020
const kLineBreakRegExp = /\n|\r\n/;
2121
const kDefaultTAPVersion = 13;
22-
const inspectOptions = {
23-
__proto__: null,
24-
colors: false,
25-
breakLength: Infinity,
26-
};
22+
const inspectOptions = { __proto__: null, colors: false, breakLength: Infinity };
2723
let testModule; // Lazy loaded due to circular dependency.
2824

2925
function lazyLoadTest() {
3026
testModule ??= require('internal/test_runner/test');
3127
return testModule;
3228
}
3329

34-
async function* tapReporter(source) {
30+
31+
async function * tapReporter(source) {
3532
yield `TAP version ${kDefaultTAPVersion}\n`;
3633
for await (const { type, data } of source) {
3734
switch (type) {
3835
case 'test:fail': {
39-
yield reportTest(
40-
data.nesting,
41-
data.testNumber,
42-
'not ok',
43-
data.name,
44-
data.skip,
45-
data.todo,
46-
data.expectFailure,
47-
data.flakyRetriedCount,
48-
);
49-
const location = data.file
50-
? `${data.file}:${data.line}:${data.column}`
51-
: null;
36+
yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo, data.expectFailure, data.retryCount);
37+
const location = data.file ? `${data.file}:${data.line}:${data.column}` : null;
5238
yield reportDetails(data.nesting, data.details, location);
5339
break;
54-
}
55-
case 'test:pass':
56-
yield reportTest(
57-
data.nesting,
58-
data.testNumber,
59-
'ok',
60-
data.name,
61-
data.skip,
62-
data.todo,
63-
data.expectFailure,
64-
data.flakyRetriedCount,
65-
);
40+
} case 'test:pass':
41+
yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo, data.expectFailure, data.retryCount);
6642
yield reportDetails(data.nesting, data.details, null);
6743
break;
6844
case 'test:plan':
@@ -73,42 +49,23 @@ async function* tapReporter(source) {
7349
break;
7450
case 'test:stderr':
7551
case 'test:stdout': {
76-
const lines = RegExpPrototypeSymbolSplit(
77-
kLineBreakRegExp,
78-
data.message,
79-
);
52+
const lines = RegExpPrototypeSymbolSplit(kLineBreakRegExp, data.message);
8053
for (let i = 0; i < lines.length; i++) {
8154
if (lines[i].length === 0) continue;
8255
yield `# ${tapEscape(lines[i])}\n`;
8356
}
8457
break;
85-
}
86-
case 'test:diagnostic':
58+
} case 'test:diagnostic':
8759
yield `${indent(data.nesting)}# ${tapEscape(data.message)}\n`;
8860
break;
8961
case 'test:coverage':
90-
yield getCoverageReport(
91-
indent(data.nesting),
92-
data.summary,
93-
'# ',
94-
'',
95-
true,
96-
);
62+
yield getCoverageReport(indent(data.nesting), data.summary, '# ', '', true);
9763
break;
9864
}
9965
}
10066
}
10167

102-
function reportTest(
103-
nesting,
104-
testNumber,
105-
status,
106-
name,
107-
skip,
108-
todo,
109-
expectFailure,
110-
flakyRetriedCount,
111-
) {
68+
function reportTest(nesting, testNumber, status, name, skip, todo, expectFailure, retryCount) {
11269
let line = `${indent(nesting)}${status} ${testNumber}`;
11370

11471
if (name) {
@@ -121,9 +78,9 @@ function reportTest(
12178
line += ` # TODO${typeof todo === 'string' && todo.length ? ` ${tapEscape(todo)}` : ''}`;
12279
} else if (expectFailure !== undefined) {
12380
line += ' # EXPECTED FAILURE';
124-
} else if (flakyRetriedCount !== undefined && flakyRetriedCount > 0) {
125-
const retryText = flakyRetriedCount === 1 ? 're-try' : 're-tries';
126-
line += ` # FLAKY ${flakyRetriedCount} ${retryText}`;
81+
} else if (retryCount !== undefined && retryCount > 0) {
82+
const retryText = retryCount === 1 ? 're-try' : 're-tries';
83+
line += ` # FLAKY ${retryCount} ${retryText}`;
12784
}
12885

12986
line += '\n';
@@ -159,6 +116,7 @@ function indent(nesting) {
159116
return value;
160117
}
161118

119+
162120
// In certain places, # and \ need to be escaped as \# and \\.
163121
function tapEscape(input) {
164122
let result = StringPrototypeReplaceAll(input, '\b', '\\b');
@@ -322,12 +280,7 @@ function jsToYaml(indent, name, value, seen) {
322280
}
323281

324282
function isAssertionLike(value) {
325-
return (
326-
value &&
327-
typeof value === 'object' &&
328-
'expected' in value &&
329-
'actual' in value
330-
);
283+
return value && typeof value === 'object' && 'expected' in value && 'actual' in value;
331284
}
332285

333286
module.exports = tapReporter;

0 commit comments

Comments
 (0)