Lenny-Hu / note

blog
5 stars 1 forks source link

vue-cli3 使用记录 #94

Open Lenny-Hu opened 4 years ago

Lenny-Hu commented 4 years ago

vue-lic3 mocha-webpack 生成覆盖率 (@vue/cli-plugin-unit-mocha)

https://github.com/vuejs/vue-cli/issues/1363#issuecomment-521692197

[1/3] Install babel-plugin-istanbul + configure it in babel.config.js

npm install --save-dev babel-plugin-istanbul
// babel.config.js
module.exports = {
  presets: [
    '@vue/app'
  ],
  env: {
    test: {
      plugins: [
        ['istanbul', {
          useInlineSourceMaps: false
        }]
      ]
    }
  }
};

[2/3]: Install nyc + configure it in nyc.config.js

npm install nyc --save-dev
// nyc.config.js
module.exports = {
  'check-coverage': false,
  'per-file': true,
  'skip-full': true,
  all: true,
  include: [
    'src/**/*.{js,vue}'
  ],
  exclude: [
    'src/*.js',
    '**/index.js'
  ],
  reporter: [
    'lcov',
    'text',
    'text-summary'
  ],
  extension: [
    '.js',
    '.vue'
  ]
};

[3/3] Use it

nyc vue-cli-service test:unit --require tests/setup.js