-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract summary & logging from TestRunner. (#6297)
## Summary This is a part of a plan to clean up TestRunner. Logging and managing the summary was the easiest functionality for extracting ## Test plan
- Loading branch information
Showing
3 changed files
with
76 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/TestSummaryLogger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { TestCase, TestSuite } from '../types'; | ||
import { color, EMPTY_LOG_PLACEHOLDER, indentNestingLevel } from '../utils/stringFormatUtils'; | ||
|
||
export class TestSummaryLogger { | ||
private _passed: number = 0; | ||
private _failed: number = 0; | ||
private _skipped: number = 0; | ||
private _failedTests: Array<string> = []; | ||
private _startTime: number = Date.now(); | ||
private _endTime: number = 0; | ||
|
||
public logRunningTestSuite(testSuite: TestSuite) { | ||
console.log(`${indentNestingLevel(testSuite.nestingLevel)}${testSuite.name}`); | ||
} | ||
|
||
public showTestCaseSummary(testCase: TestCase, nestingLevel: number) { | ||
let mark; | ||
if (testCase.errors.length > 0) { | ||
this._failed++; | ||
this._failedTests.push(testCase.name); | ||
mark = color('✖', 'red'); | ||
} else { | ||
this._passed++; | ||
mark = color('✔', 'green'); | ||
} | ||
console.log(`${indentNestingLevel(nestingLevel)} ${mark} ${color(testCase.name, 'gray')}`); | ||
|
||
for (const error of testCase.errors) { | ||
const indentedError = error.replace(/\n/g, '\n' + EMPTY_LOG_PLACEHOLDER + indentNestingLevel(nestingLevel + 2)); | ||
console.log(`${indentNestingLevel(nestingLevel)}\t${indentedError}`); | ||
} | ||
} | ||
|
||
public countSkippedTestSuiteTests(testSuite: TestSuite) { | ||
if (testSuite.skip) { | ||
this._skipped += testSuite.testCases.length; | ||
return; | ||
} | ||
for (const testCase of testSuite.testCases) { | ||
if (testCase.skip) { | ||
this._skipped++; | ||
} | ||
} | ||
} | ||
|
||
public printSummary() { | ||
this._endTime = Date.now(); | ||
|
||
console.log('End of tests run 🏁'); | ||
console.log('\n'); | ||
console.log( | ||
`🧮 Tests summary: ${color(this._passed, 'green')} passed, ${color(this._failed, 'red')} failed, ${color( | ||
this._skipped, | ||
'orange', | ||
)} skipped`, | ||
); | ||
console.log(`⏱️ Total time: ${Math.round(((this._endTime - this._startTime) / 1000) * 100) / 100}s`); | ||
if (this._failed > 0) { | ||
console.log('❌ Failed tests:'); | ||
for (const failedTest of this._failedTests) { | ||
console.log(`\t• ${failedTest}`); | ||
} | ||
} else { | ||
console.log('✅ All tests passed!'); | ||
} | ||
console.log('\n'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters