测试覆盖率已关闭(源地图问题?),使用业力覆盖,运行浏览器,伊斯坦布尔运行javascript / vue单元测试

时间:2018-08-20 13:14:20

标签: javascript vue.js browserify istanbul karma-coverage

我正在使用karma,phantomjs,茉莉花和vue / test-utils运行vue单元测试。我一直在努力使它正常工作,我对javascript尤其是自动化测试还很陌生。感谢我能提供的所有帮助:)单元测试运行正常且符合预期。但是,覆盖范围似乎已关闭。例如,我正在触发按钮单击,并希望覆盖该按钮单击所调用的功能,但事实并非如此。相反,会覆盖真正的随机内容,例如道具的类型(例如字符串)。这使我相信我的源映射不正确,并且我的配置错误。我的karma.conf.js看起来像这样:

module.exports = function(config) {

  var doVueify = require('vueify');
  var doBabelify = require('babelify');
  var doCover = require('browserify-istanbul');

  var coverOptions = {
    ignore: ['tests/my_project/**/*.js'],
    defaultIgnore: true
  }

  config.set({

    basePath: '',

    frameworks: ['jasmine', 'browserify'],

    browserify: {
        debug: true,
        extensions: [".js", ".vue"],
        configure: function(bundle){
            bundle.on('prebundle', function(){
                bundle
                    .transform(doBabelify)
                    .transform(doVueify)
                    .transform(doCover(coverOptions));
            });
        }
    },

    files: [
        'node_modules/es6-promise/dist/es6-promise.js',
        'node_modules/whatwg-fetch/fetch.js',
        'tests/my_project/**/*.js'
    ],

    preprocessors: {
      'tests/my_project/**/*.js': ['browserify']
    },

    reporters: ['spec', 'coverage'],

    coverageReporter: {
        dir: 'reports/coverage/javascript',
        includeAllSources: true,
        reporters: [
            { type : 'cobertura', subdir: '.', file: 'cobertura.xml' },
            { type : 'lcov', subdir: '.' },
            { type: 'text-summary' }
        ]
    },

    junitReporter: {
        outputFile: 'reports/test-results.xml',
        useBrowserName: false
    },

    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: false, 
    browsers: ['PhantomJS'],    
    singleRun: false,    
    concurrency: Infinity
  })
}

我的package.json是这样的

  "devDependencies": {
    "@mapbox/stylelint-processor-arbitrary-tags": "^0.2.0",
    "@vue/test-utils": "^1.0.0-beta.13",
    "ajv": "^5.3.0",
    "autoprefixer": "^7.1.4",
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.6.1",
    "babelify": "^8.0.0",
    "browserify-istanbul": "^3.0.1",
    "eslint": "^4.17.0",
    "eslint-plugin-vue": "4.3.0",
    "es6-promise": "^2.3.0",
    "grunt": "^1.0.2",
    "grunt-browserify": "^5.2.0",
    "grunt-contrib-clean": "^1.1.0",
    "grunt-contrib-copy": "^1.0.0",
    "grunt-contrib-less": "^1.4.1",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-eslint": "^20.1.0",
    "grunt-postcss": "^0.9.0",
    "grunt-stylelint": "^0.9.0",
    "jasmine": "^2.5.3",
    "karma": "^2.0.0",
    "karma-browserify": "^5.3.0",
    "karma-cli": "^1.0.1",
    "karma-coverage": "^1.1.1",
    "karma-jasmine": "^1.1.1",
    "karma-junit-reporter": "^1.2.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-spec-reporter": "0.0.32",
    "karma-sourcemap-loader": "^0.3.7",
    "stylelint": "^8.2.0",
    "stylelint-config-standard": "^17.0.0",
    "vueify": "^9.4.1"
  },
  "dependencies": {
    "@fortawesome/fontawesome": "^1.1.5",
    "@fortawesome/fontawesome-free-solid": "^5.0.10",
    "@fortawesome/vue-fontawesome": "0.0.22",
    "core-js": "^2.5.3",
    "normalize.css": "^7.0.0",
    "pikaday": "^1.6.1",
    "v-tooltip": "^2.0.0-rc.32",
    "vue": "^2.5.13",
    "whatwg-fetch": "^2.0.4"
  },
  "browser": {
    "vue": "vue/dist/vue.common.js"
  },
  "scripts": {
    "test": "npm run test:browser",
    "test:browser": "karma start --single-run --browsers PhantomJS",
    "test:ci": "npm run test:browser -- --reporters spec,coverage,junit"
  }

有什么建议吗? :)

0 个答案:

没有答案