I have created a docker container which runs my angular project and now I'm trying to run my unit tests inside the container unsuccessfully. I need a headless browser to run my tests and PhantomJS is too buggy for my taste, also gives different results with Chrome, when running tests.
Here, I provide my Dockerfile:
# download (or use if it's in cache) the latest official image from node
FROM node:latest
# create directory in the container and set all privileges
RUN mkdir -p /usr/src/app && chmod 777 /usr/src/app
# make the directory available for following commands
WORKDIR /usr/src/app
# copy all local's frontend content to the WORKDIR
COPY . /usr/src/app
# Expose the port the app runs in
EXPOSE 4200
CMD ["npm", "start"]
I tried using Headless Chrome, but still it needs some more configuration that I don't know how to do it. Anyone having any thoughts?
after a lot of investigation, I found a way to do this:
I installed Chrome inside my frontend Dockerfile:
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list
RUN apt-get update && apt-get install --no-install-recommends -y google-chrome-stable
and I used headless Chrome for my tests with the proper configuration inside karma.config:
browsers: ['Chrome_without_sandbox'],
customLaunchers: {
Chrome_without_sandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox'] // with sandbox it fails under Docker
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With