https://kotlinlang.org logo
#javascript
Title
# javascript
c

CLOVIS

12/04/2023, 9:38 PM
Due to https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plug[…]jetbrains/kotlin/gradle/targets/js/testing/karma/KotlinKarma.kt, Chrome is always enabled as a browser. What if I don't want to use Chrome? How can I run tests only on Firefox? For context, I'm setting up my CI pipeline, and each browser is tested in parallel in a specific image that only has what is necessary. Thus, no Chrome in the Firefox tests.
h

hfhbd

12/04/2023, 9:50 PM
You can easily change the browser using the Gradle dsl
testTask { useFirefox() }
or set it with a property: https://youtrack.jetbrains.com/issue/KT-52951
c

CLOVIS

12/05/2023, 10:36 AM
I have
kotlin.js.browser.karma.browsers=firefox
but it still tries to execute Chrome too. As you can see in the code I linked above, KGP always adds Chrome, no matter what other browsers you specify.
h

hfhbd

12/05/2023, 10:44 AM
The link in KGP only adds the launcher dependency, but does not use Crome as default browser. This is handled in this line: https://github.com/JetBrains/kotlin/blob/405a502675bfeb2457ecdd15bee10e054d1c0934/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinBrowserJsIr.kt#L61, so you need to use an empty testTask:
Copy code
js(IR) {
  browser {
    testTask { }
  }
}
Sorry, you need to use this code:
Copy code
js(IR) {
  browser {
    testTask {
      useKarma {
      }
    }
  }
}
This results into: Execution failed for task 'sharedjsBrowserTest'.
No browsers configured for task 'sharedjsBrowserTest'