Gradle, js: fixes for groovy dsl

This commit is contained in:
Sergey Rostov
2019-05-15 11:04:23 +03:00
parent 7e4eaa8210
commit 3ede15b2b2
4 changed files with 55 additions and 4 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.gradle.targets.js.dsl
import groovy.lang.Closure
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
@@ -12,18 +13,49 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
interface KotlinJsTargetDsl {
fun browser() = browser { }
fun browser(body: KotlinJsBrowserDsl.() -> Unit)
fun browser(fn: Closure<*>) {
browser {
fn.delegate = this
fn.call()
}
}
fun nodejs() = nodejs { }
fun nodejs(body: KotlinJsNodeDsl.() -> Unit)
fun nodejs(fn: Closure<*>) {
nodejs {
fn.delegate = this
fn.call()
}
}
}
interface KotlinJsSubTargetDsl {
fun testTask(body: KotlinJsTest.() -> Unit)
fun testTask(fn: Closure<*>) {
testTask {
fn.delegate = this
fn.call()
}
}
}
interface KotlinJsBrowserDsl : KotlinJsSubTargetDsl {
fun runTask(body: KotlinWebpack.() -> Unit)
fun runTask(fn: Closure<*>) {
runTask {
fn.delegate = this
fn.call()
}
}
fun webpackTask(body: KotlinWebpack.() -> Unit)
fun webpackTask(fn: Closure<*>) {
testTask {
fn.delegate = this
fn.call()
}
}
}
interface KotlinJsNodeDsl : KotlinJsSubTargetDsl {
@@ -25,8 +25,6 @@ class KotlinBrowserJs(target: KotlinJsTarget) :
override fun configureDefaultTestFramework(it: KotlinJsTest) {
it.useKarma {
useMocha()
useWebpack()
useChromeHeadless()
}
}
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.gradle.targets.js.testing
import groovy.lang.Closure
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.SkipWhenEmpty
@@ -34,10 +35,28 @@ open class KotlinJsTest : KotlinTest(), RequiresNpmDependencies {
get() = testFramework!!.requiredNpmDependencies
fun useNodeJs(body: KotlinNodeJsTestRunner.() -> Unit) = use(KotlinNodeJsTestRunner(project), body)
fun useNodeJs(fn: Closure<*>) {
useNodeJs {
fn.delegate = this
fn.call()
}
}
fun useMocha(body: KotlinMocha.() -> Unit) = use(KotlinMocha(project), body)
fun useMocha(fn: Closure<*>) {
useMocha {
fn.delegate = this
fn.call()
}
}
fun useKarma(body: KotlinKarma.() -> Unit) = use(KotlinKarma(project), body)
fun useKarma(fn: Closure<*>) {
useKarma {
fn.delegate = this
fn.call()
}
}
private inline fun <T : KotlinJsTestFramework> use(runner: T, body: T.() -> Unit): T {
check(testFramework == null) {
@@ -44,6 +44,8 @@ class KotlinKarma(val project: Project) : KotlinJsTestFramework {
requiredDependencies.add(versions.karma)
useTeamcityReporter()
useMocha()
useWebpack()
config.singleRun = true
}
@@ -78,13 +80,13 @@ class KotlinKarma(val project: Project) : KotlinJsTestFramework {
requiredDependencies.add(dependency)
}
fun useMocha() {
private fun useMocha() {
requiredDependencies.add(versions.karmaMocha)
requiredDependencies.add(versions.mocha)
config.frameworks.add("mocha")
}
fun useWebpack() {
private fun useWebpack() {
requiredDependencies.add(versions.karmaWebpack)
addPreprocessor("webpack")