diff --git a/README.md b/README.md index 2d66480..43623b6 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,24 @@ kotlinFrontend { } ``` +In some cases you need to define a Karma custom launcher configuration. Here an example for Chrome headless: + +``` +kotlinFrontend { + karma { + browsers = ["ChromeHeadless"] + plugins = ["karma-chrome-launcher", + ...] + customLauncher { + name = "ChromeHeadlessNoSandbox" + base = "ChromeHeadless" + flags = ["--no-sandbox"] + displayName = "Chrome headless browser" + } + } +} +``` + Your custom config file will be copied to the build folder and renamed to `karma.config.js`. karma log is located at `build/logs/karma.log` diff --git a/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/CustomLauncher.kt b/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/CustomLauncher.kt new file mode 100644 index 0000000..74bf16b --- /dev/null +++ b/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/CustomLauncher.kt @@ -0,0 +1,25 @@ +package org.jetbrains.kotlin.gradle.frontend.karma + +import org.gradle.api.tasks.Input +import java.io.Serializable + +/** + * Custom browner launcher configuration for Karma. + * + * http://karma-runner.github.io/2.0/config/browsers.html + */ +open class CustomLauncher : Serializable { + @Input + var name: String? = null + @Input + var base: String? = null + @Input + var flags: List = emptyList() + @Input + var displayName: String? = null + + /** + * @return true when minimalistic configuration is present. + */ + fun isConfigured() = !name.isNullOrEmpty() && !base.isNullOrBlank() +} \ No newline at end of file diff --git a/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaConfigTask.kt b/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaConfigTask.kt index 9eddff4..e733a79 100644 --- a/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaConfigTask.kt +++ b/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaConfigTask.kt @@ -29,6 +29,17 @@ open class KarmaConfigTask : DefaultTask() { val preprocessors = extension.preprocessors.toMutableSet() val clientConfig = mutableMapOf() + val customLauncher = if (extension.customLauncherConfig.isConfigured()) { + val launcher = extension.customLauncherConfig + mapOf(launcher.name to mutableMapOf("base" to launcher.base, "flags" to launcher.flags).apply { + if (!launcher.displayName.isNullOrBlank()) { + put("displayName", launcher.displayName) + } + }) + } else { + null + } + if (extension.customConfigFile.isNotBlank()) { val file = project.projectDir.resolve(extension.customConfigFile) file.copyTo(project.buildDir.resolve("karma.conf.js"), true) @@ -46,6 +57,7 @@ open class KarmaConfigTask : DefaultTask() { "colors" to false, "autoWatch" to true, "browsers" to extension.browsers, + "customLaunchers" to customLauncher, "captureTimeout" to extension.captureTimeout, "singleRun" to false, "preprocessors" to mapOf( diff --git a/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaExtension.kt b/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaExtension.kt index aa705b2..e0ad8d8 100644 --- a/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaExtension.kt +++ b/kotlin-frontend/src/main/kotlin/org/jetbrains/kotlin/gradle/frontend/karma/KarmaExtension.kt @@ -1,5 +1,7 @@ package org.jetbrains.kotlin.gradle.frontend.karma +import groovy.lang.Closure +import org.gradle.api.Action import org.gradle.api.tasks.* open class KarmaExtension { @@ -21,6 +23,9 @@ open class KarmaExtension { @Input var browsers = mutableListOf("PhantomJS") + @Input + var customLauncherConfig: CustomLauncher = CustomLauncher() + @Input var plugins: MutableList = mutableListOf() @@ -35,4 +40,8 @@ open class KarmaExtension { @Input var captureTimeout: Int = 60000 + + fun customLauncher(config: Action) { + config.execute(customLauncherConfig) + } }