Karma无法捕获PhantomJS

时间:2013-07-03 15:07:27

标签: node.js centos phantomjs karma-runner socket-timeout-exception

我们已经设置了一个运行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     咕噜v0.4.1     节点0.10.12和0.8.25。     phantomjs 1.9.1     业力0.8.6

非常感谢任何帮助!

2 个答案:

答案 0 :(得分: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']
    }
  );
  };

<强>参考

答案 1 :(得分:0)

在我的情况下添加

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

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