New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comply with html reporter format #160
Changes from 43 commits
460023f
93eba12
86e7c77
8e3cb2a
f3f6fae
c0b60c7
b8b7c5e
2f6779e
55329ce
17680bf
aa90691
d9153d0
e081c48
cfc2522
fbdb58e
e00f474
632fe0b
3441459
514dc4f
a9ffa5b
a548118
cf1d7ed
3abff6b
1a2bf82
6a9889e
1b36880
ab84208
92bdae4
aa3d36f
ab2a0a3
f92dde3
f9ac27d
6d64b56
5d818bb
564eb52
a582084
683435a
00ec106
308d05e
d1cf0bd
36a6916
ccddc52
faa01e5
bfc5431
34eadd4
d2b75d2
cc072dc
40ec153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package stryker4s.report | ||
import better.files.Resource | ||
import stryker4s.config.Config | ||
import stryker4s.model.MutantRunResults | ||
import stryker4s.report.mapper.MutantRunResultMapper | ||
|
||
class HtmlReporter(implicit config: Config) extends FinishedRunReporter with MutantRunResultMapper { | ||
|
||
private val reportVersion = "0.0.7" | ||
|
||
def indexHtml(json: String): String = { | ||
val mutationTestElementsScript = Resource.getAsString( | ||
s"META-INF/resources/webjars/mutation-testing-elements/$reportVersion/dist/mutation-test-elements.js") | ||
|
||
s"""<!DOCTYPE html> | ||
|<html> | ||
|<body> | ||
| <mutation-test-report-app title-postfix="Stryker4s report"></mutation-test-report-app> | ||
| <script> | ||
| document.querySelector('mutation-test-report-app').report = $json | ||
| </script> | ||
| <script> | ||
| $mutationTestElementsScript | ||
| </script> | ||
|</body> | ||
|</html>""".stripMargin | ||
} | ||
|
||
override def reportRunFinished(runResults: MutantRunResults): Unit = { | ||
val mapped = toReport(runResults).toJson | ||
|
||
println(mapped) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package stryker4s.report.mapper | ||
import java.nio.file.Path | ||
|
||
import stryker4s.config.{Config, Thresholds => ConfigThresholds} | ||
import stryker4s.model._ | ||
import stryker4s.report.model.MutantStatus.MutantStatus | ||
import stryker4s.report.model._ | ||
|
||
trait MutantRunResultMapper { | ||
|
||
private val schemaVersion = "1" | ||
|
||
def toReport(mutantRunResults: MutantRunResults)(implicit config: Config): MutationTestReport = MutationTestReport( | ||
schemaVersion, | ||
toThresholds(config.thresholds), | ||
toMutationTestResultMap(mutantRunResults.results.toSeq) | ||
) | ||
|
||
private def toThresholds(thresholds: ConfigThresholds): Thresholds = | ||
Thresholds(high = thresholds.high, low = thresholds.low) | ||
|
||
private def toMutationTestResultMap(results: Seq[MutantRunResult])( | ||
implicit config: Config): Map[String, MutationTestResult] = | ||
results groupBy (_.fileSubPath) map { | ||
case (path, runResults) => path.toString.replace('\\', '/') -> toMutationTestResult(runResults) | ||
} | ||
|
||
private def toMutationTestResult(runResults: Seq[MutantRunResult])(implicit config: Config): MutationTestResult = | ||
MutationTestResult( | ||
fileContentAsString(runResults.head.fileSubPath), | ||
runResults.map(toMutantResult) | ||
) | ||
|
||
private def toMutantResult(runResult: MutantRunResult): MutantResult = { | ||
val mutant = runResult.mutant | ||
MutantResult( | ||
mutant.id.toString, | ||
mutant.mutationType.mutationName, | ||
mutant.mutated.syntax, | ||
toLocation(mutant.original.pos), | ||
toMutantStatus(runResult) | ||
) | ||
} | ||
|
||
private def toLocation(pos: scala.meta.inputs.Position): Location = Location( | ||
start = Position(line = pos.startLine + 1, column = pos.startColumn + 1), | ||
end = Position(line = pos.endLine + 1, column = pos.endColumn + 1) | ||
) | ||
|
||
private def toMutantStatus(mutant: MutantRunResult): MutantStatus = mutant match { | ||
case _: Survived => MutantStatus.Survived | ||
case _: Killed => MutantStatus.Killed | ||
case _: NoCoverage => MutantStatus.NoCoverage | ||
case _: TimedOut => MutantStatus.Timeout | ||
case _: Error => MutantStatus.CompileError | ||
} | ||
|
||
private def fileContentAsString(path: Path)(implicit config: Config): String = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no real reason other than consistency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there's consistency on this throughout stryker4s though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. But now there is within the class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we'll save this discussion for later then. x) |
||
(config.baseDir / path.toString).contentAsString | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package stryker4s.report.model | ||
import io.circe.Encoder | ||
import stryker4s.report.model.MutantStatus.MutantStatus | ||
|
||
final case class MutationTestReport(schemaVersion: String, | ||
thresholds: Thresholds, | ||
files: Map[String, MutationTestResult]) { | ||
|
||
private implicit val encoder: Encoder[MutantStatus] = Encoder.enumEncoder(MutantStatus) | ||
|
||
def toJson: String = { | ||
import io.circe.generic.auto._ | ||
import io.circe.syntax._ | ||
this.asJson.noSpaces | ||
} | ||
} | ||
|
||
final case class MutationTestResult(source: String, mutants: Seq[MutantResult], language: String = "scala") | ||
|
||
final case class MutantResult(id: String, | ||
mutatorName: String, | ||
replacement: String, | ||
location: Location, | ||
status: MutantStatus) | ||
|
||
final case class Location(start: Position, end: Position) | ||
|
||
final case class Position(line: Int, column: Int) | ||
|
||
final case class Thresholds(high: Int, low: Int) | ||
|
||
object MutantStatus extends Enumeration { | ||
Wmaarts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type MutantStatus = Value | ||
val Killed, Survived, NoCoverage, CompileError, Timeout = Value | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of thoughts about this trait.
toReport
, if I'm correct.toLocation
makes more sense as an extension method. Now for example you're callingtoMutantStatus
, but I'm thinking: "you're going to MutantStatus... from where exactly?" if that makes sense. To me something likemapRunResultToMutantStatus
makes more sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. The single test is a bit massive. The thing is though is that the 'top' map function calls the other functions anyway. So then having tests for the 'smaller' functions is a bit redundant
Hmm, I feel like the "from where" is already apparent from it being given as a parameter (as well as the signature). Having names like
mapRunResultToMutantStatus
will get pretty big and unreadable. I agree the names could be better though