0

私は私の個人的なプロジェクトのためにそれを使用できるように反応の定型文を作成しようとしています。今、私はコードカバレッジ機能を統合しようとしています。別のテストフォルダを作成するのではなく、すべてのテストファイルをそれぞれのコンポーネントフォルダに配置します。以下はレポへのリンクです。カルマコードカバレッジは常にテストの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'); 
関連する問題