I'm facing the same problem that was described in ...
# javascript
p
I'm facing the same problem that was described in https://kotlinlang.slack.com/archives/C0B8L3U69/p1583764679215200, that is: I cannot run unit tests because my Jenkins says
Copy code
[2021-12-10T10:37:29.209Z] > Task :frontend-react:browserTest
[2021-12-10T10:37:29.209Z] Cannot start ChromeHeadless
[2021-12-10T10:37:29.209Z] 	[1210/103728.346077:ERROR:<http://zygote_host_impl_linux.cc|zygote_host_impl_linux.cc>(90)] Running as root without --no-sandbox is not supported. See <https://crbug.com/638180>.
[2021-12-10T10:37:29.209Z] ChromeHeadless stdout:
[2021-12-10T10:37:29.209Z] ChromeHeadless stderr: [1210/103728.346077:ERROR:<http://zygote_host_impl_linux.cc|zygote_host_impl_linux.cc>(90)] Running as root without --no-sandbox is not supported. See <https://crbug.com/638180>.
I told Gradle plugin to look into `karma.config.d`:
Copy code
testTask {
    useKarma {
        useConfigDirectory("karma.config.d")
    }
}
and there I have
Copy code
module.exports = function(config) {
    config.set({
        browsers: ['ChromeHeadlessNoSandbox'],

        // you can define custom flags
        customLaunchers: {
            ChromeHeadlessNoSandbox: {
                base: 'ChromeHeadless',
                flags: ['--no-sandbox']
            }
        }
    })
}
but I'm not even sure if this config is picked up. Too bad Kotlin/JS's Gradle plugin does't allow building on top of available configs. E.g. if I could define:
Copy code
fun useChromeHeadlessNoSandbox() {
        config.customLaunchers["ChromeHeadlessNoSandbox"] = CustomLauncher("ChromeHeadless").apply {
            flags.add("--no-sandbox")
        }
        useChromeLike("ChromeHeadlessNoSandbox")
    }
it could work fine and without defining any extra files. Unfortunately,
config
is private now
defining no browser from within Gradle to leverage the JS file config entirely is not supported either, I get:
Copy code
> No browsers configured for task ':frontend-react:browserTest'
but it's not true - I did define them in karma.config.d/karma.js
I added
delay(10000)
in my unit test, then kept polling with
ps aux | grep chrome
to see Chrome's arguments. I didn't see
--no-sandbox
I made it work. My config: build.gradle.kts
Copy code
testTask {
                useKarma {
                   useConfigDirectory("$projectDir/karma.config.d")
                    useChromeHeadless()
                }
            }
karma.config.d/karma.conf.js
Copy code
config.set({
    browsers: ['ChromeHeadlessNoSandbox'],

    customLaunchers: {
        ChromeHeadlessNoSandbox: {
            base: 'ChromeHeadless',
            // Needed to work on Jenkins. Otherwise, there's an error:
            // 'Running as root without --no-sandbox is not supported. See <https://crbug.com/638180.>'
            flags: ['--no-sandbox'],
        }
    }
});
I'm not sure what was the issue, too many moving parts and too little time to pinpoint the issue 🤷
I'd really appreciate allowing more config capabilities with the Kotlin/JS Gradle plugin, even some preset like
useChromeHeadlessNoSandbox()
? it seems pretty popular now in k8s days
1
@Ilya Goncharov [JB] are you planning any works in Kotlin/JS Gradle plugin's API, to allow more flexible config?
i
@Piotr Krzemiński Yes, it is in plan. And I think something similar to your PR initially, to make separate method
🙌 1