is there any way set karma options in the js plugi...
# javascript
p
is there any way set karma options in the js plugin? I found the declaration of
KarmaConfig
which has all the options, unfortunately the Karma’s
config
property is private. Id like to do use chrome headless in a test (which is run in a container) as explained here https://docs.travis-ci.com/user/chrome#sandboxing It seems like the translation into gradle.kts would be the following (but does not work because
config
is private)
Copy code
karma { 
    config.customLaunchers["ChromeHeadlessNoSandbox"] = CustomLauncher("ChromeHeadless").apply { flags.add("--no-sandbox") }
}
t
You can write additional js scripts in
karma.config.d
directory
p
could you point me to some documentation on how to go about it?
t
This feature is undocumented as I know
p
what do I put inside karma.config.d? The same file as documented here? http://karma-runner.github.io/4.0/config/configuration-file.html
or is it some special format?
t
You can use
config
variable for manipulation
Valid example
Copy code
config.basePath = '../..'
p
ok. what is the name of the file inside
karma.conf.d
directory?
t
All scripts will be applied
js extension required
p
thanks it worked
t
Do you need
--no-sandbox
in your case?
p
yes
I am testing inside a docker container in gitlab
t
Custom docker container?
With limited user you won’t need this flag
p
I know, it even says so before it crashes. I’m using gradle’s image as a base and add node and chrome headless on top. The image is not setup to work as any user.
you encouraged me to look into it again. It turns out gradle’s base image does set up a non-privileged user (called ‘gradle’) but it does not use it. When I switch to the unprivileged user by inserting
USER gradle
at the end of my Dockerfile it leads to a crash on my mac (apparently a bug in docker) but it works on gitlab ci. Now I don’t need the --no-sandbox workaround after all.
Regardless of my unsound use-case, it would be nice if
useConfigDirectory()
and its default value
karma.config.d
were documented
s
This doesn’t seem to work because
useBrowser
is private and I’m not able to define the custom launcher.
I’m using CodeBuild (AWS), and this requires the
-no-sandbox
option.
I set this up, and it seems to be using it:
Copy code
module.exports = function (config) {
    config.set({
        browsers: ['ChromeHeadlessNoSandbox'],
        customLaunchers: {
            ChromeHeadlessNoSandbox: {
                base: 'ChromeHeadless',
                flags: ['--no-sandbox']
            }

        }
    });
};
but I don’t see how to reference the
ChromeHeadlessNoSandbox
launcher. When I try to run, I get
No browsers configured for task ':client:jsBrowserTest'
but everything worth configuring is private in the Karma configuration
And yes, I do need this option. This is the default for CodeBuild, and I’m not going to make custom Docker images for a simple build.