Skip to content

Commit

Permalink
Add MermaidTestsReporterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
platan committed Nov 1, 2023
1 parent 00b7d85 commit a861b52
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.github.platan.tests_execution_chart.reporters.json

import io.github.platan.tests_execution_chart.report.data.Mark
import io.github.platan.tests_execution_chart.report.data.TestExecutionScheduleReport
import io.github.platan.tests_execution_chart.report.data.TimedTestResult
import io.github.platan.tests_execution_chart.report.TestExecutionScheduleReportBuilder
import spock.lang.Specification
import spock.lang.TempDir

Expand All @@ -18,9 +16,9 @@ class JsonReporterTest extends Specification {
def "should generate report in json"() {
given:
def configOutputLocation = "my-output-location"
def report = new TestExecutionScheduleReport([
new TimedTestResult('class', 'test', toEpochMilli('2023-03-10T19:00:02Z'), toEpochMilli('2023-03-10T19:00:05Z'), 'passed', TEST)
], [new Mark('mark1', toEpochMilli('2023-03-10T19:00:05Z'))])
def report = new TestExecutionScheduleReportBuilder()
.addResult('class', 'test', toEpochMilli('2023-03-10T19:00:02Z'), toEpochMilli('2023-03-10T19:00:05Z'), 'passed', TEST)
.addMark('mark1', toEpochMilli('2023-03-10T19:00:05Z')).build()
def reporter = new JsonReporter().tap {
it.setConfiguration(new JsonConfig(true, configOutputLocation))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.github.platan.tests_execution_chart.reporters.mermaid

import io.github.platan.tests_execution_chart.report.TestExecutionScheduleReportBuilder
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.TempDir

import java.time.Instant

import static io.github.platan.tests_execution_chart.report.data.TimedTestResult.Type.TEST

class MermaidTestsReporterTest extends Specification {

@TempDir
File baseDir

def configOutputLocation = "my-output-location"

@Subject
def reporter = new MermaidTestsReporter().tap {
it.setConfiguration(new MermaidConfig(true, configOutputLocation))
}

def "should generate report in mermaid format"() {
given:
def report = new TestExecutionScheduleReportBuilder()
.addResult('class', 'test', toEpochMilli('2023-03-10T19:00:02Z'), toEpochMilli('2023-03-10T19:00:05Z'), 'passed', TEST)
.addMark('mark1', toEpochMilli('2023-03-10T19:00:05Z')).build()

when:
reporter.report(report, baseDir, "taskname")

then:
def reportFile = new File(baseDir, "$configOutputLocation/taskname.txt")
reportFile.text ==
"""|gantt
|dateFormat YYYY-MM-DDTHH:mm:ss.SSSZZ
|axisFormat %H:%M:%S.%L
|section class
|test - 3000 ms :2023-03-10T20:00:02.000+0100, 2023-03-10T20:00:05.000+0100
|mark1 : milestone, 2023-03-10T20:00:05.000+0100, 0
|""".stripMargin()
}

private static long toEpochMilli(String instant) {
Instant.parse(instant).toEpochMilli()
}
}

0 comments on commit a861b52

Please sign in to comment.