0

我正在嘗試構建反應樣板,以便可以將其用於我的個人項目。現在,我正在嘗試整合代碼覆蓋功能。我希望所有測試文件都駐留在其各自的組件文件夾中,而不是創建單獨的測試文件夾。以下是回購的鏈接。Karma代碼覆蓋率始終顯示測試的100%(0/0)

https://github.com/shettyrahul8june/react-webpack-beej

karma.conf.js

import webpackConfig from './webpack.config'; 

webpackConfig.devtool = 'inline-source-map'; 

module.exports = (config) => { 
    config.set({ 
    browsers: ['Chrome'], // run in Chrome 
    singleRun: true, // just run once by default 
    colors: true, 
    // autoWatch: true, 
    // logLevel: config.LOG_DEBUG, 
    // use the mocha, chai and sinon test framework 
    frameworks: ['mocha', 'chai', 'sinon'], 
    files: [ 
     'tests.webpack.js', // just load this file 
    ], 
    preprocessors: { 
     // preprocess with webpack and our sourcemap loader 
     'tests.webpack.js': ['webpack', 'sourcemap'], 
    }, 
    plugins: [ 
     'karma-chrome-launcher', 
     'karma-chai', 
     'karma-mocha', 
     'karma-sinon', 
     'karma-sourcemap-loader', 
     'karma-webpack', 
     'karma-coverage', 
    ], 
    // report results in this format 
    reporters: ['progress', 'coverage'], 
    coverageReporter: { 
     dir: '../coverage', 
     reporters: [ 
     { type: 'text-summary' }, 
     { type: 'html' }, 
     { type: 'lcov' }, 
     ], 
    }, 
    webpack: { 
     node: { 
     fs: 'empty', 
     }, 
     module: webpackConfig.module, 
     resolve: webpackConfig.resolve, 
     externals: Object.assign({}, webpackConfig.externals, { 
     'react/addons': true, 
     'react/lib/ExecutionEnvironment': true, 
     'react/lib/ReactContext': 'window', 
     }), 
    }, 
    webpackServer: { 
     noInfo: true, // please don't spam the console when running in karma! 
    }, 
    }); 
}; 

test.webpack.js

// make sure you have your directory and regex test set correctly! 
const context = require.context('../src/', true, /.+\.test\.jsx?$/); 
context.keys().forEach(context); 

我試圖通過它們與我相似,但沒有真正解決各種問題去我的問題。他們中的大多數都以不同的方式配置。我不確定我做錯了什麼。我嘗試了各種技術,但都徒勞無功。測試似乎工作正常,但覆蓋率始終顯示100%。

+0

如果您有(0/0),覆蓋率應爲100%。因爲這意味着0從0測試失敗。 – tomepejo

回答

0

我有類似的問題。我發現zone.js元素的導入需要遵循嚴格的流程。重要的項目是代理,它需要放置在不同的測試類型導入之後。

require('zone.js/dist/zone'); 
require('zone.js/dist/long-stack-trace-zone'); 
require('zone.js/dist/async-test'); 
require('zone.js/dist/fake-async-test'); 
require('zone.js/dist/sync-test'); 
require('zone.js/dist/proxy'); 
require('zone.js/dist/jasmine-patch'); 
相關問題