问题描述
我正在将Karma和PhantomJS与Jasmine结合使用来测试我的AngularJS.当我在本地运行gulp测试时,它工作正常,可以启动PhantomJS并运行所有测试,但是当测试在构建服务器上运行时,它将失败,并出现以下错误:
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:
请注意,我正在使用VSTS并使用其内置的云构建系统(托管代理).话虽如此,它几乎是一个任务运行程序,我只用它在签入时运行gulp任务(构建,测试等)
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.
我的Karma配置为:
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"]
}
};
这是我package.json的相关部分.请注意,在运行测试之前已执行NPM安装
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?
推荐答案
所以...该解决方案非常简单,但花了一些时间才找到:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!