寻找与业力报告的好方法吗? [英] Find a good way to get a coverage report with karma?

查看:110
本文介绍了寻找与业力报告的好方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用业力覆盖+ browserify + angular.我从覆盖范围得到的结果是100%的受测文件被覆盖了,这是不正确的.知道如何进行这项工作吗?

I'm using karma-coverage + browserify + angular. The result i get from coverage is that 100% of the files under test are covered which is not true. Any idea how to make this work?

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

This is my file karma.conf.js :

// Karma configuration

module.exports = function (config) {
    config.set({
        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: './',

        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['browserify', 'jasmine'],

        // list of files / patterns to load in the browser
        files: [
            'karma.spec.js',
            'node_modules/es6-shim/es6-shim.js',
            'src/**/*.js',
            'unitest/**/*.js',
            'node_modules/karma-read-json/karma-read-json.js',
            { pattern: 'unitest/mocks/*.json', included: false }
        ],

        // list of files to exclude
        exclude: [

        ],

        // preprocess matching files before serving them to the browser
        // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
        preprocessors: {
            'karma.spec.js': ['browserify'],
            'src/**/*.js': ['browserify']
        },

        browserify: {
            debug: true,
            transform: ['babelify']
        },

        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        // https://www.npmjs.com/package/karma-notify-reporter
        // enable coverage module
        reporters: ['progress', 'coverage'],

        // generate coverage report in htm format
        coverageReporter: {
            type : 'json',
            dir : 'report/',
            subdir: './report',
            file: 'coverage-final.json'
        },
        // web server port
        port: 9876,

        // enable / disable colors in the output (reporters and logs)
        colors: true,

        // level of logging
        // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        logLevel: config.LOG_INFO,

        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,

        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        // Start these browsers, currently available:
        // - Chrome
        // - ChromeCanary
        // - Firefox
        // - Opera
        // - Safari (only Mac)
        // - PhantomJS
        // - IE (only Windows)
        browsers: ['Chrome', 'PhantomJS'],

        // If browser does not capture in given timeout [ms], kill it
        'captureTimeout': 60000,

        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: true,

        // Concurrency level
        // how many browser should be started simultaneous
        concurrency: Infinity
    })
}

这是我的package.json:

This is my package.json :

{
  "name": "project-name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "name",
  "devDependencies": {
    "angular-mocks": "^1.5.0",
    "babel": "^6.5.2",
    "babel-preset-es2015": "^6.9.0",
    "babelify": "^7.2.0",
    "browserify": "^13.0.1",
    "envify": "^3.4.0",
    "glob": "^7.0.0",
    "concurrently": "^2.0.0",
    "lite-server": "^2.1.0",
    "typescript": "^1.8.7",
    "jasmine-core": "2.4.1",
    "jasmine": "^2.4.1",
    "jspm": "^0.16.29",
    "karma": "^0.13.21",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-browserify": "^5.0.1",
    "karma-coverage": "^0.5.5",
    "karma-chrome-launcher": "^0.2.2",
    "karma-jasmine": "^0.3.7",
    "karma-notify-reporter": "^0.1.1",
    "karma-read-json": "^1.1.0",
    "karma-sourcemap-loader": "^0.3.7",
    "remap-istanbul": "^0.5.1"
  },
  "scripts": {
    "remap-istanbul": "remap-istanbul -i ./report/coverage/coverage-final.json -o ./report/coverage/html-report -t html",
    "test": "karma start && npm run remap-istanbul"
  },
  "dependencies": {
    "angular": "^v1.5.0",
    "angular-animate": "^1.5.7",
    "angular-route": "^v1.5.0-rc.2",
    "angular-translate": "^2.9.0",
    "angular-ui-bootstrap": "^1.3.3",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "lodash": "^4.14.0",
    "watchify": "^3.7.0"
  },
  "browserify": {
    "transform": [
      [
        "babelify",
        {
          "presets": [
            "es2015"
          ]
        }
      ]
    ]
  }
}

推荐答案

感谢大家,我找到了正确的解决方案.

Thanks to all of you, i am found the right solution.

这是我的文件Karma.conf& package.json:

Here is my files Karma.conf & package.json :

Karma.conf:

// Karma configuration
'use strict';

let babelify = require( 'babelify' );
let browserify = require('browserify');
let browserifyBabalIstanbul = require('browserify-babel-istanbul');
let isparta = require('isparta');

