MCPcopy Index your code
hub / github.com/nodejs/node / reportReruns

Function reportReruns

lib/internal/test_runner/reporter/rerun.js:11–76  ·  view source on GitHub ↗
(previousRuns, globalOptions)

Source from the content-addressed store, hash-verified

9const { writeFileSync } = require('fs');
10
11function reportReruns(previousRuns, globalOptions) {
12 return async function reporter(source) {
13 const obj = { __proto__: null };
14 const disambiguator = { __proto__: null };
15 let currentSuite = null;
16 const roots = [];
17
18 function getTestId(data) {
19 return `${relative(globalOptions.cwd, data.file)}:${data.line}:${data.column}`;
20 }
21
22 function startTest(data) {
23 const originalSuite = currentSuite;
24 currentSuite = { __proto__: null, data, parent: currentSuite, children: [] };
25 if (originalSuite?.children) {
26 ArrayPrototypePush(originalSuite.children, currentSuite);
27 }
28 if (!currentSuite.parent) {
29 ArrayPrototypePush(roots, currentSuite);
30 }
31 }
32
33 for await (const { type, data } of source) {
34 let currentTest;
35 if (type === 'test:start') {
36 startTest(data);
37 } else if (type === 'test:fail' || type === 'test:pass') {
38 if (!currentSuite) {
39 startTest({ __proto__: null, name: 'root', nesting: 0 });
40 }
41 if (currentSuite.data.name !== data.name || currentSuite.data.nesting !== data.nesting) {
42 startTest(data);
43 }
44 currentTest = currentSuite;
45 if (currentSuite?.data.nesting === data.nesting) {
46 currentSuite = currentSuite.parent;
47 }
48 }
49
50
51 if (type === 'test:pass' || type === 'test:fail') {
52 const baseIdentifier = getTestId(data);
53 let identifier = baseIdentifier;
54 if (disambiguator[baseIdentifier] !== undefined) {
55 identifier += `:(${disambiguator[baseIdentifier]})`;
56 disambiguator[baseIdentifier] += 1;
57 } else {
58 disambiguator[baseIdentifier] = 1;
59 }
60 if (type === 'test:pass') {
61 const children = ArrayPrototypeMap(currentTest.children, (child) => child.data);
62 obj[identifier] = {
63 __proto__: null,
64 name: data.name,
65 children,
66 passed_on_attempt: data.details.passed_on_attempt ?? data.details.attempt,
67 duration_ms: data.details.duration_ms,
68 };

Callers 1

setupFailureStateFileFunction · 0.85

Calls 3

getTestIdFunction · 0.85
writeFileSyncFunction · 0.85
startTestFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…