()
| 637 | } |
| 638 | |
| 639 | private reportImportDurations() { |
| 640 | const { print, failOnDanger, thresholds } = this.ctx.config.experimental.importDurations |
| 641 | if (!print && !failOnDanger) { |
| 642 | return |
| 643 | }; |
| 644 | |
| 645 | const testModules = this.ctx.state.getTestModules() |
| 646 | |
| 647 | interface ImportEntry { |
| 648 | importedModuleId: string |
| 649 | selfTime: number |
| 650 | external?: boolean |
| 651 | totalTime: number |
| 652 | testModule: TestModule |
| 653 | } |
| 654 | |
| 655 | const allImports: ImportEntry[] = [] |
| 656 | |
| 657 | for (const testModule of testModules) { |
| 658 | const diagnostic = testModule.diagnostic() |
| 659 | const importDurations = diagnostic.importDurations |
| 660 | |
| 661 | for (const filePath in importDurations) { |
| 662 | const duration = importDurations[filePath] |
| 663 | allImports.push({ |
| 664 | importedModuleId: filePath, |
| 665 | testModule, |
| 666 | selfTime: duration.selfTime, |
| 667 | totalTime: duration.totalTime, |
| 668 | external: duration.external, |
| 669 | }) |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | if (allImports.length === 0) { |
| 674 | return |
| 675 | } |
| 676 | |
| 677 | const dangerImports = allImports.filter(imp => imp.totalTime >= thresholds.danger) |
| 678 | const warnImports = allImports.filter(imp => imp.totalTime >= thresholds.warn) |
| 679 | const hasDangerImports = dangerImports.length > 0 |
| 680 | const hasWarnImports = warnImports.length > 0 |
| 681 | |
| 682 | // Determine if we should print |
| 683 | const shouldFail = failOnDanger && hasDangerImports |
| 684 | const shouldPrint = (print === true) || (print === 'on-warn' && hasWarnImports) || shouldFail |
| 685 | if (!shouldPrint) { |
| 686 | return |
| 687 | } |
| 688 | |
| 689 | const sortedImports = allImports.sort((a, b) => b.totalTime - a.totalTime) |
| 690 | const maxTotalTime = sortedImports[0].totalTime |
| 691 | const limit = this.ctx.config.experimental.importDurations.limit |
| 692 | const topImports = sortedImports.slice(0, limit) |
| 693 | |
| 694 | const totalSelfTime = allImports.reduce((sum, imp) => sum + imp.selfTime, 0) |
| 695 | const totalTotalTime = allImports.reduce((sum, imp) => sum + imp.totalTime, 0) |
| 696 | const slowestImport = sortedImports[0] |
nothing calls this directly
no test coverage detected