Running and Debugging Tests in a Docker Container

I want to pin my node.js app and run everything inside a docker container including tests.

Sounds simple if you are using PhantomJS and I actually tried this and it worked.

One thing I like about running tests in Chrome though is easy debugging. You can start the Karma server, open devtools, set a breakpoint in the test file (using the instruction debugger

) and start Karma - it will connect to the server test results and stop at the breakpoint, allowing you to do all sorts of things from there.

Now how to do this in a docker container?

  • Do I have to run the Karma server (with Chrome) on the hosting and tell somehow the Karma-runner inside the container to connect to it to run the tests? (How to do it?)

  • Is it possible to run Chrome in a docker container (this sounds like a silly question, but when I tried a docker search desktop

    bunch of things I guess it is possible (?)

  • Perhaps it is possible to debug tests in PhantomJS (although I doubt it will be as convenient as with Chrome devtools)

Could you share your experience with and debugging Karma tests in a docker container?

upd . I just figured out that it is possible to run the Karma server in a container and still debug the tests simply by going to the Karma page (for example localhost: 9876) from the host machine.

However, I still have a problem - I plan to install and start using Protractor. Now these tests definitely need to be run in a real browser (PhantomJS has too many quirks). Can anyone tell me how to run a Protractor test inside a docker container?

+3


source to share


1 answer


I don't know Protractor

and this is a workflow, but if you need a browser inside a container, have you seen this article? I will allow myself to quote this:



$ docker run -it \
    --net host \ # may as well YOLO
    --cpuset 0 \ # control the cpu
    --memory 512mb \ # max memory it can use
    -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
    -e DISPLAY=unix$DISPLAY \ # pass the display
    -v $HOME/Downloads:/root/Downloads \ # optional, but nice
    -v $HOME/.config/google-chrome/:/data \ # if you want to save state
    -v /dev/snd:/dev/snd --privileged \ # so we have sound
    --name chrome \
    jess/chrome

      

+4


source







All Articles