3

我正在使用、和对我的.js.jsx文件运行测试覆盖率,用于 ES6 代码覆盖率。karmamochaisparta

由于某种原因,文件的覆盖率报告.jsx已损坏。

见下图:

在此处输入图像描述

所有文件的报告看起来都是一样的.jsx,即从JSX语法出现的那一行看 - 覆盖已损坏,即使我们可以看到该函数已被访问过一次。

这是我的karma.conf.js文件:

var path = require('path');
var isparta = require('isparta');

const babelOptions = {
presets: ['stage-0', 'react'],
plugins: [
    'transform-es2015-modules-commonjs',
    'transform-es2015-destructuring',
    'transform-es2015-spread',
    'transform-object-rest-spread',
    'transform-class-properties'
    ]
};

module.exports = function (config) {
config.set({

    browsers: [process.env.JENKINS_HOME ? 'Firefox' : 'Chrome'],

    singleRun: true,

    frameworks: ['mocha'],

    files: [
        'tests.webpack.js'
    ],

    preprocessors: {
        'tests.webpack.js': ['webpack', 'sourcemap'],
        'src/**/*.jsx': ['coverage']
    },

    reporters: ['progress', 'coverage'],

    coverageReporter: {
        dir: 'dist/coverage/',
        reporters: [
            {type: 'html'},
            {type: 'text-summary'}
        ],
        includeAllSources: true,
        instrumenters: {isparta: isparta},
        instrumenter: {
            '**/*.js': 'isparta',
            '**/*.jsx': 'isparta'
        },
        instrumenterOptions: {
            isparta: {
                babel: babelOptions,
                embedSource: true,
                noAutoWrap: true,
            }
        }
    },

    webpack: {
        babel: babelOptions,
        devtool: 'inline-source-map',
        resolve: {
            root: [path.resolve('.')],
            alias: {
                i18nJson: 'nfvo-utils/i18n/locale.json',
                'nfvo-utils/RestAPIUtil.js': 'test-utils/mocks/RestAPIUtil.js',
                'nfvo-utils': 'src/nfvo-utils',
                'nfvo-components': 'src/nfvo-components',
                'sdc-app': 'src/sdc-app'
            }
        },
        module: {
            preLoaders: [
                {test: /\.js$/, exclude: /(src|node_modules)/, loader: 'eslint-loader'},
                {test: /\.(js|jsx)$/, exclude: /(test|test\.js|node_modules)/, loader: 'isparta'}
            ],
            loaders: [
                {test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader'},
                {test: /\.json$/, loaders: ['json']},
                {test: /\.(css|scss|png|jpg|svg|ttf|eot|otf|woff|woff2)(\?.*)?$/, loader: 'ignore-loader'},
            ]
        },
        eslint: {
            configFile: './.eslintrc',
            emitError: true,
            emitWarning: true
        },
    },

    webpackServer: {
        noInfo: true
    }

});
};

如果需要任何进一步的信息,请告诉我,我会编辑。

4

0 回答 0