Skip to content

#24 TS Compilation testing #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object Versions {
const val kotlinxKover = "0.5.0"
const val kotlinxSerialization = "1.3.2"
const val ksp = "1.6.10-1.0.4"
const val gradleNodePlugin = "3.2.1"

const val kotest = "5.2.3"
}
Expand All @@ -36,9 +37,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-knit:${Versions.kotlinxKnit}")
implementation("org.jetbrains.kotlinx:kover:${Versions.kotlinxKover}")

// implementation("org.jetbrains.reflekt:gradle-plugin:1.6.10-1-SNAPSHOT") {
// isChanging = true
// }
implementation("com.github.node-gradle:gradle-node-plugin:${Versions.gradleNodePlugin}")
}


Expand Down
14 changes: 14 additions & 0 deletions buildSrc/repositories.settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ dependencyResolutionManagement {
mavenCentral()
jitpack()
gradlePluginPortal()

// Declare the Node.js download repository
ivy("https://nodejs.org/dist/") {
name = "Node Distributions at $url"
patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
metadataSources { artifact() }
content { includeModule("org.nodejs", "node") }
}
ivy("https://github.com/yarnpkg/yarn/releases/download") {
name = "Yarn Distributions at $url"
patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") }
metadataSources { artifact() }
content { includeModule("com.yarnpkg", "yarn") }
}
}

pluginManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
}

