Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

#100 : Custom launcher Karma #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
Original file line number Diff line number Diff line change
@@ -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<String> = emptyList()
@Input
var displayName: String? = null

/**
* @return true when minimalistic configuration is present.
*/
fun isConfigured() = !name.isNullOrEmpty() && !base.isNullOrBlank()
}
Original file line number Diff line number Diff line change
@@ -29,6 +29,17 @@ open class KarmaConfigTask : DefaultTask() {
val preprocessors = extension.preprocessors.toMutableSet()
val clientConfig = mutableMapOf<String, Any>()

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(
Original file line number Diff line number Diff line change
@@ -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<String> = mutableListOf()

@@ -35,4 +40,8 @@ open class KarmaExtension {

@Input
var captureTimeout: Int = 60000

fun customLauncher(config: Action<in CustomLauncher>) {
config.execute(customLauncherConfig)
}
}