Azure-pipelines-tasks: Trouble capturing Phantomjs via Karma when testing on a hosted agent

Created on 5 Apr 2016  路  13Comments  路  Source: microsoft/azure-pipelines-tasks

I'm trying to use a VSTS hosted agent to build my web app and run Jasmine tests through Karma. I'm using NPM to launch Karma using the task:

"test": "karma start --reporters mocha,junit --single-run --browsers PhantomJS",

I'm able to build my web app just fine, but Karma runs into issues trying to start the PhantomJS headless browser to run my tests. I'm seeing these messages in the logs:

2016-04-04T22:54:15.0148818Z [command]C:\Program Files\nodejs\npm.cmd run test
2016-04-04T22:54:15.9338829Z > [email protected] test C:\a\1\s
2016-04-04T22:54:15.9338829Z > karma start --reporters mocha,junit --single-run --browsers PhantomJS
2016-04-04T22:54:19.0078825Z START:
2016-04-04T22:54:35.1438831Z ts-loader: Using [email protected] and C:\a\1\s\test\tsconfig.json
2016-04-04T22:54:42.3838827Z 04 04 2016 22:54:42.380:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
2016-04-04T22:54:42.3958835Z 04 04 2016 22:54:42.393:INFO [launcher]: Starting browser PhantomJS
2016-04-04T22:57:42.3970982Z 04 04 2016 22:57:42.396:WARN [launcher]: PhantomJS have not captured in 180000 ms, killing.
2016-04-04T22:57:44.4000982Z 04 04 2016 22:57:44.399:WARN [launcher]: PhantomJS was not killed in 2000 ms, sending SIGKILL.
2016-04-04T22:57:46.4000995Z 04 04 2016 22:57:46.399:WARN [launcher]: PhantomJS was not killed by SIGKILL in 2000 ms, continuing.
2016-04-04T22:57:46.4090997Z Finished in 0 secs / 0 secs
2016-04-04T22:57:46.6030998Z npm ERR! Windows_NT 6.3.9600
2016-04-04T22:57:46.6040993Z npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
2016-04-04T22:57:46.6040993Z npm ERR! node v0.12.7
2016-04-04T22:57:46.6050995Z npm ERR! npm  v2.11.3
2016-04-04T22:57:46.6050995Z npm ERR! code ELIFECYCLE
2016-04-04T22:57:46.6060993Z npm ERR! [email protected] test: `karma start --reporters mocha,junit --single-run --browsers PhantomJS`
2016-04-04T22:57:46.6060993Z npm ERR! Exit status 1
2016-04-04T22:57:46.6060993Z npm ERR! 
2016-04-04T22:57:46.6070995Z npm ERR! Failed at the [email protected] test script 'karma start --reporters mocha,junit --single-run --browsers PhantomJS'.
2016-04-04T22:57:46.6070995Z npm ERR! This is most likely a problem with the myapp package,
2016-04-04T22:57:46.6080994Z npm ERR! not with npm itself.
2016-04-04T22:57:46.6080994Z npm ERR! Tell the author that this fails on your system:
2016-04-04T22:57:46.6080994Z npm ERR!     karma start --reporters mocha,junit --single-run --browsers PhantomJS
2016-04-04T22:57:46.6090992Z npm ERR! You can get their info via:
2016-04-04T22:57:46.6090992Z npm ERR!     npm owner ls myapp
2016-04-04T22:57:46.6100992Z npm ERR! There is likely additional logging output above.
2016-04-04T22:57:46.6100992Z npm ERR! Please include the following file with any support request:
2016-04-04T22:57:46.6100992Z npm ERR!     C:\a\1\s\npm-debug.log
2016-04-04T22:57:46.6230995Z ##[debug]rc:1
2016-04-04T22:57:46.6240986Z ##[debug]success:false
2016-04-04T22:57:46.6250991Z ##[debug]taskRunner fail
2016-04-04T22:57:46.6270971Z ##[debug]task result: Failed
2016-04-04T22:57:46.6330990Z Npm failed with error: C:\Program Files\nodejs\npm.cmd failed with return code: 1

I'm able to run this just fine on my Windows machine. I tried increasing the capture timeout in case it wasn't starting up within 60 seconds, but it still doesn't work with a timeout of 180 seconds. Could it be because I can't connect to http://localhost:9876/ with PhantomJS? Also, I'm not sure why Karma's not able to kill the process.

Is there a technique or workaround to get PhantomJS to launch properly and connect to Karma on a hosted agent?

Test

Most helpful comment

@ntziolis I was coming across the same issue and was able to resolve it by changing from "Hosted" to "Hosted VS2017" agent in the Options tab of my builds. Not sure if that's an option for you but something seems to have changed on the default Hosted agents that Microsoft is spinning up for us

