PhantomJS not captured when ran via build server

2019-03-27 10:07发布

问题:

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?

回答1:

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.