Skip to content

Commit 5aa178b

Browse files
committed
add test
1 parent a73243a commit 5aa178b

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

dokka-aws/build.gradle.kts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
*/
55
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
66
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
7+
import java.time.LocalDate
78

89
/*
910
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1011
* SPDX-License-Identifier: Apache-2.0
1112
*/
1213
plugins {
14+
alias(libs.plugins.dokka)
1315
alias(libs.plugins.kotlin.jvm)
1416
}
1517

@@ -18,6 +20,16 @@ description = "Custom Dokka plugin for AWS Kotlin SDK API docs"
1820
dependencies {
1921
compileOnly(libs.dokka.base)
2022
compileOnly(libs.dokka.core)
23+
24+
testImplementation(libs.jsoup)
25+
testImplementation(libs.junit.jupiter)
26+
testImplementation(libs.kotest.assertions.core.jvm)
27+
testImplementation(libs.kotlin.test.junit5)
28+
}
29+
30+
tasks.test {
31+
useJUnitPlatform()
32+
dependsOn(tasks.dokkaHtml)
2133
}
2234

2335
tasks.withType<KotlinCompile> {
@@ -31,3 +43,30 @@ tasks.withType<JavaCompile> {
3143
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
3244
targetCompatibility = JavaVersion.VERSION_1_8.toString()
3345
}
46+
47+
48+
tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
49+
val sdkVersion: String by project
50+
moduleVersion.set(sdkVersion)
51+
52+
val year = LocalDate.now().year
53+
val pluginConfigMap = mapOf(
54+
"org.jetbrains.dokka.base.DokkaBase" to """
55+
{
56+
"customStyleSheets": [
57+
"${rootProject.file("docs/dokka-presets/css/logo-styles.css")}",
58+
"${rootProject.file("docs/dokka-presets/css/aws-styles.css")}"
59+
],
60+
"customAssets": [
61+
"${rootProject.file("docs/dokka-presets/assets/logo-icon.svg")}",
62+
"${rootProject.file("docs/dokka-presets/assets/aws_logo_white_59x35.png")}",
63+
"${rootProject.file("docs/dokka-presets/scripts/accessibility.js")}"
64+
],
65+
"footerMessage": "© $year, Amazon Web Services, Inc. or its affiliates. All rights reserved.",
66+
"separateInheritedMembers" : true,
67+
"templatesDir": "${rootProject.file("docs/dokka-presets/templates")}"
68+
}
69+
""",
70+
)
71+
pluginsMapConfiguration.set(pluginConfigMap)
72+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.dokka
6+
7+
import org.jsoup.Jsoup
8+
import org.junit.jupiter.api.Assumptions.assumeTrue
9+
import org.junit.jupiter.api.Test
10+
import org.junit.jupiter.api.TestInstance
11+
import java.io.File
12+
import kotlin.test.assertTrue
13+
14+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
15+
class DokkaAwsTest {
16+
@Test
17+
fun testLoadScripts() {
18+
val testFile = File("build/dokka/html/index.html")
19+
20+
assumeTrue(
21+
testFile.exists(),
22+
"Skipping test: test file does not exist",
23+
)
24+
25+
val document = Jsoup.parse(testFile, "UTF-8")
26+
27+
val expectedScripts = listOf(
28+
"awshome_s_code.js",
29+
)
30+
31+
val scripts = document.head().select("script[src]")
32+
33+
expectedScripts.forEach { expectedScript ->
34+
assertTrue(
35+
scripts.any { it.attr("src").endsWith(expectedScript) },
36+
"Expected script $expectedScript not found",
37+
)
38+
}
39+
}
40+
}

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ kotlinx-benchmark-version = "0.4.12"
2626
kotlinx-serialization-version = "1.7.3"
2727
mockk-version = "1.13.13"
2828
slf4j-version = "2.0.16"
29+
jsoup-version = "1.19.1"
2930

3031
[libraries]
3132
aws-kotlin-repo-tools-build-support = { module="aws.sdk.kotlin.gradle:build-support", version.ref = "aws-kotlin-repo-tools-version" }
@@ -111,6 +112,8 @@ smithy-aws-smoke-test-model = { module = "software.amazon.smithy:smithy-aws-smok
111112
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-version" }
112113
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-version" }
113114

115+
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup-version" }
116+
114117
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest-version" }
115118
kotest-assertions-core-jvm = { module = "io.kotest:kotest-assertions-core-jvm", version.ref = "kotest-version" }
116119
kotest-framework-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest-version" }

0 commit comments

Comments
 (0)