All 13 comments

I discovered the problem:

The hosted VSO agent has a global copy of PhantomJS installed at C:\NPM\Modules\PhantomJS.cmd, but the exe file linked to the cmd is not at C:\NPM\Modules\node_modules\phantomjs\lib\phantom\phantomjs.exe.

When npm installs a Phantomjs dependency, the install checks if there's a global phantomjs install; if there is, it just stores the location to the global install and doesn't install a local version in node_modules.

Later, when the karma-phantomjs-launcher gets the location, if it receives the path to the global .cmd file, it naively walks from the .cmd file to cmdfile//node_modules//phantomjs//lib//phantom//phantomjs.exe. Since this doesn't exist on the hosted build agent, it doesn't start PhantomJS at all, and breaks, resulting in the 60 second time out, and subsequent not being able to kill the PhantomJS process.

I'll go file an issue on https://github.com/karma-runner/karma-phantomjs-launcher.

I am having the same issue, however, PhantomJS.cmd is not at the location C:\NPM\Modules\PhantomJS.cmd. I don't even have C:\NPM path.

I did add the environment variable PHANTOMJS_BIN into the build server with path to the npm install phantomjs -g installation path however this has not fixed the issue. Any help?

package.json

"karma-phantomjs-launcher": "1.0.0",
"phantomjs": "2.1.3",
"phantomjs-prebuilt": "2.1.3"

I've been running into the same issue as @chekkan - something was recently changed

@lediur @chekkan The hosted agent image has been updated recently. Can you try executing the task and let us know if the issue still exists?

@SatishThareja This issue seems to be back.

Here is our situation:

  • 2 days ago the commit in questions completed successfully including test runs
  • if I do a manual rerun of the same commit, it will now fail every time due to PhantomJS have not captured in xxx ms.

Questions:

  • Has the agent been updated recently again?
  • Is there a place where one can see when agents get updated and what the change log is?

You can find the details about the software on the hosted agent pool image here : https://www.visualstudio.com/en-us/docs/build/admin/agents/hosted-pool

Image updates are published here as well : https://blogs.msdn.microsoft.com/visualstudioalm/

In case anyone else lands here, the fix I found via stackoverflow is to add a build variable with the key "PHANTOMJS_BIN" and the value "C:\NPM\Modules\PhantomJS.cmd".

@ntziolis I was coming across the same issue and was able to resolve it by changing from "Hosted" to "Hosted VS2017" agent in the Options tab of my builds. Not sure if that's an option for you but something seems to have changed on the default Hosted agents that Microsoft is spinning up for us

@BrianMikinski Changing the type worked for me, thx!

I don't think either solution works anymore; I've tried the build agent variable;
image
And the Agent is the most recent possible version;
image

Any other ideas?

I have the same problem when I try to execute unit tests of an angular 5 application with a phantomjs browser (ng cli wrap karma) on VSTS.
When I use the _Hosted_ queue, I get this error :

2018-01-07T15:44:15.5926415Z > ng test --single-run=true --watch=false --code-coverage "--reporters=junit,progress" "--browsers=PhantomJS"
2018-01-07T15:44:15.5926758Z 
2018-01-07T15:44:28.1121799Z 07 01 2018 15:44:28.070:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
2018-01-07T15:44:28.1122355Z 07 01 2018 15:44:28.076:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
2018-01-07T15:44:28.1271165Z 07 01 2018 15:44:28.084:INFO [launcher]: Starting browser PhantomJS
2018-01-07T15:44:28.8297664Z (node:2940) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
2018-01-07T15:44:28.8298129Z parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
2018-01-07T15:45:28.1022794Z 07 01 2018 15:45:28.087:WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
2018-01-07T15:45:30.1050689Z 07 01 2018 15:45:30.104:WARN [launcher]: PhantomJS was not killed in 2000 ms, sending SIGKILL.
2018-01-07T15:45:32.1060881Z 07 01 2018 15:45:32.105:WARN [launcher]: PhantomJS was not killed by SIGKILL in 2000 ms, continuing.
2018-01-07T15:45:32.5133865Z 
2018-01-07T15:45:32.5135723Z npm ERR! Windows_NT 6.3.9600

But when I use the _Hosted Linux Preview_ or the _Hosted VS2017_ queues, unit tests are correctly executed.

@fredgate - you should also open another issue for the encoding problems (?s).

I do not know if it's a tease, but just in case: there is no encoding problem. On VSTS, everything is well displayed, these odd characters just appeared during the copy / paste on github.

Was this page helpful?
0 / 5 - 0 ratings