DEV Community

Michal Bryxí
Michal Bryxí

Posted on

Testing EmberJS app in Chrome in Docker

Assuming you already have an ember-cli app. First, let's create a Dockerfile:

# Dockerfile

FROM node:10-alpine

RUN npm install -g ember-cli

RUN \
  echo http://dl-3.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories  && \
  apk add chromium

WORKDIR /myapp

COPY . /myapp/

RUN yarn

CMD ["ember", "test"]
Enter fullscreen mode Exit fullscreen mode

Then you will need to alter your application testem.js. Note that we are not using Chrome, but Chromium:

module.exports = {
  test_page: 'tests/index.html?hidepassed',
  disable_watching: true,
  launch_in_ci: [
    'Chromium'
  ],
  launch_in_dev: [
    'Chromium'
  ],
  browser_args: {
    Chromium: {
      ci: [
        // --no-sandbox is needed when running Chrome inside a container
        // process.env.CI ? '--no-sandbox' : null,
        '--no-sandbox',
        '--headless',
        '--disable-gpu',
        '--disable-dev-shm-usage',
        '--disable-software-rasterizer',
        '--mute-audio',
        '--remote-debugging-port=0',
        '--window-size=1440,900'
      ].filter(Boolean)
    }
  }
};
Enter fullscreen mode Exit fullscreen mode

Build your container:

$ docker build -t myapp .
Enter fullscreen mode Exit fullscreen mode

And after this your tests should be able to run:

$ docker run myapp 
Could not start watchman
Visit https://ember-cli.com/user-guide/#watchman for more info.
cleaning up...
Built project successfully. Stored in "/myapp/tmp/class-tests_dist-RpV40XiD.tmp".
ok 1 Chrome 68.0 - [3 ms] - ESLint | app: app.js
ok 2 Chrome 68.0 - [0 ms] - ESLint | app: resolver.js
ok 3 Chrome 68.0 - [0 ms] - ESLint | app: router.js
ok 4 Chrome 68.0 - [0 ms] - ESLint | tests: test-helper.js
ok 5 Chrome 68.0 - [2 ms] - ember-qunit: Ember.onerror validation: Ember.onerror is functioning properly

1..5
# tests 5
# pass  5
# skip  0
# fail  0

# ok
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
thisismydesign profile image
thisismydesign

For me this fails with "Failed to read DnsConfig." I could only find this question but no solution: stackoverflow.com/questions/548383...

Collapse
 
jrock2004 profile image
John Costanzo

What do you do for watchman? Is there concern on file size of image with chromium installed?

Collapse
 
michalbryxi profile image
Michal Bryxí

If there is a need for watchman, it is certainly possible to install it. Last time I checked Apline and Debian had quite straightforward installation.

The image sizes are nothing small TBH, but gives you the whole UI testing options. Storage space is cheap, so never considered that an issue.