Skip to content

Commit

Permalink
fix: add missing mocha type if wdio is not installed along with any u…
Browse files Browse the repository at this point in the history
…nit testing frameworks (#5769)
  • Loading branch information
sodatea committed Aug 11, 2020
1 parent 2a56179 commit b85f5f2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
33 changes: 32 additions & 1 deletion packages/@vue/cli-plugin-e2e-webdriverio/generator/index.js
@@ -1,6 +1,33 @@
const { installedBrowsers } = require('@vue/cli-shared-utils')

module.exports = (api, { webdrivers }) => {
const applyTS = module.exports.applyTS = (api, invoking) => {
api.extendPackage({
devDependencies: {
'@types/mocha': '^8.0.1'
}
})

// inject 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) {
for (const t of ['mocha', '@wdio/mocha-framework', '@wdio/sync']) {
if (!types.includes(t)) {
types.push(t)
}
}
}
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
}
})
}
}

module.exports = (api, { webdrivers }, rootOptions, invoking) => {
api.render('./template', {
hasTS: api.hasPlugin('typescript'),
hasESLint: api.hasPlugin('eslint')
Expand Down Expand Up @@ -36,4 +63,8 @@ module.exports = (api, { webdrivers }) => {
},
devDependencies
})

if (api.hasPlugin('typescript')) {
applyTS(api, invoking)
}
}
1 change: 1 addition & 0 deletions packages/@vue/cli-plugin-e2e-webdriverio/package.json
Expand Up @@ -25,6 +25,7 @@
"access": "public"
},
"dependencies": {
"@types/mocha": "^8.0.1",
"@vue/cli-shared-utils": "^4.5.2",
"@wdio/cli": "^6.1.11",
"@wdio/local-runner": "^6.1.11",
Expand Down
5 changes: 5 additions & 0 deletions packages/@vue/cli-plugin-typescript/generator/index.js
Expand Up @@ -88,6 +88,11 @@ module.exports = (api, {
// eslint-disable-next-line node/no-extraneous-require
require('@vue/cli-plugin-eslint/generator').applyTS(api)
}

if (api.hasPlugin('e2e-webdriverio')) {
// eslint-disable-next-line node/no-extraneous-require
require('@vue/cli-plugin-e2e-webdriverio/generator').applyTS(api)
}
}

api.render('./template', {
Expand Down
Expand Up @@ -22,6 +22,7 @@
"types": [
"webpack-env"<% if (hasMocha || hasJest || hasWebDriverIO) { %>,<% } %>
<%_ if (hasWebDriverIO) { _%>
<% if (!hasMocha && !hasJest) { %>"mocha",<% } %>
"@wdio/mocha-framework",
"@wdio/sync"<% if (hasMocha || hasJest) { %>,<% } %>
<%_ } _%>
Expand Down

0 comments on commit b85f5f2

Please sign in to comment.