-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feature: Add GFM (GitHub Flavored Markdown) format support. (#5) * Add the `gfm` (Github Flavored Markdown) output format and improve the handling logic of the OutputFormat cases. * Implement an encoder for the gfm format. * Update README.md --------- Co-authored-by: Kanstantsin Bucha <[email protected]>
- Loading branch information
1 parent
25aa799
commit 2887241
Showing
4 changed files
with
80 additions
and
15 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
58 changes: 58 additions & 0 deletions
58
Sources/TestifySDK/Codable/TestResultGitHubFlavoredMarkdownEncoder.swift
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,58 @@ | ||
import Foundation | ||
|
||
public struct TestResultGitHubFlavoredMarkdownEncoder: TestResultEncoder { | ||
|
||
public init() { | ||
|
||
} | ||
|
||
public func encode(_ input: TestSuite) throws -> String { | ||
var totalTestsCount = 0 | ||
var totalTime: Double = 0 | ||
var totalSucceedCount = 0 | ||
var totalFailedCount = 0 | ||
var result = "" | ||
|
||
let suites: [TestSuite] = input.children.reduce([]) { $0 + $1.children } | ||
for suite in suites { | ||
result += "\n" | ||
let name = suite.name | ||
let count = suite.cases.count | ||
let time = suite.cases.reduce(0) { $0 + $1.duration } | ||
let successCount = suite.cases.reduce(0) { $0 + ($1.outcome == .success ? 1 : 0) } | ||
let failureCount = suite.cases.reduce(0) { $0 + ($1.outcome == .failure ? 1 : 0) } | ||
|
||
totalTestsCount += count | ||
totalTime += time | ||
totalSucceedCount += successCount | ||
totalFailedCount += totalFailedCount | ||
|
||
result += "<details>\n" | ||
let suiteResult = count == successCount ? "✅" : "❌" | ||
result += "<summary> \(suiteResult) \(name): \(count) tests were completed in \(timeString(time)) with \(successCount) passed, \(failureCount) failed.</summary>\n" | ||
|
||
for testCase in suite.cases { | ||
let name = testCase.testName | ||
let testResult = testCase.outcome == .success ? "✅" : "❌" | ||
let time = timeString(testCase.duration) | ||
result += "| \(testResult) \(time) | \(name) <br>\n" | ||
} | ||
|
||
result += "<br>\n" | ||
result += "</details>\n" | ||
} | ||
|
||
let testsRunResult = totalTestsCount == totalSucceedCount ? "✅" : "❌" | ||
var testsResult = "# \(testsRunResult) \(totalTestsCount) tests were completed in \(timeString(totalTime))" | ||
testsResult += "\n \n" | ||
testsResult += "\(totalSucceedCount) tests passed, \(totalFailedCount) test failed.\n" | ||
testsResult += "\n----\n" | ||
testsResult += result | ||
|
||
return testsResult | ||
} | ||
|
||
private func timeString(_ sec: Double) -> String { | ||
"\(String(format: "%.2f", sec))s" | ||
} | ||
} |
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
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