nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 50 forks source link

When packaged, my test coverage is always 100% #221

Closed WangJiangJiaoZi closed 5 years ago

WangJiangJiaoZi commented 5 years ago

address : https://github.com/reixs/reixs

WangJiangJiaoZi commented 5 years ago
module.exports = function(config) {
    config.set({
        browsers: ['Chrome'],
        frameworks: ['browserify', 'jasmine'],
        files: ['src/**/*.js', 'test/**/*.js'],
        preprocessors: {
            'src/**/*.js': ['sourcemap', 'browserify', 'coverage'],
            'test/**/*.js': ['sourcemap', 'browserify']
        },
        browserify: {
            debug: true,
            transform: ['babelify', 'browserify-versionify']
        },
        reporters: ['progress', 'coverage'],

        // optionally, configure the reporter
        coverageReporter: {
            reporters: [
                // generates ./coverage/html
                {
                    type: 'html',
                    subdir: './html'
                },
                // generates ./coverage/lcov.info
                {
                    type: 'lcovonly',
                    subdir: '.'
                },
                // generates ./coverage/coverage-final.json
                {
                    type: 'json',
                    subdir: '.'
                }
            ]
        },
        concurrency: Infinity
    })
}
{
  "name": "reixs",
  "version": "0.1.1",
  "description": "The HTTP request library",
  "main": "./dist/reixs.js",
  "scripts": {
    "report-coverage": "codecov",
    "coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
    "test": "gulp test",
    "karma": "karma start",
    "eslint": "eslint --ext .js src",
    "dev": "gulp watch",
    "build": "gulp release"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/reixs/reixs.git"
  },
  "keywords": [
    "fetch",
    "http",
    "ajax",
    "xhr",
    "reactive"
  ],
  "author": "Wang Jiang",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/reixs/reixs/issues"
  },
  "homepage": "https://github.com/reixs/reixs#readme",
  "devDependencies": {
    "@babel/core": "^7.3.3",
    "@babel/plugin-proposal-class-properties": "^7.3.3",
    "@babel/plugin-proposal-decorators": "^7.3.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.3.2",
    "@babel/plugin-transform-runtime": "^7.4.0",
    "@babel/preset-env": "^7.3.1",
    "babel-eslint": "^11.0.0-beta.0",
    "babelify": "^10.0.0",
    "browser-sync": "^2.26.3",
    "browserify": "^16.2.3",
    "browserify-versionify": "^1.0.6",
    "codecov": "^3.3.0",
    "coveralls": "^3.0.3",
    "del": "^3.0.0",
    "eslint-plugin-html": "^5.0.3",
    "gulp": "^4.0.0",
    "gulp-eslint": "^5.0.0",
    "gulp-sourcemaps": "^2.6.5",
    "gulp-uglify": "^3.0.1",
    "http-proxy-middleware": "^0.19.1",
    "jasmine": "^3.4.0",
    "jasmine-core": "^3.4.0",
    "karma": "^4.1.0",
    "karma-browserify": "^6.0.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage": "^1.1.2",
    "karma-jasmine": "^2.0.1",
    "karma-sourcemap-loader": "^0.3.7",
    "pre-commit": "^1.2.2",
    "vinyl-buffer": "^1.0.1",
    "vinyl-source-stream": "^2.0.0",
    "watchify": "^3.11.1"
  },
  "pre-commit": [
    "eslint"
  ],
  "dependencies": {
    "@babel/runtime": "^7.4.4"
  }
}
bendrucker commented 5 years ago

You'll probably want to let browserify cover your code via something like:

https://github.com/devongovett/browserify-istanbul

WangJiangJiaoZi commented 5 years ago

You'll probably want to let browserify cover your code via something like:

https://github.com/devongovett/browserify-istanbul

Thank you for your reply. I have seen this library in other issues, but I don't know how to configure karma.conf.js

bendrucker commented 5 years ago

Googling turns up this, among a handful of other examples and StackOverflow questions:

https://github.com/segrey/karma-browserify-istanbul-example

Hopefully this helps!