可以在本地运行Grunt Karma吗?

可以在本地运行Grunt Karma吗?

启动Karma服务器,为其分配一个端口,然后在我的计算机上打开不同的浏览器,并通过插入localhost:port来运行testing。

我有一个运行Travis的Github项目,在一些浏览器中有奇怪的结果。 我可以在本地运行testing,但只能使用“虚拟”PhantomJS。 很高兴在真正的浏览器中检查我的规格。

我经常使用karma-chrome-launcher并且知道也有karma-firefox-launcher

在你的karma.conf.js文件或你的Gruntfile.js选项区域中,你可以定义:

 browsers: ['Phantomjs', 'Chrome'], 

然后在插件部分包括:

 plugins: [ 'karma-chrome-launcher', 'karma-firefox-launcher', 'karma-phantomjs-launcher' ] 

https://github.com/karma-runner有一个发射器插件列表和其他有用的插件。 甚至还有一个业力 – browserstack发射器 ,虽然这不会是本地的。

你可以在Gruntfile.jsconfiguration文件,或者在你的Gruntfile.js引用karma.conf.js

我喜欢使用一个karma.conf.js文件来分离我的大部分业务configuration的function,所以在我的Gruntfile.js我执行以下操作:

 karma: { options: { configFile: 'karma.conf.js' }, unit: { autoWatch: true, singleRun: true }, watch: { // still needs watch integration and testing browsers: ['PhantomJS'], background: true } }, 

然后在我的karma.conf.js文件中,我遵循https://github.com/karma-runner/karma/blob/master/test/client/karma.conf.js所示的基础结构