我正在尝试构建一个反应样板,以便我可以将它用于我的个人项目。现在,我正在尝试集成代码覆盖功能。我希望所有测试文件都驻留在其各自的组件文件夹中,而不是创建单独的测试文件夹。以下是回购的链接。
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)
我有类似的问题。我发现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');