Skip to content

Commit

Permalink
Move config.maxTextSize to script
Browse files Browse the repository at this point in the history
  • Loading branch information
platan committed Feb 2, 2023
1 parent d44f1a4 commit 7148954
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 45 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ test 1 - 213 ms :active, 2022-11-08T20:46:17.854+0100, 2022-11-08T20:46:18.067+0

Options:

| Key | Type | Description | Default |
|-------------------------------------------|---------|--------------------------------------------------------------------|------------------------------------------------------------|
| `formats.html.enabled` | boolean | Generate report in html format | `true` |
| `formats.html.script.embed` | boolean | If true mermaid source will be downloaded and used locally in html | `false` |
| `formats.html.script.src` | url | Url to mermaid which should be used to generate html report | `https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js` |
| `formats.html.mermaid.config.maxTextSize` | int | Limit on the size of text used to generate diagrams | `50000` |
| `formats.json.enabled` | boolean | Generate report in json format | `true` |
| `formats.mermaid.enabled` | boolean | Generate report in mermaid text format | `true` |
| Key | Type | Description | Default |
|------------------------------------------|---------|--------------------------------------------------------------------|------------------------------------------------------------|
| `formats.html.enabled` | boolean | Generate report in html format | `true` |
| `formats.html.script.embed` | boolean | If true mermaid source will be downloaded and used locally in html | `false` |
| `formats.html.script.src` | url | Url to mermaid which should be used to generate html report | `https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js` |
| `formats.html.script.config.maxTextSize` | int | Limit on the size of text used to generate diagrams | `50000` |
| `formats.json.enabled` | boolean | Generate report in json format | `true` |
| `formats.mermaid.enabled` | boolean | Generate report in mermaid text format | `true` |

`build.gradle.kts`:

Expand All @@ -131,13 +131,11 @@ configure<io.github.platan.tests_execution_chart.CreateTestsExecutionReportExten
formats {
html {
enabled.set(true)
mermaid {
script {
embed.set(false)
config {
maxTextSize.set(110000)
}
}
script {
embed.set(false)
src.set("https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js")
}
}
Expand All @@ -158,13 +156,11 @@ createTestsExecutionReport {
formats {
html {
enabled = true
mermaid {
script {
embed = false
config {
maxTextSize = 110000
}
}
script {
embed = false
src = "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"
}
}
Expand Down Expand Up @@ -225,7 +221,7 @@ Gradle can generate reports in JUnit XML format. But such reports cannot be used

## Unreleased

- (feature) Allow to set `maxTextSize` Mermaid config option
- (feature) Allow to set `maxTextSize` config option in Mermaid script in HTML report

## 0.1.0 (09 November 2022)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class TestsExecutionReportPlugin : Plugin<Project> {
) {
task.getFormats().getHtml().outputLocation
.set(createTestsExecutionReportExtension.getFormats().getHtml().outputLocation)
task.getFormats().getHtml().getMermaid().getConfig()
task.getFormats().getHtml().getScript().getConfig()
.maxTextSize.set(
createTestsExecutionReportExtension.getFormats().getHtml().getMermaid().getConfig().maxTextSize
createTestsExecutionReportExtension.getFormats().getHtml().getScript().getConfig().maxTextSize
)
task.getFormats().getHtml().getScript().src
.set(createTestsExecutionReportExtension.getFormats().getHtml().getScript().src)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ abstract class Html @Inject constructor(objectFactory: ObjectFactory) : Format(o
@Nested
abstract fun getScript(): Script

@Nested
abstract fun getMermaid(): HtmlMermaid

open fun script(action: Action<in Script>) {
action.execute(getScript())
}

open fun mermaid(action: Action<in HtmlMermaid>) {
action.execute(getMermaid())
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.github.platan.tests_execution_chart.config

import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Nested
import javax.inject.Inject

private const val DEFAULT_SRC = "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"
Expand All @@ -14,4 +16,11 @@ abstract class Script @Inject constructor(objectFactory: ObjectFactory) {

@get:Input
val embed: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(false)

@Nested
abstract fun getConfig(): ScriptConfig

open fun config(action: Action<in ScriptConfig>) {
action.execute(getConfig())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import javax.inject.Inject

private const val MAX_TEXT_SIZE = 50_000

abstract class HtmlMermaidConfig @Inject constructor(objectFactory: ObjectFactory) {
abstract class ScriptConfig @Inject constructor(objectFactory: ObjectFactory) {

@get:Input
val maxTextSize: Property<Int> = objectFactory.property(Int::class.java).convention(MAX_TEXT_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class HtmlGanttDiagramReporter(private val config: Html, private val lo
downloadFile(URL(src), "${reportsDir.absolutePath}/$scriptFileName")
src = scriptFileName
}
val maxTextSize = config.getMermaid().getConfig().maxTextSize.get()
val maxTextSize = config.getScript().getConfig().maxTextSize.get()
val htmlReport = template
.replace(GRAPH_PLACEHOLDER, mermaid)
.replace(MERMAID_SRC_PLACEHOLDER, src)
Expand Down
4 changes: 2 additions & 2 deletions test-projects/spock-single-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ createTestsExecutionReport {
formats {
html {
enabled = true
mermaid {
script {
config {
maxTextSize = 990
}
src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.js'
}
script { src = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.js' }
}
json { enabled = true }
mermaid { enabled = true }
Expand Down

0 comments on commit 7148954

Please sign in to comment.