Reputation: 748
I'm trying to run my frontend tests on Docker (node:8.15-alpine) using Chromium and Karma, however I'm getting lots of ChromeHeadless related errors.
These tests used to work but recently they suddenly stopped, so I'm guessing it's either related to a third-party dependency (apk?), or the local Docker install.
I've created a branch on the repo with an easy to run command which reproduces the issue. README.md here: https://github.com/olivercaine/react-redux-starter-kit-extended/tree/bug/cant-run-unit-tests-in-docker
Any help with this would be masively appreciated!
Thanks.
Expected Outcome:
[output of passed tests...]
Finished in 0.026 secs / 0.031 secs @ 19:53:44 GMT+1100 (AEDT)
SUMMARY:
✔ 46 tests completed
Actual Outcome:
13 02 2020 09:10:45.314:ERROR [launcher]: Cannot start ChromeHeadless
13 02 2020 09:10:45.316:ERROR [launcher]: ChromeHeadless stdout:
13 02 2020 09:10:45.317:ERROR [launcher]: ChromeHeadless stderr:
13 02 2020 09:10:45.772:ERROR [launcher]: Cannot start ChromeHeadless
13 02 2020 09:10:45.772:ERROR [launcher]: ChromeHeadless stdout:
13 02 2020 09:10:45.773:ERROR [launcher]: ChromeHeadless stderr:
13 02 2020 09:10:45.939:ERROR [launcher]: Cannot start ChromeHeadless
13 02 2020 09:10:45.939:ERROR [launcher]: ChromeHeadless stdout:
13 02 2020 09:10:45.939:ERROR [launcher]: ChromeHeadless stderr:
13 02 2020 09:10:46.424:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up.
Finished in 0 secs / 0 secs @ 09:10:46 GMT+0000 (UTC)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `cross-env NODE_ENV=test karma start build/karma.config`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-02-13T09_10_46_935Z-debug.log
Update:
The above URL has been removed, however the full (now working) repo can be found here:
https://github.com/olivercaine/react-redux-starter-kit-extended/tree/modpack/latest
Upvotes: 1
Views: 2772
Reputation: 748
Thanks Baptiste, your answer helped me verify the fix was working. Basically what I ended up doing was using a different URL for alpinelinux.org.
In the end I changed the Dockerfile to:
FROM node:8.15-alpine
WORKDIR /project
# Install Chrome
RUN echo http://dl-cdn.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
&& echo http://dl-cdn.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
&& echo http://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories \
&& apk --no-cache update && apk --no-cache upgrade \
&& apk add --no-cache chromium \
&& rm -rf /var/cache/apk/* /tmp/*
ENV CHROME_BIN /usr/bin/chromium-browser
which seemed to set the CHROME_BIN env variable properly, allowing me to run my tests in the Alpine container. Also meant I didn't need to update the karma.config.js file either. Previously I was using nl.alpinelinux.org/alpine/v3.8/ instead of edge.
Cheers for your help!
Upvotes: 0
Reputation: 299
It seems there are some issues regarding the node:8-alpine image that you are using. See https://github.com/puppeteer/puppeteer/issues/379. I don't know if it's the same issue but I was able to run your tests using the node:8.15-slim as the base image of your base Dockerfile
You'll need to update your dev Dockerfile as well:
FROM olliecaine/base:master
WORKDIR /project
# Install Chrome
RUN apt update && apt install -y chromium
Ideally you would add ENV CHROME_BIN=/usr/bin/chromium to this Dockerfile, but for some reason this is not setting the variable properly.
To check that yourself, and insert console.log(process.env.CHROME_BIN)
at the beginning of your build/karma.config.js file, you will see the value is still /usr/bin/chromium-browser when running the tests.
As a workaround, I had to insert this line at the beginning of the build/karma.config.js file:
process.env.CHROME_BIN = '/usr/bin/chromium'
Let me know if you understand why the ENV instruction is not working, I'm interested.
Upvotes: 1