通过构建服务器

时间:2016-07-13 15:26:57

标签: angularjs phantomjs karma-runner azure-devops azure-pipelines-build-task

我正在使用Karma和PhantomJS与Jasmine来测试我的AngularJS。当我在本地运行我的gulp测试时它工作正常,启动PhantomJS并运行我的所有测试,但是当测试在构建服务器上运行时它会失败并出现以下错误:

请注意,我正在使用VSTS并使用其内置的云构建系统(托管代理)。说它几乎是一个任务运行器,我只用它来运行gulp任务(构建,测试等)在签到

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

我的Karma配置是:

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"]
    }
};

以下是package.json的相关部分。请注意,在运行测试之前执行NPM安装

"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",

我已经尝试过关于此的各种答案的建议但似乎没有工作!也许我错过了什么?

1 个答案:

答案 0 :(得分:17)

所以...解决方案非常简单,但需要一段时间才能找到:

在构建设置的“变量”选项卡下,添加一个环境变量:

  

PHANTOMJS_BIN C:\ NPM \ Modules \ PhantomJS.cmd

感谢this linkthis link