2016-08-04 79 views

回答

0

我想出了以下karma.conf.js文件:

module.exports = function (config) { 
    var options = { 
     plugins: [ 
      "karma-browserify", 
      "karma-chrome-launcher", 
      "karma-firefox-launcher", 
      "karma-ie-launcher", 
      //"karma-opera-launcher", 
      "karma-phantomjs-launcher", 
      "karma-mocha" 
     ], 
     ... 
     browsers: [ 
      "Chrome", 
      "Firefox", 
      "IE", 
      //"Opera", 
      "PhantomJS" 
     ] 
    }; 

    if (process.env.TRAVIS) { 
     options.customLaunchers = { 
      Chrome_travis_ci: { 
       base: 'Chrome', 
       flags: ['--no-sandbox'] 
      } 
     }; 
     options.browsers = [ 
      "Chrome_travis_ci", 
      "Firefox", 
      //"IE", 
      //"Opera", 
      "PhantomJS" 
     ]; 
    } 

    config.set(options); 
}; 

及以下.travis.yml:

language: node_js 
node_js: 
    - "5" 
before_install: 
    - export CHROME_BIN=chromium-browser 
    - export DISPLAY=:99.0 
    - sh -e /etc/init.d/xvfb start 

中的Internet Explorer是Windows环境下唯一的工作,所以它不被Travis支持(因为它使用Linux)。 karma-opera-launcher有严重的错误,所以我无法在Travis和Windows上使用它。根据插件的github页面,它应该在Linux上工作,但我不想花费更多时间。

所以这些修改不会相互干扰,因为只有Chrome需要修改,而且这些修改是由自定义启动程序包含的。所有非PhantomJS浏览器都需要在.travis.yml中显示和xvfb。

另一种可能的解决方案是使用SauceLabs,但这种测试对我来说并不重要,所以我不想为此支付250美元/年。

相关问题