噶/茉莉花超时没有运行testing

我正在尝试从Grunt运行Karma / Jasmine,在http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/

Karma推出PhantomJS(或Chrome),根据singleRun,它要么超时,要么坐在那里,什么都不做。 我试着改变基于阅读类似问题的人的解决schemecaptureTimeoutbrowserNoActivityTimeout ,但似乎并没有工作。

我的相关版本:

  • NodeJS:0.10.25
  • 噶玛:0.12.16
  • Webpack:1.1.11
  • webpack-dev-server:1.4.1
  • 业力 – 茉莉花:0.1.5
  • Linux:Ubuntu 14.04

我发现在OS X上有同样的问题 :

我试过更新所有我的开发依赖到最新版本,但问题仍然存在。

我的控制台输出如下。 引用bundle的webpack行现在有效/无效令人担忧,但是我找不到任何有关它们的含义的信息。 这是我的控制台输出:

 Running "karma:unit" (karma) task DEBUG [config]: autoWatch set to false, because of singleRun DEBUG [plugin]: Loading karma-* from /home/ed/workspace/wwb-app/node_modules DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-chrome-launcher. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-coffee-preprocessor. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-firefox-launcher. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-html2js-preprocessor. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-jasmine. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-phantomjs-launcher. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-requirejs. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-script-launcher. DEBG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-webpack-plugin. INFO [karma]: Karma v0.12.16 server started at http://localhost:8080/ INFO [launcher]: Starting browser PhantomJS DEBUG [temp-dir]: Creating temp dir at /tmp/karma-98204612 DEBUG [launcher]: /home/ed/workspace/wwb-app/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-98204612/capture.js Hash: 89285186567c1bc5bb7f Version: webpack 1.1.11 Time: 2ms Asset Size Chunks Chunk Names webpack: bundle is now VALID. webpack: bundle is now INVALID. DEBUG [web-server]: serving: /home/ed/workspace/wwb-app/node_modules/karma/static/client.html DEBUG [web-server]: serving: /home/ed/workspace/wwb-app/node_modules/karma/static/karma.js DEBUG [web-server]: upgrade /socket.io/1/websocket/CjC8pnQq5It2z_kWYB98 DEBUG [karma]: A browser has connected on socket CjC8pnQq5It2z_kWYB98 INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket CjC8pnQq5It2z_kWYB98 with id 98204612 DEBUG [launcher]: PhantomJS (id 98204612) captured in 1.704 secs WARN [PhantomJS 1.9.7 (Linux)]: Disconnected (1 times), because no message in 30000 ms. DEBUG [karma]: Run complete, exitting. DEBUG [launcher]: Disconnecting all browsers DEBUG [launcher]: Process PhantomJS exited with code 0 DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-98204612 Warning: Task "karma:unit" failed. Use --force to continue. Aborted due to warnings. 

这是我的karma.conf.js文件:

 'use strict'; module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], files: [ 'test/helpers/**/*.js', 'test/spec/components/**/*.js' ], preprocessors: { 'test/spec/components/**/*.js': ['webpack'] }, webpack: { cache: true, module: { loaders: [{ test: /\.css$/, loader: 'style!css' }, { test: /\.gif/, loader: 'url-loader?limit=10000&minetype=image/gif' }, { test: /\.jpg/, loader: 'url-loader?limit=10000&minetype=image/jpg' }, { test: /\.png/, loader: 'url-loader?limit=10000&minetype=image/png' }, { test: /\.js$/, loader: 'jsx-loader' }] } }, webpackServer: { stats: { colors: true } }, exclude: [], port: 8080, logLevel: config.LOG_DEBUG, colors: true, autoWatch: true, // Start these browsers, currently available: // - Chrome // - ChromeCanary // - Firefox // - Opera // - Safari (only Mac) // - PhantomJS // - IE (only Windows) browsers: ['PhantomJS'], reporters: ['progress'], captureTimeout: 60000, browserNoActivityTimeout: 60000, singleRun: true }); }; 

我有同样的问题。 从相关的GitHub问题 ,我了解到,您可以延长无活动超时。

在你的gruntfile或者karmaconfiguration文件中设置这个Karmaconfiguration选项:

 browserNoActivityTimeout: 100000 

我把它设置为100秒,我的testing成功运行。 我不知道是什么原因造成的延误。

我已经改变了我的噶玛configuration

 captureTimeout: 60000, // it was already there browserDisconnectTimeout : 10000, browserDisconnectTolerance : 1, browserNoActivityTimeout : 60000,//by default 10000 

我也有200-300个testing,PhantomJS 1.9.8,它只需要大约100MB的幻影内存和咕噜声和业力他们一起使用了大约300MB的内存。

我们在构build服务器上遇到类似的问题。

增加browserNoActivityTimeout工作到一个点。 我们把它提高到了60000ms,但随着unit testing次数的增加,幻像JS不断开的问题又回来了。

我们最终将问题追踪到幻灯片可用的RAM。 我们有1100个unit testing需要大约1分30秒的时间才能运行,但是在60000ms的超时时间内,phantomJS将无法断开连接。

构build节点VM RAM从2GB增加到4GB,1100个unit testing花费约45秒运行,幻像JS将断开约5秒。 巨大的进步。

有两个教训:1. PhantomJS是饥饿的内存,所以确保它有足够的内存来做它的事情2.剖析你的代码,以了解哪里可以提高内存使用效率。

另一个可能的解释是RequireJS阻碍。 如果我将“requirejs”添加到config.frameworks数组中的karma.conf.js中,我得到了这个确切的错误。 这似乎覆盖了原生的require函数,并导致testing不被执行。 在我的情况下,描述块被触发,但没有,如果它是块。

在我的情况下,我没有在我的test.js文件中包含下面的代码:

 requirejs.config({ callback: window.__karma__.start }); describe('tests', function() { ... 

一旦包含此configuration,testing开始运行。 希望这节省了别人很多的压力!

从karmaconfiguration文件中删除'require',只需使用框架:['jasmine']。

检查localhost是否正确指向127.0.0.1而不是无法访问的IP,这可能发生在使用虚拟机的开发环境中。

我为自己的环境解决了这个问题。 我在全局安装了一堆nodejs包。 我没有做一个回归来确定问题是由什么软件包造成的,但我强烈怀疑在全球安装业力是原因。

如果你有这个问题,然后尝试

 sudo npm -g remove karma 

如果不行的话,我会删除所有的全局节点包(除了真正的全局包,比如yeoman,grunt-cli)。 然后在本地安装您的项目。

我也注意到,当你在OS X上运行sudo npm -i时,它将〜/ .npm的所有者改为root ,随后的npm -i命令将会失败并显示EACCESS错误。

这里的OP可能不是这种情况,但是如果你正在testing的代码是一个无限循环的话,它会像这样在超时的时候断开连接。