Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #346 from kwebio/kover
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity authored Oct 22, 2022
2 parents 0e92887 + 621bc81 commit 214fe17
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 101 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/kover.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Measure coverage

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Generate kover coverage report
run: ./gradlew koverXmlReport
- name: Add coverage report to PR
id: kover
uses: mi-kas/kover-report@v1
with:
path: ${{ github.workspace }}/build/reports/kover/xml/report.xml
token: ${{ secrets.GITHUB_TOKEN }}
title: Code Coverage
update-comment: true
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ plugins {

// See api/API_README.md for details
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.12.0"

// Coverage
id("org.jetbrains.kotlinx.kover") version "0.6.1"
}

group = "com.github.kwebio"
Expand Down Expand Up @@ -64,6 +67,8 @@ dependencies {

testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

testImplementation("org.awaitility:awaitility:4.2.0")
}

tasks.dokkaHtml {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/kweb/Kweb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class Kweb private constructor(
message.callback != null -> {
val (resultId, result) = message.callback
val resultHandler = remoteClientState.handlers[resultId]
?: error("No data handler for $resultId for client ${remoteClientState.id}")
?: error("No resultHandler for $resultId, for client ${remoteClientState.id}")
resultHandler(result)
}
message.keepalive -> {
Expand Down
51 changes: 29 additions & 22 deletions src/test/kotlin/kweb/HistoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.support.ThreadGuard
import org.awaitility.Awaitility.*
import java.time.Duration

@ExtendWith(SeleniumJupiter::class)
class HistoryTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
class HistoryTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {

val driver : WebDriver
val driver: WebDriver

init {
//ThreadGuard.protect ensures that the ChromeDriver can only be called by the thread that created it
//This should make this test thread safe.
driver = ThreadGuard.protect(unprotectedDriver)
driver = ThreadGuard.protect(unprotectedDriver)
}

companion object {
Expand All @@ -47,27 +49,30 @@ class HistoryTest(@Arguments("--headless") unprotectedDriver: ChromeDriver) {
fun testBackButton() {
historyTestApp.reloadCount.value shouldBe 0
driver.get("http://localhost:7665/0")
driver.findElement(By.tagName("a")).let { aElement ->
historyTestApp.url.value shouldBe "/0"
aElement.click()
Thread.sleep(100)
historyTestApp.url.value shouldBe "/1"
}
driver.findElement(By.tagName("a")).let { aElement ->
aElement.click()
Thread.sleep(100)
historyTestApp.url.value shouldBe "/2"
historyTestApp.reloadCount.value shouldBe 1

historyTestApp.url.value shouldBe "/0"
driver.findElement(By.tagName("a")).click()

await().untilAsserted { historyTestApp.url.value shouldBe "/1" }

await().pollInSameThread().untilAsserted {
// For some reason was getting a StaleElementReferenceException intermittently, so put this
// inaide an await()
driver.findElement(By.tagName("a")).click()
}

await().untilAsserted { historyTestApp.url.value shouldBe "/2" }
await().untilAsserted { historyTestApp.reloadCount.value shouldBe 1 }

driver.navigate().back()
Thread.sleep(100)
historyTestApp.url.value shouldBe "/1"
historyTestApp.reloadCount.value shouldBe 1

await().untilAsserted { historyTestApp.url.value shouldBe "/1" }
await().untilAsserted { historyTestApp.reloadCount.value shouldBe 1 }

driver.navigate().forward()
Thread.sleep(100)
historyTestApp.url.value shouldBe "/2"
historyTestApp.reloadCount.value shouldBe 1

await().untilAsserted { historyTestApp.url.value shouldBe "/2" }
await().untilAsserted { historyTestApp.reloadCount.value shouldBe 1 }
}
}

Expand All @@ -88,9 +93,11 @@ class HistoryTestApp {
route {
path("/{num}") { p ->
render(p["num"]!!.toInt()) { num ->
a().apply {
a {
element {
href = "/${num + 1}"
}
text("Next ($num)")
href = "/${num + 1}"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/kweb/HrefTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.bonigarcia.seljup.SeleniumJupiter
import io.kotest.matchers.shouldBe
import kweb.*
import kweb.state.KVar
import org.awaitility.Awaitility
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -49,10 +50,9 @@ class HrefTest(@Arguments("--headless") private var unprotectedDriver: ChromeDri
hrefTestApp.appUrl.value shouldBe "/"
hrefTestApp.renderCount.value shouldBe 1
aElement.click()
Thread.sleep(100)
hrefTestApp.appUrl.value shouldBe "/two"
Awaitility.await().untilAsserted { hrefTestApp.appUrl.value shouldBe "/two" }
// Page shouldn't have been re-rendered for a relative link
hrefTestApp.renderCount.value shouldBe 1
Awaitility.await().untilAsserted { hrefTestApp.renderCount.value shouldBe 1 }
}


Expand Down
14 changes: 6 additions & 8 deletions src/test/kotlin/kweb/InputCheckedTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import io.github.bonigarcia.seljup.SeleniumJupiter
import io.kotest.matchers.shouldBe
import kweb.*
import kweb.state.KVar
import org.awaitility.Awaitility
import org.awaitility.Awaitility.await
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -44,17 +46,13 @@ class InputCheckedTest(@Arguments("--headless") unprotectedDriver: ChromeDriver)
val input = driver.findElement(By.tagName("input"))
inputCheckedTestApp.checkKVar.value shouldBe false
input.click()
Thread.sleep(100)
inputCheckedTestApp.checkKVar.value shouldBe true
Thread.sleep(100)
await().untilAsserted { inputCheckedTestApp.checkKVar.value shouldBe true }
input.click()
Thread.sleep(100)
inputCheckedTestApp.checkKVar.value shouldBe false
await().untilAsserted { inputCheckedTestApp.checkKVar.value shouldBe false }

input.getAttribute("checked") shouldBe null
await().untilAsserted { input.getAttribute("checked") shouldBe null }
inputCheckedTestApp.checkKVar.value = true
Thread.sleep(100)
input.getAttribute("checked") shouldBe "true"
await().untilAsserted { input.getAttribute("checked") shouldBe "true" }
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/test/kotlin/kweb/SelectValueTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.bonigarcia.seljup.SeleniumJupiter
import io.kotest.matchers.shouldBe
import kweb.*
import kweb.state.KVar
import org.awaitility.Awaitility
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -43,14 +44,11 @@ class SelectValueTest(@Arguments("--headless") unprotectedDriver: ChromeDriver)
fun mainTest() {
driver.get("http://localhost:7668/")
val select = Select(driver.findElement(By.tagName("select")))
selectValueTestApp.selectValue.value shouldBe ""
Thread.sleep(100)
Awaitility.await().untilAsserted { selectValueTestApp.selectValue.value shouldBe "" }
select.selectByValue("cat")
Thread.sleep(100)
selectValueTestApp.selectValue.value shouldBe "cat"
Awaitility.await().untilAsserted { selectValueTestApp.selectValue.value shouldBe "cat" }
select.selectByValue("dog")
Thread.sleep(100)
selectValueTestApp.selectValue.value shouldBe "dog"
Awaitility.await().untilAsserted { selectValueTestApp.selectValue.value shouldBe "dog" }
}
}

Expand Down
Loading

0 comments on commit 214fe17

Please sign in to comment.