找到一个获得业力覆盖率报告的好方法?

时间:2016-08-15 10:25:05

标签: angularjs karma-runner code-coverage browserify

我使用karma-coverage + browserify + angular。我从覆盖范围得到的结果是100%的被测文件被覆盖,这是不正确的。知道如何使这项工作吗?

这是我的文件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:



{
  "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"
          ]
        }
      ]
    ]
  }
}




0 个答案:

没有答案