Skip to content

Commit

Permalink
Merge branch 'develop' into develop_ad
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Rollet committed Oct 17, 2019
2 parents 6617afe + 796af58 commit 24146b4
Show file tree
Hide file tree
Showing 73 changed files with 724 additions and 2,594 deletions.
33 changes: 3 additions & 30 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
TestResults*
.DS_Store
xchtmlreport
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
builds/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
/.build
/Packages
/*.xcodeproj
xcuserdata/
xchtmlreport.swiftmodule/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
osx_image: xcode9.3
osx_image:
- xcode9.3
- xcode10.1
- xcode10.2

language: objective-c

before_script:
- bundle install
script:
- set -o pipefail
- set -o pipefail && xcodebuild clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -workspace XCTestHTMLReport.xcworkspace -scheme XCTestHTMLReport -configuration Release | xcpretty
- ./xchtmlreport -h
25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "Rainbow",
"repositoryURL": "https://github.com/onevcat/Rainbow.git",
"state": {
"branch": null,
"revision": "9c52c1952e9b2305d4507cf473392ac2d7c9b155",
"version": "3.1.5"
}
},
{
"package": "XCResultKit",
"repositoryURL": "https://github.com/davidahouse/XCResultKit.git",
"state": {
"branch": null,
"revision": "a3c59768f90c0a0945ef1b8576017175f04a54b3",
"version": "0.4.0"
}
}
]
},
"version": 1
}
25 changes: 25 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "XCTestHTMLReport",
products: [
.executable(name: "xchtmlreport", targets: ["XCTestHTMLReport"])
],
dependencies: [
.package(url: "https://github.com/onevcat/Rainbow.git", from: "3.0.0"),
.package(url: "https://github.com/davidahouse/XCResultKit.git", from: "0.4.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "XCTestHTMLReport",
dependencies: ["Rainbow", "XCResultKit"]),
.testTarget(
name: "XCTestHTMLReportTests",
dependencies: ["XCTestHTMLReport"]),
]
)
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Xcode-like HTML report for Unit and UI Tests
- Filter out successful or failed tests
- Displays information about the target device
- Displays activity logs
- Junit report

## Fastlane Support

https://github.com/TitouanVanBelle/fastlane-plugin-xchtmlreport

## Installation

Expand Down
28 changes: 28 additions & 0 deletions Sources/XCTestHTMLReport/Classes/Extensions/String+Path.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// String+Path.swift
// XCTestHTMLReport
//
// Created by Titouan Van Belle on 26.11.17.
// Copyright © 2017 Tito. All rights reserved.
//

import Foundation

extension String
{
func dropLastPathComponent() -> String
{
if let url = URL(string: self) {
return url.deletingLastPathComponent().path
}
return self
}

func addPathComponent(_ component: String) -> String
{
if let url = URL(string: self) {
return url.appendingPathComponent(component).path
}
return self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,7 @@ struct HTMLTemplates
<li onclick=\"showApplicationLogs(this);\">App Logs</li>
</ul>
</div>
<iframe id=\"test-logs-iframe\" src=\"logs-[[DEVICE_IDENTIFIER]].txt\"></iframe>
<iframe id=\"app-logs-iframe\" src=\"app-logs-[[DEVICE_IDENTIFIER]].txt\"></iframe>
<iframe id=\"logs-iframe\" src=\"[[LOG_PATH]]\"></iframe>
</div>
<div id=\"design-review\">
[[TEST_DESIGN_REVIEW]]
Expand Down Expand Up @@ -1024,15 +1023,15 @@ struct HTMLTemplates
<span class=\"icon left screenshot-icon\" style=\"margin-left: [[PADDING]]px\"></span>
[[NAME]]
<span class=\"icon preview-icon\" data=\"[[FILENAME]]\" onclick=\"showScreenshot('[[FILENAME]]')\"></span>
<img class=\"screenshot\" src=\"[[PATH]]/Attachments/[[FILENAME]]\" id=\"screenshot-[[FILENAME]]\"/>
<img class=\"screenshot\" src=\"[[PATH]]\" id=\"screenshot-[[FILENAME]]\"/>
</p>
"""

static let text = """
<p class=\"attachment list-item\">
<span class=\"icon left text-icon\" style=\"margin-left: [[PADDING]]px\"></span>
[[NAME]]
<span class=\"icon preview-icon\" data=\"[[PATH]]/Attachments/[[FILENAME]]\" onclick=\"showText('[[PATH]]/Attachments/[[FILENAME]]')\"></span>
<span class=\"icon preview-icon\" data=\"[[PATH]]\" onclick=\"showText('[[PATH]]')\"></span>
</p>
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import Rainbow

struct Logger
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import XCResultKit

enum ActivityType: String {
case unknwown = ""
Expand Down Expand Up @@ -34,11 +35,11 @@ enum ActivityType: String {

struct Activity: HTML
{
var uuid: String
var padding = 0
var attachments: [Attachment]?
var startTime: TimeInterval?
var finishTime: TimeInterval?
let uuid: String
let padding: Int
let attachments: [Attachment]
let startTime: TimeInterval?
let finishTime: TimeInterval?
var totalTime: TimeInterval {
if let start = startTime, let finish = finishTime {
return finish - start
Expand All @@ -47,16 +48,14 @@ struct Activity: HTML
return 0.0
}
var title: String
var subActivities: [Activity]?
var subActivities: [Activity]
var type: ActivityType?
var hasGlobalAttachment: Bool {
let hasDirecAttachment = attachments?.count ?? 0 > 0
let subActivitesHaveAttachments = subActivities?.reduce(false) { $0 || $1.hasGlobalAttachment } ?? false
return hasDirecAttachment || subActivitesHaveAttachments
let hasDirectAttachment = !attachments.isEmpty
let subActivitesHaveAttachments = subActivities.reduce(false) { $0 || $1.hasGlobalAttachment }
return hasDirectAttachment || subActivitesHaveAttachments
}
var hasFailingSubActivities: Bool {
guard let subActivities = subActivities else { return false }

return subActivities.reduce(false) { $0 || $1.type == .assertionFailure || $1.hasFailingSubActivities }
}
var cssClasses: String {
Expand All @@ -71,28 +70,19 @@ struct Activity: HTML

return cls
}

init(screenshotsPath: String, dict: [String : Any], padding: Int) {
uuid = dict["UUID"] as! String
startTime = dict["StartTimeInterval"] as? TimeInterval
finishTime = dict["FinishTimeInterval"] as? TimeInterval
title = dict["Title"] as! String

let rawActivityType = dict["ActivityType"] as! String
if let activityType = ActivityType(rawValue: rawActivityType) {
type = activityType
} else {
Logger.warning("Activity type is not supported: \(rawActivityType). Skipping activity: \(title)")
init(summary: ActionTestActivitySummary, file: ResultFile, padding: Int = 0) {
self.uuid = summary.uuid
self.startTime = summary.start?.timeIntervalSince1970 ?? 0
self.finishTime = summary.finish?.timeIntervalSince1970 ?? 0
self.title = summary.title
self.subActivities = summary.subactivities.map {
Activity(summary: $0, file: file, padding: padding + 10)
}

if let rawAttachments = dict["Attachments"] as? [[String : Any]] {
attachments = rawAttachments.map { Attachment(screenshotsPath: screenshotsPath, dict: $0, padding: padding + 16) }
self.type = ActivityType(rawValue: summary.activityType)
self.attachments = summary.attachments.map {
Attachment(attachment: $0, file: file, padding: padding + 16)
}

if let rawSubActivities = dict["SubActivities"] as? [[String : Any]] {
subActivities = rawSubActivities.map { Activity(screenshotsPath: screenshotsPath, dict: $0, padding: padding + 10) }
}

self.padding = padding
}

Expand All @@ -105,16 +95,16 @@ struct Activity: HTML
"UUID": uuid,
"TITLE": title.stringByEscapingXMLChars,
"PAPER_CLIP_CLASS": hasGlobalAttachment ? "inline-block" : "none",
"PADDING": (subActivities == nil && (attachments == nil || attachments?.count == 0)) ? String(padding + 18) : String(padding),
"PADDING": (subActivities.isEmpty && attachments.isEmpty) ? String(padding + 18) : String(padding),
"TIME": totalTime.timeString,
"ACTIVITY_TYPE_CLASS": cssClasses,
"HAS_SUB-ACTIVITIES_CLASS": (subActivities == nil && (attachments == nil || attachments?.count == 0)) ? "no-drop-down" : "",
"SUB_ACTIVITY": subActivities?.reduce("", { (accumulator: String, activity: Activity) -> String in
"HAS_SUB-ACTIVITIES_CLASS": (subActivities.isEmpty && attachments.isEmpty) ? "no-drop-down" : "",
"SUB_ACTIVITY": subActivities.reduce("") { (accumulator: String, activity: Activity) -> String in
return accumulator + activity.html
}) ?? "",
"ATTACHMENTS": attachments?.reduce("", { (accumulator: String, attachment: Attachment) -> String in
},
"ATTACHMENTS": attachments.reduce("") { (accumulator: String, attachment: Attachment) -> String in
return accumulator + attachment.html
}) ?? "",
},
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import XCResultKit

enum AttachmentType: String {
case unknwown = ""
Expand Down Expand Up @@ -57,34 +58,26 @@ enum AttachmentName: RawRepresentable {

struct Attachment: HTML
{
var padding = 0
var filename: String
var path: String
var type: AttachmentType?
var name: AttachmentName?
let padding: Int
let filename: String
let path: String
let type: AttachmentType
let name: AttachmentName?

init(screenshotsPath: String, dict: [String : Any], padding: Int)
{
path = screenshotsPath
filename = dict["Filename"] as! String
let typeRaw = dict["UniformTypeIdentifier"] as! String

if let attachmentType = AttachmentType(rawValue: typeRaw) {
type = attachmentType
init(attachment: ActionTestAttachment, file: ResultFile, padding: Int = 0) {
self.filename = attachment.filename ?? ""
self.type = AttachmentType(rawValue: attachment.uniformTypeIdentifier) ?? .unknwown
self.name = attachment.name.map(AttachmentName.init(rawValue:))
if let id = attachment.payloadRef?.id,
let url = file.exportPayload(id: id) {
self.path = url.relativePath
} else {
Logger.warning("Attachment type is not supported: \(typeRaw). Skipping.")
}

if let name = dict["Name"] as? String {
self.name = AttachmentName(rawValue: name)
self.path = ""
}

self.padding = padding
}

var fallbackDisplayName: String {
guard let type = type else { return "Attachment" }

switch type {
case .png, .jpeg:
return "Screenshot"
Expand All @@ -107,18 +100,14 @@ struct Attachment: HTML
// PRAGMA MARK: - HTML

var htmlTemplate: String {
if let type = type {
switch type {
case .png, .jpeg:
return HTMLTemplates.screenshot
case .text, .html, .data:
return HTMLTemplates.text
case .unknwown:
return ""
}
switch type {
case .png, .jpeg:
return HTMLTemplates.screenshot
case .text, .html, .data:
return HTMLTemplates.text
case .unknwown:
return ""
}

return ""
}

var htmlPlaceholderValues: [String: String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extension JUnitReport.TestCase
state = .unknown
}

results = test.activities?.map { JUnitReport.TestResult(activity: $0) } ?? []
results = test.activities.map { JUnitReport.TestResult(activity: $0) }
}
}

Expand Down
Loading

0 comments on commit 24146b4

Please sign in to comment.