7

I am using Karma and PhantomJS with Jasmine to test my AngularJS. When I run my gulp test locally it works fine, launches PhantomJS and runs all my tests, but when the tests get run on the build server it fails with the following errors:

Note that I am using VSTS and using their built in cloud build system (hosted agent). Having said that its pretty much a task runner and I only use it to run gulp tasks (build, test etc) on checkin

[32m13 07 2016 15:21:32.260:INFO [karma]: [39mKarma v1.1.1 server started at http://localhost:9876/
[32m13 07 2016 15:21:32.262:INFO [launcher]: [39mLaunching browser PhantomJS with unlimited concurrency
[32m13 07 2016 15:21:32.284:INFO [launcher]: [39mStarting browser PhantomJS
[33m13 07 2016 15:22:32.285:WARN [launcher]: [39mPhantomJS have not captured in 60000 ms, killing.
[33m13 07 2016 15:22:34.287:WARN [launcher]: [39mPhantomJS was not killed in 2000 ms, sending SIGKILL.
[33m13 07 2016 15:22:36.288:WARN [launcher]: [39mPhantomJS was not killed by SIGKILL in 2000 ms, continuing.

My Karma config is:

var configuration = {
    basePath: "",
    files: listFiles(),

    singleRun: true,

    autoWatch: false,

    //usePolling: true,
    //transports: ["xhr-polling", "jsonp-polling"],

    frameworks: ["jasmine", "angular-filesort"],

    angularFilesort: {
        whitelist: [path.join(conf.paths.src, "/**/!(*.html|*.spec|*.mock).js")]
    },

    ngHtml2JsPreprocessor: {
        stripPrefix: "src/",
        moduleName: "veriApp"
    },

    browsers: ["PhantomJS"],
    //browsers: ["Chrome"],

    plugins: [
      "karma-chrome-launcher",
      "karma-phantomjs-launcher",
      "karma-angular-filesort",
      "karma-jasmine",
      "karma-ng-html2js-preprocessor"
    ],

    preprocessors: {
        "src/**/*.html": ["ng-html2js"]
    }
};

Here are the relevant parts of my package.json. Note that an NPM install is performed before the test is run

"karma": "1.1.1",
"karma-angular-filesort": "1.0.0",
"karma-jasmine": "1.0.2",
"karma-ng-html2js-preprocessor": "1.0.0",
"phantomjs-prebuilt": "2.1.4",
"karma-phantomjs-launcher": "1.0.0",
"karma-chrome-launcher": "1.0.1",

I've tried following advice from various answers regarding this but none seem to work! Perhaps I am missing something?

Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
Chris
  • 26,744
  • 48
  • 193
  • 345
  • Even though I have no idea what most of this is, I'm inclining to ask if the remote server has PhantomJS installed and if it is accessible via the running user's PATH. – apokryfos Jul 13 '16 at 15:29
  • @apokryfos It should do, I have setup my npm modules to include `phantom-prebuilt` - I'll update my question with the relevant parts of my package.json – Chris Jul 13 '16 at 15:50
  • Does PhantomJS attempt to launch an interactive process? Is so the VSTS build agent isn't allowed to do that. – James Davis - MSFT Jul 13 '16 at 16:23
  • @debugthings Honestly no idea, is there anyway around it if so? – Chris Jul 13 '16 at 16:26

1 Answers1

18

So... the solution is pretty easy but took a while to find:

Under the Variables tab of the build setup, add an environment variable:

PHANTOMJS_BIN C:\NPM\Modules\PhantomJS.cmd

Thanks to this link and this link.

Chris
  • 26,744
  • 48
  • 193
  • 345
  • 1
    Under VSTS, at the time of writing, I was only able to get this working with the variable under a 'Hosted' box, not Hosted VS2017. Not sure of the difference on the box that was causing this: https://www.visualstudio.com/en-us/docs/build/concepts/agents/hosted – David Douglas Anderson May 18 '17 at 08:31