9

我们已经设置了一个运行 Karma 的 Jenkins CI 服务器,目标是 PhantomJS。我们正在通过 Grunt 运行我们的测试。Jenkins、Grunt 和 Phantom 都运行正常,而且 Karma 似乎启动良好,但 Karma 无法捕获 Phantom。我们的脚本在本地(OSX)运行得很好。通过 bash 或 Jenkins 运行时存在相同的错误:

Running "karma:jenkins-unit" (karma) task
[2013-07-03 11:03:12.168] [WARN] config - urlRoot normalized to "/__karma/"
DEBUG [reporter]: Using reporter "dots".
DEBUG [reporter]: Using reporter "junit".
DEBUG [reporter]: Using reporter "coverage".
INFO [karma]: Karma server started at http://localhost:8084/__karma/
INFO [launcher]: Starting browser PhantomJS
DEBUG [launcher]: Creating temp dir at /tmp/testacular-7720703
DEBUG [launcher]: phantomjs /tmp/testacular-7720703/capture.js
INFO [karma]: To run via this server, use "karma run --runner-port 9104"
...
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
DEBUG [launcher]: Process PhantomJS exitted with code 0
DEBUG [launcher]: Cleaning temp dir /tmp/testacular-7720703
INFO [launcher]: Trying to start PhantomJS again.
DEBUG [launcher]: Creating temp dir at /tmp/testacular-7720703
DEBUG [launcher]: phantomjs /tmp/testacular-7720703/capture.js
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
DEBUG [launcher]: Process PhantomJS exitted with code 0
DEBUG [launcher]: Cleaning temp dir /tmp/testacular-7720703
INFO [launcher]: Trying to start PhantomJS again.
DEBUG [launcher]: Creating temp dir at /tmp/testacular-7720703
DEBUG [launcher]: phantomjs /tmp/testacular-7720703/capture.js
WARN [launcher]: PhantomJS have not captured in 60000 ms, killing.
DEBUG [launcher]: Process PhantomJS exitted with code 0
DEBUG [karma]: PhantomJS failed to capture, aborting the run.
DEBUG [launcher]: Disconnecting all browsers
DEBUG [launcher]: Killing PhantomJS
DEBUG [launcher]: Cleaning temp dir /tmp/testacular-7720703
Warning: Task "karma:jenkins-unit" failed. Use --force to continue.

我们的服务器是 CentOS 6.4。

以下是我们运行的版本:grunt-cli v0.1.9 grunt v0.4.1 node 0.10.12 和 0.8.25。phantomjs 1.9.1 业力 0.8.6

任何帮助将非常感激!

4

2 回答 2

6

在配置文件中使用轮询而不是套接字和绝对路径而不是相对路径,karma.conf.js以确保正确遍历目录结构并且客户端/服务器连接没有外部依赖项:

module.exports = function(config) 
  {
  var absolute_root = process.cwd() + '/';
  config.set
  (
    {
    // https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],

    // list of files

    files: 
       [
       absolute_root + 'test/Spec/**/*.js',
       absolute_root + 'js/*.js',
       absolute_root + '../libs/jquery.js'
       ],

     usePolling: true,

     transports: ['xhr-polling', 'jsonp-polling'],

     browsers: ['PhantomJS']
    }
  );
  };

参考

于 2015-04-15T16:59:28.890 回答
0

在我的情况下添加

transports: ['xhr-polling', 'jsonp-polling']

karma.conf.js足够了。真正的问题是业力的一个非常旧的版本(0.12)。现在有了 1.4。我不需要消耗 CPU 的轮询。

于 2017-04-26T07:27:39.213 回答