module.exports = function (config) {
    config.set({
        // base path that will be used to resolve all patterns (eg. files, exclude)
        basePath: './',

        // frameworks to use
        // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
        frameworks: ['jasmine', 'browserify'],

        // list of files / patterns to load in the browser
        files: [
            'karma.spec.js',
            'src/**/*.js',
            'unitest/**/*.js',
            'node_modules/karma-read-json/karma-read-json.js',
            { pattern: 'unitest/mocks/*.json', included: false }
        ],

        // list of files to exclude
        exclude: [
        ],

        // preprocess matching files before serving them to the browser
        // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
        preprocessors: {
            'karma.spec.js': ['browserify'],
            'src/**/*.js': ['browserify']

        },

        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ['coverage', 'dots'],

        // Configure coverage reporter
        coverageReporter: {
            reporters:[
                {type: 'html', dir:'coverage/'},
                {type: 'text-summary'},
                {
                    type : 'text',
                    dir : 'coverage/',
                    file : 'coverage.txt',
                    includeAllSources: true
                }
            ],
            check: {
                global: {
                    statements: 60,
                    branches: 60,
                    functions: 60,
                    lines: 60,
                    excludes: [
                        'foo/bar/**/*.js'
                    ]
                },
                each: {
                    statements: 20,
                    branches: 20,
                    functions: 20,
                    lines: 20,
                    excludes: [
                        'other/directory/**/*.js'
                    ],
                    overrides: {
                        'baz/component/**/*.js': {
                            statements: 98
                        }
                    }
                }
            },
            watermarks: {
                statements: [ 50, 75 ],
                functions: [ 50, 75 ],
                branches: [ 50, 75 ],
                lines: [ 50, 75 ]
            }
        },

        // web server port
        port: 9876,

        // enable / disable colors in the output (reporters and logs)
        colors: true,

        // level of logging
        // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        logLevel: config.LOG_INFO,

        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,

        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        // Start these browsers, currently available:
        // - Chrome
        // - ChromeCanary
        // - Firefox
        // - Opera
        // - Safari (only Mac)
        // - PhantomJS
        // - IE (only Windows)
        browsers: ['Chrome'],

        // If browser does not capture in given timeout [ms], kill it
        'captureTimeout': 60000,

        browserify: {
            debug: true,
            transform: [
                browserifyBabalIstanbul({
                    instrumenter: isparta,
                    instrumenterConfig: { babel: { presets: ["es2015"] } },
                    ignore: ['**/node_modules/**', '**/unitest/**']
                }),
                [ babelify, { presets: ["es2015"] } ]
            ]
        },

        // Karma plugins loaded
        plugins: [
            'karma-jasmine',
            'karma-babel-preprocessor',
            'karma-browserify',
            'karma-coverage',
            'karma-chrome-launcher'
        ],

        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: true,

        // Concurrency level
        // how many browser should be started simultaneous
        concurrency: Infinity
    })
}

package.json

{
  "name": "project-name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "name",
  "devDependencies": {
    "angular-mocks": "^1.5.0",
    "babel": "^6.5.2",
    "babel-preset-es2015": "^6.9.0",
    "babelify": "^7.2.0",
    "browserify": "^13.0.1",
    "browserify-babel-istanbul": "^0.3.0",
    "isparta": "^4.0.0",
    "envify": "^3.4.0",
    "glob": "^7.0.0",
    "jasmine": "^2.4.1",
    "jspm": "^0.16.29",
    "karma": "^0.13.21",
    "karma-babel-preprocessor": "^6.0.1",
    "karma-browserify": "^5.0.1",
    "karma-coverage": "^0.5.5",
    "karma-chrome-launcher": "^0.2.2",
    "karma-jasmine": "^0.3.7",
    "karma-read-json": "^1.1.0"
  },
  "scripts": {
    "test": "karma start"
  },
  "dependencies": {
    "angular": "^v1.5.0",
    "angular-animate": "^1.5.7",
    "angular-route": "^v1.5.0-rc.2",
    "angular-translate": "^2.9.0",
    "angular-ui-bootstrap": "^1.3.3",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "lodash": "^4.14.0",
    "watchify": "^3.7.0"
  }
}

这篇关于寻找与业力报告的好方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