2016-03-01 80 views
1

我已經開始使用React和Redux,並且我想使用Karma和Mocha和PhantomJS2爲它編寫測試。我在這裏使用源代碼作爲基礎:https://github.com/reactjs/redux/tree/master/examples/counter。我基本上想用Phantom在Karma運行測試,而不是使用節點和「npm測試」。測試與業力和摩卡的反應和還原

我已經建立了與安裝業力所需要的軟件包:

的package.json

"scripts": { 
    "test:karma": "karma start", 
}, 
"karma": "^0.13.21", 
"karma-babel-preprocessor": "^6.0.1", 
"karma-mocha": "^0.2.2", 
"karma-phantomjs2-launcher": "^0.5.0", 
"phantomjs2": "^2.2.0", 

而且我一直試圖弄清楚如何建立我karma.config.js但我似乎沒有讓我的測試運行,這是我需要幫助。

karma.config.js

module.exports = function(config) { 
    process.env.PHANTOMJS_BIN = './node_modules/phantomjs2/lib/phantom/bin'; 
    config.set({ 
     basePath: './', 
     frameworks: ['mocha'], 
     plugins: [ 'karma-mocha', 'karma-phantomjs2-launcher', 'karma-babel-preprocessor' ], 
     files: [ 
      "components/Counter.js", 
      "test/components/Counter.spec.js" 
     ], 
     preprocessors: { 
      "components/Counter.js": ["babel"], 
      "test/components/Counter.spec.js": ["babel"] 
     }, 
     babelPreprocessor: { 
      options: { 
       "presets": ["es2015", "react"], 
      } 
     }, 
     reporters: ['progress'], 
     browsers: ['PhantomJS2'], 
     port: 9099, 
     runnerPort: 9100, 
     urlRoot: '/', 
     colors: true, 
     logLevel: config.LOG_INFO, 
     autoWatch: false, 
     singleRun: false, 
     concurrency: Infinity 
    }) 
} 

回答