Skip to content

Commit

Permalink
JS config
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Oct 31, 2024
1 parent a473c6f commit f9bb474
Showing 1 changed file with 29 additions and 53 deletions.
82 changes: 29 additions & 53 deletions buildSrc/src/main/kotlin/JsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,22 @@
*/

import org.gradle.api.Project
import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension


inline fun KotlinJsTargetDsl.configJs(
nodeJs: Boolean = true,
browser: Boolean = true,
block: () -> Unit = {}
) {
if (nodeJs) {
nodejs()
// {
//// testTask {
//// useMocha {
//// timeout = "10000"
//// }
//// }
// }
}

if (browser) {
browser()
// {
// testTask{
// useKarma {
// useChromeHeadless()
// // useConfigDirectory(File(project.rootProject.projectDir, "karma"))
// }
// }
// }
nodejs {
testTask {
useMocha {
timeout = "10000"
}
}
}
}

binaries.library()
Expand All @@ -59,30 +42,24 @@ inline fun KotlinJsTargetDsl.configJs(
fun Project.configJsTestTasks() {
// val shouldRunJsBrowserTest = !hasProperty("teamcity") || hasProperty("enable-js-tests")
// if (shouldRunJsBrowserTest) return
tasks.findByName("cleanJsBrowserTest")?.apply {
onlyIf { false }
}
tasks.findByName("jsBrowserTest")?.apply {
onlyIf { false }
}
// tasks.findByName("cleanJsBrowserTest")?.apply {
// onlyIf { false }
// }
// tasks.findByName("jsBrowserTest")?.apply {
// onlyIf { false }
// }
}

inline fun KotlinWasmJsTargetDsl.configWasmJs(
nodeJs: Boolean = true,
browser: Boolean = true,
block: () -> Unit = {}
) {
if (nodeJs && isLinux) {
// win in candy node `21.0.0-v8-canary202309143a48826a08` is not supported
// nodejs()
}

if (browser) {
browser {
testTask{
useKarma {
useChromeHeadless()
// useConfigDirectory(File(project.rootProject.projectDir, "karma"))
nodejs {
testTask {
useMocha {
timeout = "10000"
}
}
}
Expand All @@ -93,18 +70,17 @@ inline fun KotlinWasmJsTargetDsl.configWasmJs(
}

inline fun Project.configWasmJsTest(block: () -> Unit = {}) {
if (false) {
// see https://youtrack.jetbrains.com/issue/KT-63014/Running-tests-with-wasmJs-in-1.9.20-requires-Chrome-Canary#focus=Comments-27-8321383.0-0
rootProject.the<NodeJsRootExtension>().apply {
// nodeVersion = "21.0.0-v8-canary202309143a48826a08"
version = "21.0.0-v8-canary202309143a48826a08"
downloadBaseUrl = "https://nodejs.org/download/v8-canary"
}

tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {
args.add("--ignore-engines")
}
}

// if (false) {
// // see https://youtrack.jetbrains.com/issue/KT-63014/Running-tests-with-wasmJs-in-1.9.20-requires-Chrome-Canary#focus=Comments-27-8321383.0-0
// rootProject.the<NodeJsRootExtension>().apply {
// // nodeVersion = "21.0.0-v8-canary202309143a48826a08"
// version = "21.0.0-v8-canary202309143a48826a08"
// downloadBaseUrl = "https://nodejs.org/download/v8-canary"
// }
//
// tasks.withType<org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask>().configureEach {
// args.add("--ignore-engines")
// }
// }
block()
}

0 comments on commit f9bb474

Please sign in to comment.