Skip to content

Commit 452538e

Browse files
committed
add test for KMP project custom shared WasmJS/WasmWASI source set
This recreates the issue reported in #4116
1 parent 371fd6e commit 452538e

File tree

2 files changed

+59
-18
lines changed

2 files changed

+59
-18
lines changed

dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/kotestFiles.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ package org.jetbrains.dokka.gradle.utils
66
import com.github.difflib.DiffUtils
77
import com.github.difflib.UnifiedDiffUtils
88
import io.kotest.assertions.fail
9+
import io.kotest.matchers.MatcherResult
10+
import io.kotest.matchers.neverNullMatcher
11+
import io.kotest.matchers.paths.shouldBeAFile
12+
import io.kotest.matchers.paths.shouldExist
13+
import io.kotest.matchers.should
14+
import io.kotest.matchers.shouldNot
915
import java.io.IOException
1016
import java.io.OutputStream
1117
import java.nio.file.Path
@@ -178,3 +184,44 @@ class NullOutputStream : OutputStream() {
178184
// do nothing
179185
}
180186
}
187+
188+
189+
/**
190+
* Assert the given [Path] does not contain the given [text].
191+
*/
192+
fun Path.shouldContainText(
193+
text: String,
194+
ignoreCase: Boolean = false,
195+
) {
196+
this.shouldExist()
197+
this.shouldBeAFile()
198+
this should containText(text, ignoreCase)
199+
}
200+
201+
/**
202+
* Assert the given [Path] does not contain the given [text].
203+
*/
204+
fun Path.shouldNotContainText(
205+
text: String,
206+
ignoreCase: Boolean = false,
207+
) {
208+
this.shouldExist()
209+
this.shouldBeAFile()
210+
this shouldNot containText(text, ignoreCase)
211+
}
212+
213+
private fun containText(
214+
text: String,
215+
ignoreCase: Boolean = false,
216+
) =
217+
neverNullMatcher<Path> { value ->
218+
MatcherResult(
219+
value.useLines { lines ->
220+
lines.any { line ->
221+
line.contains(text, ignoreCase = ignoreCase)
222+
}
223+
},
224+
{ "$value should include '$text'" + if (ignoreCase) " (ignoring case)" else "" },
225+
{ "$value should not include '$text'" + if (ignoreCase) " (ignoring case)" else "" },
226+
)
227+
}

dokka-runners/dokka-gradle-plugin/src/testFunctional/kotlin/KmpSharedWasmTest.kt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
*/
44
package org.jetbrains.dokka.gradle
55

6-
import io.kotest.assertions.withClue
76
import io.kotest.core.spec.style.FunSpec
87
import io.kotest.inspectors.shouldForAll
98
import io.kotest.inspectors.shouldForNone
109
import io.kotest.matchers.paths.shouldBeAFile
1110
import io.kotest.matchers.sequences.shouldNotBeEmpty
1211
import io.kotest.matchers.string.shouldContain
13-
import io.kotest.matchers.string.shouldNotContainIgnoringCase
1412
import org.jetbrains.dokka.gradle.internal.DokkaConstants
1513
import org.jetbrains.dokka.gradle.utils.*
16-
import kotlin.io.path.name
17-
import kotlin.io.path.useLines
14+
import kotlin.io.path.*
1815

16+
/**
17+
* Small reproducer for issue reported by kotlinx-io
18+
* https://github.com/Kotlin/dokka/issues/4116
19+
*/
1920
class KmpSharedWasmTest : FunSpec({
2021
context("given a KMP project with a custom shared Wasm source set") {
2122
val project = initKmpSharedWasmProject()
@@ -33,22 +34,17 @@ class KmpSharedWasmTest : FunSpec({
3334
}
3435

3536
test("expect no 'unknown class' message in HTML files") {
36-
val htmlFiles = project.projectDir.toFile()
37+
val htmlFiles = project.projectDir
3738
.resolve("build/dokka/html")
3839
.walk()
39-
.filter { it.isFile && it.extension == "html" }
40+
.filter { it.isRegularFile() && it.extension == "html" }
4041

4142
htmlFiles.shouldNotBeEmpty()
4243

4344
htmlFiles.forEach { htmlFile ->
44-
val relativePath = htmlFile.relativeTo(project.projectDir.toFile())
45-
htmlFile.useLines { lines ->
46-
withClue("$relativePath should not contain Error class: unknown class") {
47-
lines.shouldForAll { line -> line.shouldNotContainIgnoringCase("Error class: unknown class") }
48-
}
49-
withClue("$relativePath should not contain ERROR CLASS: Symbol not found") {
50-
lines.shouldForAll { line -> line.shouldNotContainIgnoringCase("ERROR CLASS: Symbol not found") }
51-
}
45+
htmlFile.relativeTo(project.projectDir).apply {
46+
shouldNotContainText("Error class: unknown class")
47+
shouldNotContainText("ERROR CLASS: Symbol not found")
5248
}
5349
}
5450
}
@@ -79,19 +75,17 @@ private fun initKmpSharedWasmProject(
7975
""".trimMargin()
8076

8177
buildGradleKts = """
82-
|import org.jetbrains.kotlin.gradle.*
83-
|
8478
|plugins {
8579
| kotlin("multiplatform") version embeddedKotlinVersion
8680
| id("org.jetbrains.dokka") version "${DokkaConstants.DOKKA_VERSION}"
8781
|}
8882
|
89-
|@OptIn(ExperimentalWasmDsl::class)
83+
|@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)
9084
|kotlin {
9185
| wasmJs { browser() }
9286
| wasmWasi { nodejs() }
9387
|
94-
| @OptIn(ExperimentalKotlinGradlePluginApi::class)
88+
| @OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
9589
| applyDefaultHierarchyTemplate {
9690
| common {
9791
| group("wasm") {

0 commit comments

Comments
 (0)