(previousRuns, globalOptions)
| 9 | const { writeFileSync } = require('fs'); |
| 10 | |
| 11 | function 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 | }; |
no test coverage detected
searching dependent graphs…