Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChromeHeadless running with docker #189

Closed
mjh5153 opened this issue Oct 12, 2018 · 7 comments
Closed

ChromeHeadless running with docker #189

mjh5153 opened this issue Oct 12, 2018 · 7 comments

Comments

@mjh5153
Copy link

mjh5153 commented Oct 12, 2018

Getting a timeout error when running ChromeHeadless with karma inside a docker container. This is an Angular cli project with angular 6 with karma 3.0. We run Karma through a makefile script that uses docker-compose. Here's the Karma config file.

// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html

module.exports = function(config) {
  var host = process.env.HOST_IP || process.env.HOSTNAME;

  config.set({
    basePath: '',
    mime: {
      "text/x-typescript": ["ts", "tsx"]
    },
    frameworks: ['parallel', 'jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('karma-junit-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
      require('karma-parallel')
    ],
    parallelOptions: {
      executors: Math.ceil(require('os').cpus().length / 2),
      shardStrategy: 'round-robin'
    },
    client: {
      jasmine: {
        random: false // Don't run tests in random order
      }
    },
    customLaunchers: {
      Chrome_no_sandbox: {
        base: 'Chrome',
        flags: [
          '--headless',
          '--disable-web-security',
          '--disable-gpu',
          // Without a remote debugging port, Google Chrome exits immediately.
          '--remote-debugging-port=xxxx',
          '--remote-debugging-address=xxx.x.x.x'
        ]
      }
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'),
      reports: ['html', 'lcovonly', 'cobertura'],
      fixWebpackSourcePaths: true
    },
    // the default configuration
    junitReporter: {
      outputDir: './test-results', // results will be saved as $outputDir/$browserName.xml
      outputFile: 'test-results.xml', // if included, results will be saved as $outputDir/$browserName/$outputFile
      suite: '', // suite will become the package name attribute in xml testsuite element
      useBrowserName: false, // add browser name to report and classes names
      nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
      classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
      properties: {} // key value pair of properties to add to the <properties> section of the report
    },
    reporters:
      config.buildWebpack &&
      config.buildWebpack.options &&
      config.buildWebpack.options.codeCoverage
        ? ['progress', 'coverage-istanbul', 'junit']
        : ['progress', 'kjhtml'],
    hostname: host,
    port: process.env.KARMA_PORT,
    colors: true,
    logLevel: config.LOG_DEBUG,
    autoWatch: true,
    browsers: ['ChromeHeadless'],
    singleRun: false,
    captureTimeout: 100000,
    browserDisconnectTimeout: 10000,
    browserDisconnectTolerance: 1,
    browserNoActivityTimeout: 100000
  });
};
@mjh5153
Copy link
Author

mjh5153 commented Oct 12, 2018

Here's the error

12 10 2018 17:51:09.063:DEBUG [framework:karma-parallel]: registering browser id 23007463 with aggregated browser id 345830493895 at shard index 9
12 10 2018 17:51:09.064:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=bbH5sShszKC2jzOWAAAJ
12 10 2018 17:51:33.675:WARN [launcher]: ChromeHeadless have not captured in 100000 ms, killing.
12 10 2018 17:51:33.703:WARN [launcher]: ChromeHeadless have not captured in 100000 ms, killing.
12 10 2018 17:51:35.677:WARN [launcher]: ChromeHeadless was not killed in 2000 ms, sending SIGKILL.
12 10 2018 17:51:35.703:WARN [launcher]: ChromeHeadless was not killed in 2000 ms, sending SIGKILL.
12 10 2018 17:51:37.679:WARN [launcher]: ChromeHeadless was not killed by SIGKILL in 2000 ms, continuing.
12 10 2018 17:51:37.680:DEBUG [launcher]: Process ChromeHeadless exited with code -1
12 10 2018 17:51:37.682:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-74160764
12 10 2018 17:51:37.686:DEBUG [launcher]: ChromeHeadless failed (timeout). Not restarting.

@rmngrc
Copy link

rmngrc commented Nov 20, 2018

I think your issue is that what you have in the browsers option (ChromeHeadless) doesn't match with what you have in customLaunchers (Chrome_no_sandbox).

Have set it up mine this way and works for me:

Dockerfile:

FROM node:11.0-alpine

# Installs latest Chromium package
RUN apk update && apk upgrade && \
    echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories && \
    echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories && \
    apk add --no-cache bash chromium@edge nss@edge

# This line is to tell karma-chrome-launcher where
# chromium was downloaded and installed to.
ENV CHROME_BIN /usr/bin/chromium-browser

# Tell Puppeteer to skip installing Chrome.
# We'll be using the installed package instead.
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# Telling node-sass which pre-built binary to fetch.
# This way we don't need rebuilding node-sass each time!
ENV SASS_BINARY_NAME=linux-x64-67

# ...

Then in karma.conf.js:

browsers : ['ChromeHeadlessCustom'],
customLaunchers: {
  ChromeHeadlessCustom: {
    base: 'ChromeHeadless',
    flags: ['--no-sandbox']
  }
},
frameworks: [
  'jasmine',
],
plugins : [
  'karma-chrome-launcher',
  'karma-jasmine',
  // ...
],

@Krinkle
Copy link
Contributor

Krinkle commented Nov 21, 2018

It seems the main missing part in the configuration is --no-sandbox. This flag is required when using Chrome inside Docker. See also #158 and https://docs.travis-ci.com/user/chrome#sandboxing.

@rogeriopvl
Copy link
Collaborator

Closing this as the suggested configurations seem to fix the problem.

@Louspirit
Copy link

Is the watch feature supposed to work with this? It doesn't auto reload tests upon file save - like it does with Standard Chrome

@Krinkle
Copy link
Contributor

Krinkle commented Jan 4, 2022

@Louspirit I'm not aware of launchers having any influence on that behaviour, whether Firefox or Chrome, whether Headless or otherwise. Can you confirm that you are using the default ChromeHeadless launcher without custom launchers? What happens if you use Firefox instead, does the issue happen there? Most likely it will be a problem not related to launchers, and may be best filed as a new issue under the main Karma repo or ask in Karma's Gitter chat room.

@Louspirit
Copy link

@Krinkle indeed I am using a custom launcher because I am inside a docker container and running without --no-sandbox flag is not supported. This way I am able via port forward to access the karma screen. Only that watch is not working (maybe it's because of the --no-sandbox flag).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants