Skip to content

Commit

Permalink
Fix test suites running for ios target (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
OptimumCode authored Jul 28, 2023
1 parent 2a8b3a2 commit e136ff0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ kotlin {
val macOsTargets = listOf<KotlinTarget>(
macosX64(),
macosArm64(),
iosX64(),
iosArm64(),
iosSimulatorArm64(),
)
Expand Down
13 changes: 13 additions & 0 deletions test-suites/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove when migrate to Gradle 8
Expand Down Expand Up @@ -34,6 +36,7 @@ kotlin {
val macOsTargets = listOf<KotlinTarget>(
macosX64(),
macosArm64(),
iosX64(),
iosArm64(),
iosSimulatorArm64(),
)
Expand Down Expand Up @@ -115,6 +118,16 @@ kotlin {
}
}

tasks.withType<KotlinJsTest> {
// This is used to pass the right location for Node.js test
environment("TEST_SUITES_DIR", "$projectDir/schema-test-suite/tests")
}

tasks.withType<KotlinNativeSimulatorTest> {
// prefix SIMCTL_CHILD_ is used to pass the env variable to the simulator
environment("SIMCTL_CHILD_TEST_SUITES_DIR", "$projectDir/schema-test-suite/tests")
}

ktlint {
version.set(libs.versions.ktlint)
reporters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.mpp.env
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
Expand Down Expand Up @@ -50,10 +51,12 @@ internal fun FunSpec.runTestSuites(
val testSuiteDir = when {
fs.exists(TEST_SUITES_DIR) -> TEST_SUITES_DIR
fs.exists(TEST_SUITES_DIR_FROM_ROOT) -> TEST_SUITES_DIR_FROM_ROOT
else -> fs.resolveRoot()
else -> env(TEST_SUITES_DIR_ENV_VAR)?.toPath()
}?.resolve(draftName)
?: error("neither $TEST_SUITES_DIR or $TEST_SUITES_DIR_FROM_ROOT exist " +
"(current dir: ${fs.canonicalize(".".toPath())})")
?: error(
"neither $TEST_SUITES_DIR or $TEST_SUITES_DIR_FROM_ROOT exist " +
"(current dir: ${fs.canonicalize(".".toPath())}, env: ${env(TEST_SUITES_DIR_ENV_VAR)})",
)

require(fs.exists(testSuiteDir)) { "folder $testSuiteDir does not exist" }

Expand Down Expand Up @@ -134,17 +137,6 @@ private class SchemaTest(

private val TEST_SUITES_DIR: Path = "schema-test-suite/tests".toPath()
private val TEST_SUITES_DIR_FROM_ROOT: Path = "test-suites".toPath() / TEST_SUITES_DIR

/**
* This function tries to find the repo root using `build` folder as maker.
*
* This is done in order to execute NodeJS tests
*/
private fun FileSystem.resolveRoot(): Path? {
val absolutePath = canonicalize(".".toPath())
return generateSequence(absolutePath) {
it.parent
}.find { it.name == "build" }?.parent?.resolve(TEST_SUITES_DIR_FROM_ROOT)
}
private const val TEST_SUITES_DIR_ENV_VAR: String = "TEST_SUITES_DIR"

expect fun fileSystem(): FileSystem

0 comments on commit e136ff0

Please sign in to comment.