dependencies {
testImplementation(platform("io.kotest:kotest-bom:5.2.1"))
testImplementation(platform("io.kotest:kotest-bom:5.2.3"))
testImplementation("io.kotest:kotest-runner-junit5")
testImplementation("io.kotest:kotest-assertions-core")
testImplementation("io.kotest:kotest-property")
Expand Down Expand Up @@ -49,6 +49,6 @@ tasks.compileTestKotlin {
kotlinOptions.freeCompilerArgs += "-opt-in=io.kotest.common.ExperimentalKotest"
}

tasks.test {
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
29 changes: 29 additions & 0 deletions buildSrc/src/main/kotlin/buildsrc/convention/node.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package buildsrc.convention

plugins {
id("com.github.node-gradle.node")
id("buildsrc.convention.subproject")
}

val rootGradleDir: Directory by extra {
rootProject.layout.projectDirectory.dir(".gradle")
}

node {
download.set(true)

distBaseUrl.set(null as String?) // set in repositories.settings.gradle.kts

workDir.set(rootGradleDir.dir("nodejs"))
npmWorkDir.set(rootGradleDir.dir("npm"))
yarnWorkDir.set(rootGradleDir.dir("yarn"))
}

tasks.withType<Test> {
val npmInstallDir = tasks.npmSetup.map { it.npmDir.get().asFile.canonicalPath }
inputs.dir(npmInstallDir)

doFirst {
environment("NPM_INSTALL_DIR", npmInstallDir.get())
}
}
23 changes: 12 additions & 11 deletions docs/code/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
buildsrc.convention.`kotlin-jvm`
buildsrc.convention.node
kotlin("plugin.serialization")
id("org.jetbrains.kotlinx.knit")
}


val kotlinxSerializationVersion = "1.3.2"

dependencies {
Expand All @@ -14,17 +16,20 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")

implementation("org.jetbrains.kotlinx:kotlinx-knit:0.3.0")

implementation(kotlin("reflect"))


testImplementation(kotlin("test"))

testImplementation("org.jetbrains.kotlinx:kotlinx-knit-test:0.3.0")
testImplementation("com.github.pgreze:kotlin-process:1.3.1")
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
tasks.withType<KotlinCompile> {
mustRunAfter(tasks.knit)
kotlinOptions.freeCompilerArgs += listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
)
Expand All @@ -46,13 +51,9 @@ knit {
}
}

tasks.withType<Test>().configureEach { dependsOn(tasks.knit) }

tasks.test {
dependsOn(tasks.knit)
// finalizedBy(tasks.knitCheck)
// TSCompile tests are slow, they don't need to run every time
systemProperty("kotest.tags", "!TSCompile")
}

tasks.compileKotlin { mustRunAfter(tasks.knit) }

//tasks.knitCheck {
// dependsOn(tasks.test)
//}
3 changes: 2 additions & 1 deletion docs/code/example/example-map-primitive-05.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import dev.adamko.kxstsgen.*

@Serializable
data class Config(
val properties: Map<String?, String?>
val nullableVals: Map<String, String?>,
val nullableKeys: Map<String?, String>,
)

fun main() {
Expand Down
37 changes: 23 additions & 14 deletions docs/code/knit-test.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,41 @@
@file:Suppress("JSUnusedLocalSymbols")
package ${test.package}

import dev.adamko.kxstsgen.util.*
<#--import io.kotest.assertions.*-->
<#--import io.kotest.core.*-->
import io.kotest.core.spec.style.*
import io.kotest.matchers.*
<#--import io.kotest.matchers.string.*-->
import kotlinx.knit.test.*
import org.junit.jupiter.api.Test
import dev.adamko.kxstsgen.util.*

class ${test.name} {
class ${test.name} : FunSpec({

tags(Knit)

<#list cases as case><#assign method = test["mode.${case.param}"]!"custom">
@Test
fun test${case.name}() {
captureOutput("${case.name}") {
context("${case.name}") {
val actual = captureOutput("${case.name}") {
${case.knit.package}.${case.knit.name}.main()
}<#if method != "custom">.${method}(
}.normalizeJoin()

test("expect actual matches TypeScript") {
actual.shouldBe(
// language=TypeScript
"""
<#list case.lines as line>
<#list case.lines as line>
|${line}
</#list>
</#list>
""".trimMargin()
.normalize()
.normalize()
)
<#else>.also { lines ->
check(${case.param})
}
</#if>

test("expect actual compiles").config(tags = tsCompile) {
actual.shouldTypeScriptCompile()
}
}
<#sep>

</#list>
}
})
59 changes: 40 additions & 19 deletions docs/code/test/AbstractClassesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,45 @@
@file:Suppress("JSUnusedLocalSymbols")
package dev.adamko.kxstsgen.example.test

import dev.adamko.kxstsgen.util.*
import io.kotest.core.spec.style.*
import io.kotest.matchers.*
import kotlinx.knit.test.*
import org.junit.jupiter.api.Test
import dev.adamko.kxstsgen.util.*

class AbstractClassesTest {
@Test
fun testExampleAbstractClassSingleField01() {
captureOutput("ExampleAbstractClassSingleField01") {
class AbstractClassesTest : FunSpec({

tags(Knit)

context("ExampleAbstractClassSingleField01") {
val actual = captureOutput("ExampleAbstractClassSingleField01") {
dev.adamko.kxstsgen.example.exampleAbstractClassSingleField01.main()
}.normalizeJoin()
.shouldBe(

test("expect actual matches TypeScript") {
actual.shouldBe(
// language=TypeScript
"""
|export type Color = any;
|// interface Color {
|// rgb: number;
|// }
""".trimMargin()
.normalize()
.normalize()
)
}

test("expect actual compiles").config(tags = tsCompile) {
actual.shouldTypeScriptCompile()
}
}

@Test
fun testExampleAbstractClassPrimitiveFields01() {
captureOutput("ExampleAbstractClassPrimitiveFields01") {
context("ExampleAbstractClassPrimitiveFields01") {
val actual = captureOutput("ExampleAbstractClassPrimitiveFields01") {
dev.adamko.kxstsgen.example.exampleAbstractClassPrimitiveFields01.main()
}.normalizeJoin()
.shouldBe(

test("expect actual matches TypeScript") {
actual.shouldBe(
// language=TypeScript
"""
|export type SimpleTypes = any;
Expand All @@ -42,24 +52,35 @@ class AbstractClassesTest {
|// privateMember: string;
|// }
""".trimMargin()
.normalize()
.normalize()
)
}

test("expect actual compiles").config(tags = tsCompile) {
actual.shouldTypeScriptCompile()
}
}

@Test
fun testExampleAbstractClassAbstractField01() {
captureOutput("ExampleAbstractClassAbstractField01") {
context("ExampleAbstractClassAbstractField01") {
val actual = captureOutput("ExampleAbstractClassAbstractField01") {
dev.adamko.kxstsgen.example.exampleAbstractClassAbstractField01.main()
}.normalizeJoin()
.shouldBe(

test("expect actual matches TypeScript") {
actual.shouldBe(
// language=TypeScript
"""
|export type AbstractSimpleTypes = any;
|// export interface AbstractSimpleTypes {
|// rgb: number;
|// }
""".trimMargin()
.normalize()
.normalize()
)
}

test("expect actual compiles").config(tags = tsCompile) {
actual.shouldTypeScriptCompile()
}
}
}
})
Loading