(testModules: TestModule[], options?: { stackTrace?: boolean; diff?: boolean })
| 573 | } |
| 574 | |
| 575 | export function buildErrorTree(testModules: TestModule[], options?: { stackTrace?: boolean; diff?: boolean }) { |
| 576 | const root = testModules[0]?.project.config.root |
| 577 | |
| 578 | function mapError(e: { message: string; diff?: string; stacks?: { file: string; line: number; column: number; method: string }[] }) { |
| 579 | let message = e.message |
| 580 | if (options?.diff && e.diff) { |
| 581 | message = [message, stripVTControlCharacters(e.diff)].join('\n') |
| 582 | } |
| 583 | if (options?.stackTrace) { |
| 584 | const stacks = (e.stacks || []).map((s) => { |
| 585 | const loc = `${relative(root, s.file)}:${s.line}:${s.column}` |
| 586 | return s.method ? ` at ${s.method} (${loc})` : ` at ${loc}` |
| 587 | }) |
| 588 | message = [message, ...stacks].join('\n') |
| 589 | } |
| 590 | return message |
| 591 | } |
| 592 | |
| 593 | return buildTestTree( |
| 594 | testModules, |
| 595 | (testCase) => { |
| 596 | const result = testCase.result() |
| 597 | if (result.state === 'failed') { |
| 598 | return result.errors.map(e => mapError(e)) |
| 599 | } |
| 600 | return result.state |
| 601 | }, |
| 602 | (testSuite, suiteChildren) => { |
| 603 | const errors = testSuite.errors() |
| 604 | if (errors.length > 0) { |
| 605 | return { |
| 606 | ...suiteChildren, |
| 607 | __suite_errors__: errors.map(e => mapError(e)), |
| 608 | } |
| 609 | } |
| 610 | return suiteChildren |
| 611 | }, |
| 612 | (testModule, moduleChildren) => { |
| 613 | const errors = testModule.errors() |
| 614 | if (errors.length > 0) { |
| 615 | return { |
| 616 | ...moduleChildren, |
| 617 | __module_errors__: errors.map(e => mapError(e)), |
| 618 | } |
| 619 | } |
| 620 | return moduleChildren |
| 621 | }, |
| 622 | ) |
| 623 | } |
| 624 | |
| 625 | export function buildTestTree( |
| 626 | testModules: TestModule[], |
no test coverage detected