question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trouble capturing Phantomjs via Karma when testing on a hosted agent

See original GitHub issue

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 > myapp@0.1.0 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 typescript@1.8.9 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! myapp@0.1.0 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 myapp@0.1.0 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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
BrianMikinskicommented, Mar 20, 2017

@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

9reactions
bonnicicommented, Mar 15, 2017

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”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PhantomJS not captured when ran via build server
I am using Karma and PhantomJS with Jasmine to test my AngularJS. When I run my gulp test locally it works fine, launches...
Read more >
Karma unable to run on Visual Studio Online 'PhantomJS ...
Coding example for the question Karma unable to run on Visual Studio Online 'PhantomJS have not captured in 60000 ms, killing.'-phantom.js.
Read more >
Error with Karma test runner and PhantomJS
I've included "karma-phantomjs-launcher" and "karma-teamcity-reporter" plugins. I'm using the command line runner in my build step with the ...
Read more >
karma-phantomjs-launcher@0.1.3 vulnerabilities - Snyk
Affected versions of this package are vulnerable to Remote Memory Exposure. If user input ends up in consume() argument and can become negative,...
Read more >
Customize JavaScript for Azure Pipelines - Microsoft Learn
Tools that you commonly use to build, test, and run JavaScript apps ... The hosted agents are regularly updated, and setting up this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found