Skip to content

Commit

Permalink
Support mixed children test types in test suites (#349)
Browse files Browse the repository at this point in the history
* Support mixed children test types in test suites

* Add verbose logging for test case and group initialization

* Add XCTestHTMLReportSampleApp build folder to gitignore

---------

Co-authored-by: Kevin Brotcke <brotckek@amazon.com>
Co-authored-by: Tyler Vick <1395852+tylervick@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 23, 2024
1 parent 04b4812 commit 9229533
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ RetryResults*
SanityResults*
.DS_Store
/.build
/XCTestHTMLReportSampleApp/Build
/Packages

/*.xcodeproj
Expand Down
7 changes: 4 additions & 3 deletions Sources/XCTestHTMLReportCore/Classes/HTMLTemplates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1027,12 +1027,13 @@ struct HTMLTemplates
for (var i = 0; i < testSummaryGroups.length; i++) {
var testSummaryGroup = testSummaryGroups[i];
var children = Array.prototype.slice.call(testSummaryGroup.children);
var testSummaries = children.filter(function(a) { return a.classList.contains('test-summary'); });
if (testSummaries.length == 0) {
var testSummaryChildren = children.filter(function(a) { return a.classList.contains('test-summary'); });
var testSummaryGroupChildren = children.filter(function(a) { return a.classList.contains('test-summary-group'); });
if (testSummaryChildren == 0 || testSummaryGroupChildren.length > 0) {
continue;
}
if (testSummaries.filter(function(a) { return a.style.display == 'block' }).length == 0) {
if (testSummaryChildren.filter(function(a) { return a.style.display == 'block' }).length == 0) {
testSummaryGroup.style.display = 'none';
} else {
testSummaryGroup.style.display = 'block';
Expand Down
58 changes: 32 additions & 26 deletions Sources/XCTestHTMLReportCore/Classes/Models/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public struct TestGroup: Test {
return .unknown
}

let subTests: [Test]
var subTests: [Test] = []

var descendantSubTests: [Test] {
subTests.flatMap { subTest -> [Test] in
Expand All @@ -98,31 +98,35 @@ public struct TestGroup: Test {
identifier = group.identifier ?? "---group-identifier-not-found---"
duration = group.duration

if group.subtests.isEmpty {
subTests = group.subtestGroups.map { TestGroup(
group: $0,
resultFile: resultFile,
renderingMode: renderingMode,
downsizeImagesEnabled: downsizeImagesEnabled,
downsizeScaleFactor: downsizeScaleFactor
) }
} else {
subTests = Array(group.subtests.reduce(into: Set<TestCase>()) { subTestSet, metadata in
let newTest = TestCase(
metadata: metadata,
resultFile: resultFile,
renderingMode: renderingMode,
downsizeImagesEnabled: downsizeImagesEnabled,
downsizeScaleFactor: downsizeScaleFactor
)
if let index = subTestSet.firstIndex(of: newTest) {
var existingTest = subTestSet[index]
existingTest.iterations.append(contentsOf: newTest.iterations)
subTestSet.update(with: existingTest)
} else {
subTestSet.insert(newTest)
}
})
Logger.substep("Initializing TestGroup \(identifier)")

if !group.subtests.isEmpty {
subTests += Array(group.subtests.reduce(into: Set<TestCase>()) { subTestSet, metadata in
let newTest = TestCase(
metadata: metadata,
resultFile: resultFile,
renderingMode: renderingMode,
downsizeImagesEnabled: downsizeImagesEnabled,
downsizeScaleFactor: downsizeScaleFactor
)
if let index = subTestSet.firstIndex(of: newTest) {
var existingTest = subTestSet[index]
existingTest.iterations.append(contentsOf: newTest.iterations)
subTestSet.update(with: existingTest)
} else {
subTestSet.insert(newTest)
}
})
}

if !group.subtestGroups.isEmpty {
subTests += group.subtestGroups.map { TestGroup(
group: $0,
resultFile: resultFile,
renderingMode: renderingMode,
downsizeImagesEnabled: downsizeImagesEnabled,
downsizeScaleFactor: downsizeScaleFactor
) }
}
}
}
Expand Down Expand Up @@ -203,6 +207,8 @@ struct TestCase: Test {
title = metadata.name ?? ""
identifier = metadata.identifier ?? ""

Logger.substep("Initializing TestCase \(identifier)")

iterations = [Iteration(
metadata: metadata,
resultFile: resultFile,
Expand Down

0 comments on commit 9229533

Please sign in to comment.