mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-24 08:08:54 -06:00
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
module.exports = (api, _, __, invoking) => {
|
|
api.render('./template', {
|
|
hasTS: api.hasPlugin('typescript')
|
|
})
|
|
|
|
api.extendPackage({
|
|
devDependencies: {
|
|
'@vue/test-utils': '1.0.0-beta.29',
|
|
'chai': '^4.1.2'
|
|
},
|
|
scripts: {
|
|
'test:unit': 'vue-cli-service test:unit'
|
|
}
|
|
})
|
|
|
|
if (api.hasPlugin('eslint')) {
|
|
applyESLint(api)
|
|
}
|
|
|
|
if (api.hasPlugin('typescript')) {
|
|
applyTS(api, invoking)
|
|
}
|
|
}
|
|
|
|
const applyESLint = module.exports.applyESLint = api => {
|
|
api.render(files => {
|
|
files['tests/unit/.eslintrc.js'] = api.genJSConfig({
|
|
env: { mocha: true }
|
|
})
|
|
})
|
|
}
|
|
|
|
const applyTS = module.exports.applyTS = (api, invoking) => {
|
|
api.extendPackage({
|
|
devDependencies: {
|
|
'@types/mocha': '^5.2.4',
|
|
'@types/chai': '^4.1.0'
|
|
}
|
|
})
|
|
// inject mocha/chai types to tsconfig.json
|
|
if (invoking) {
|
|
api.render(files => {
|
|
const tsconfig = files['tsconfig.json']
|
|
if (tsconfig) {
|
|
const parsed = JSON.parse(tsconfig)
|
|
const types = parsed.compilerOptions.types
|
|
if (types) {
|
|
if (!types.includes('mocha')) {
|
|
types.push('mocha')
|
|
}
|
|
if (!types.includes('chai')) {
|
|
types.push('chai')
|
|
}
|
|
}
|
|
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
|
|
}
|
|
})
|
|
}
|
|
}
|