1 npm install --save-dev @vue/test-utils mocha mocha-webpack 2 3 npm install --save-dev jsdom jsdom-global webapck-node-externals 4 5 npm install --save-dev expect 6 7 npm install --save-dev nyc babel-plugin-istanbul
8 npm install cross-env --save-dev
配置
webpack.base.conf.js
1 if (process.env.NODE_ENV === 'test') { 2 module.exports.externals = [require('webpack-node-externals')()] 3 module.exports.devtool='inline-cheap-module-source-map' 4 }
.babelrc.js
1 "plugins": ["transform-vue-jsx", "transform-runtime", "istanbul"]
test/steup.js
1 require('jsdom-global')() 2 global.expect = require('expect')
package.json
1 "nyc": { 2 "include": [ 3 "src/**/*.(js|vue)" 4 ], 5 "instrument": false, 6 "sourceMap":false 7 },
package.json
1 "script": { 2 "test": "cross-env NODE_ENV=test nyc mocha-webpack --webpack-config build/webpack.base.conf.js --require test/setup.js test/**/*.spec.js" 3 4 }