使用业力茉莉花和离子的代码覆盖率

时间:2019-03-26 19:34:46

标签: javascript ionic-framework karma-jasmine

我正在使用Ionic开发应用程序。我需要做单元测试。我用业力和茉莉花。我的问题是这是我的第一个使用离子的应用程序。我已经使用Angular开发了一些应用程序,但从未遇到过单元测试的问题。

当我运行此命令(位于site上)时:

karma start ./test-config/karma.conf.js --coverage

在执行单元测试(生成html报告程序等)时,我的报告是空的(我的意思是每个文件为0%)

这是我的karma.conf.js

var webpackConfig = require('./webpack.test.js');
const path = require('path');

module.exports = function (config) {
    var _config = {
        basePath: '../',

        frameworks: ['jasmine'],
        plugins: [
            require('karma-chrome-launcher'),
            require('karma-webpack'),
            require('karma-sourcemap-loader'),
            require('karma-jasmine-html-reporter'),
            require('karma-jasmine'),
            require('karma-coverage-istanbul-reporter'),
            require('karma-coverage'),
            require('karma-spec-reporter')
        ],
        files: [
            {
                pattern: './test-config/karma-test-shim.js',
                watched: true
            },
            {
                pattern: './src/assets/**/*',
                watched: false,
                included: false,
                served: true,
                nocache: false
            }
        ],

        proxies: {
            '/assets/': '/base/src/assets/'
        },

        preprocessors: {
            './test-config/karma-test-shim.js': ['webpack', 'sourcemap'],
            './test-config/*.js': ['coverage']
        },
        webpack: webpackConfig,

        webpackMiddleware: {
            stats: 'errors-only'
        },

        webpackServer: {
            noInfo: true
        },

        browserConsoleLogOptions: {
            level: 'log',
            format: '%b %T: %m',
            terminal: true
        },

        coverageIstanbulReporter: {
            reports: ['html', 'lcovonly', 'text-summary'],
            type: 'text',
            dir: path.join(__dirname, 'coverage'),
            file: 'coverage.txt',
            'report-config': {
                html: {
                    subdir: 'html',
                    date: Date()
                },
                lcovonly: {
                    file: 'coverage.lcov'
                },
                combineBrowserReports: true,
                skipFilesWithNoCoverage: false,
                fixWebpackSourcePaths: true
            }
        },
        reporters: ['coverage-istanbul', 'spec'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browserDisconnectTimeout: 10000,
        browserDisconnectTolerance: 3,
        browserNoActivityTimeout: 60000,
        flags: [
          '--disable-web-security',
          '--disable-gpu',
          '--no-sandbox'
        ],
        browsers: ['Chrome_no_sandbox'],
        customLaunchers: {
            Chrome_no_sandbox: {
                base: 'Chrome',
                flags: ['--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222', '--signe-un']
            }
        },
        singleRun: true
    };

    config.set(_config);
};

0 个答案:

没有答案