( testModules: TestModule[], onTestCase?: (result: TestCase) => unknown, onTestSuite?: (testSuite: TestSuite, suiteChildren: Record<string, any>) => unknown, onTestModule?: (testModule: TestModule, moduleChildren: Record<string, any>) => unknown, )
| 623 | } |
| 624 | |
| 625 | export function buildTestTree( |
| 626 | testModules: TestModule[], |
| 627 | onTestCase?: (result: TestCase) => unknown, |
| 628 | onTestSuite?: (testSuite: TestSuite, suiteChildren: Record<string, any>) => unknown, |
| 629 | onTestModule?: (testModule: TestModule, moduleChildren: Record<string, any>) => unknown, |
| 630 | ) { |
| 631 | type TestTree = Record<string, any> |
| 632 | |
| 633 | function walkCollection(collection: TestCollection): TestTree { |
| 634 | const node: TestTree = {} |
| 635 | |
| 636 | for (const child of collection) { |
| 637 | if (child.type === 'suite') { |
| 638 | // Recursively walk suite children |
| 639 | const suiteChildren = walkCollection(child.children) |
| 640 | node[child.name] = onTestSuite ? onTestSuite(child, suiteChildren) : suiteChildren |
| 641 | } |
| 642 | else if (child.type === 'test') { |
| 643 | const result = child.result() |
| 644 | if (onTestCase) { |
| 645 | node[child.name] = onTestCase(child) |
| 646 | } |
| 647 | else { |
| 648 | node[child.name] = result.state |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | return node |
| 654 | } |
| 655 | |
| 656 | const tree: TestTree = {} |
| 657 | |
| 658 | for (const module of testModules) { |
| 659 | // Use relative module ID for cleaner output |
| 660 | const key = module.relativeModuleId |
| 661 | const moduleChildren = walkCollection(module.children) |
| 662 | tree[key] = onTestModule ? onTestModule(module, moduleChildren) : moduleChildren |
| 663 | } |
| 664 | |
| 665 | return tree |
| 666 | } |
| 667 | |
| 668 | export function buildTestProjectTree(testModules: TestModule[], onTestCase?: (result: TestCase) => unknown) { |
| 669 | const projectTree: Record<string, Record<string, any>> = {} |
no test coverage detected