Skip to content

Commit

Permalink
refactor: Move tests to other directory, add tests dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Feb 13, 2022
1 parent 00bfdb6 commit 417f2ec
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 63 deletions.
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-html:0.7.3")
implementation("org.jetbrains.kotlin-wrappers:kotlin-extensions:1.0.1-pre.294-kotlin-1.6.10")
implementation(npm("pixi.js", "6.2.2"))
testImplementation(kotlin("test-js"))
testImplementation(kotlin("test-junit"))
testImplementation(kotlin("test-js-runner"))
}

tasks {
Expand All @@ -56,6 +59,12 @@ kotlin {
cssSupport.enabled = true
outputFileName = "dist.js"
}

testTask {
useKarma {
useChromeHeadless()
}
}
}
binaries.executable()
}
Expand Down
42 changes: 0 additions & 42 deletions src/main/kotlin/tests/Main.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pixi.utils
package utils

import kotlinext.js.jso
import pixi.typings.app.Application
Expand Down
59 changes: 59 additions & 0 deletions src/test/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package tests

import kotlinx.browser.document
import kotlinx.browser.window
import pixi.typings.app.Application
import pixi.typings.loaders.Loader
import pixi.typings.sprite.Sprite
import pixi.typings.ticker.Ticker
import utils.Application
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertNotNull

lateinit var app: Application

class Tests {
lateinit var sprite: Sprite

init {
println("executing main")
pixi.typings.require("pixi.js")
app = Application {
backgroundColor = (0xf0f0f0).toDouble()
resizeTo = window
}

Loader.shared.add("test", "test.png").load { _, _ -> start() }
document.getElementById("root")!!.appendChild(app.view)
}

fun start() {
val size = 250.0
sprite = Sprite.from("test.png").apply {
width = size
height = size
anchor.set(0.5)
}

Ticker.shared.add<Any>({ _, _ ->
sprite.apply {
x = (Random.nextDouble() * window.innerWidth).coerceIn(size / 2, window.innerWidth - size / 2)
y = (Random.nextDouble() * window.innerHeight).coerceIn(size / 2, window.innerHeight - size / 2)
}
})

app.stage.addChild(sprite)
}

@Test
fun testAppAdded() {
assertNotNull(document.querySelector("canvas"))
}

@Test
fun testSprite() {
assertContains(app.stage.children, sprite)
}
}
16 changes: 8 additions & 8 deletions src/main/resources/index.css → src/test/resources/index.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
* {
margin: 0;
padding: 0;
}

body {
overflow: hidden;
}
* {
margin: 0;
padding: 0;
}

body {
overflow: hidden;
}
24 changes: 12 additions & 12 deletions src/main/resources/index.html → src/test/resources/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS Client</title>
<link href="index.css" rel="stylesheet">
</head>
<body>
<script defer src="dist.js"></script>
<div id="root"></div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS Client</title>
<link href="index.css" rel="stylesheet">
</head>
<body>
<script defer src="dist.js"></script>
<div id="root"></div>
</body>
</html>
File renamed without changes

0 comments on commit 417f2ec

Please sign in to comment.