0
votes

currently, am trying to run the unit test cases of angular app in docker environment using ng test so it opens up a browser I don't need that in prod to happen so I tried RUN ng test --browser PhantomJS but it ain't working.

am getting this error 22 08 2017 11:52:42.355:WARN [karma]: No captured browser, open http://localhost:9876/ 22 08 2017 11:52:42.370:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/ 22 08 2017 11:52:42.370:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency 22 08 2017 11:52:42.382:INFO [launcher]: Starting browser PhantomJS 68% building modules 507/523 modules 16 active .../rxjs/observable/PromiseObs22 08 2017 11:52:53.039:WARN [karma]: No captured browser, open localhost:9876/ 22 08 2017 11:53:42.382:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing. 22 08 2017 11:53:44.383:WARN [launcher]: PhantomJS was not killed in 2000 ms, sending SIGKILL. 22 08 2017 11:53:46.385:WARN [launcher]: PhantomJS was not killed by SIGKILL in 2000 ms, continuing.

1
You never mentioned what is the error? Show logs of your execution - Tarun Lalwani

1 Answers

1
votes

You cannot run your angular tests without a browser as it is part of a front end application that only works when run on a browser. I see that you are trying to run it on PhantomJs. PhantomJs is a javascript project that is meant to emulate a browser for angular application testing.

From your perspective, all that you want is to ensure that the test runs and you dont really care about a browser opening. This is precisely what a 'headless' browser is. A browser with no GUI. PhantomJs, an example of a headless browser, has become popular in the past as it can run tests in pipeline without the need for a GUI. Today Chrome also offers a headless mode for test runners.

If you have set up your Karma configuration file properly with PhantomJs then you will find that it works correctly. Here is a link of person doing what you want in docker environment for a gitlab CI pipeline.

https://medium.com/letsboot/angular-4-and-testing-angular-cli-gitlab-ci-ng-test-phantomjs-tdd-afc20f50b928