Skip to content

Commit b85f5f2

Browse files
authored
fix: add missing mocha type if wdio is not installed along with any unit testing frameworks (#5769)
1 parent 2a56179 commit b85f5f2

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

Diff for: packages/@vue/cli-plugin-e2e-webdriverio/generator/index.js

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
const { installedBrowsers } = require('@vue/cli-shared-utils')
22

3-
module.exports = (api, { webdrivers }) => {
3+
const applyTS = module.exports.applyTS = (api, invoking) => {
4+
api.extendPackage({
5+
devDependencies: {
6+
'@types/mocha': '^8.0.1'
7+
}
8+
})
9+
10+
// inject types to tsconfig.json
11+
if (invoking) {
12+
api.render(files => {
13+
const tsconfig = files['tsconfig.json']
14+
if (tsconfig) {
15+
const parsed = JSON.parse(tsconfig)
16+
const types = parsed.compilerOptions.types
17+
if (types) {
18+
for (const t of ['mocha', '@wdio/mocha-framework', '@wdio/sync']) {
19+
if (!types.includes(t)) {
20+
types.push(t)
21+
}
22+
}
23+
}
24+
files['tsconfig.json'] = JSON.stringify(parsed, null, 2)
25+
}
26+
})
27+
}
28+
}
29+
30+
module.exports = (api, { webdrivers }, rootOptions, invoking) => {
431
api.render('./template', {
532
hasTS: api.hasPlugin('typescript'),
633
hasESLint: api.hasPlugin('eslint')
@@ -36,4 +63,8 @@ module.exports = (api, { webdrivers }) => {
3663
},
3764
devDependencies
3865
})
66+
67+
if (api.hasPlugin('typescript')) {
68+
applyTS(api, invoking)
69+
}
3970
}

Diff for: packages/@vue/cli-plugin-e2e-webdriverio/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"access": "public"
2626
},
2727
"dependencies": {
28+
"@types/mocha": "^8.0.1",
2829
"@vue/cli-shared-utils": "^4.5.2",
2930
"@wdio/cli": "^6.1.11",
3031
"@wdio/local-runner": "^6.1.11",

Diff for: packages/@vue/cli-plugin-typescript/generator/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ module.exports = (api, {
8888
// eslint-disable-next-line node/no-extraneous-require
8989
require('@vue/cli-plugin-eslint/generator').applyTS(api)
9090
}
91+
92+
if (api.hasPlugin('e2e-webdriverio')) {
93+
// eslint-disable-next-line node/no-extraneous-require
94+
require('@vue/cli-plugin-e2e-webdriverio/generator').applyTS(api)
95+
}
9196
}
9297

9398
api.render('./template', {

Diff for: packages/@vue/cli-plugin-typescript/generator/template/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"types": [
2323
"webpack-env"<% if (hasMocha || hasJest || hasWebDriverIO) { %>,<% } %>
2424
<%_ if (hasWebDriverIO) { _%>
25+
<% if (!hasMocha && !hasJest) { %>"mocha",<% } %>
2526
"@wdio/mocha-framework",
2627
"@wdio/sync"<% if (hasMocha || hasJest) { %>,<% } %>
2728
<%_ } _%>

0 commit comments

Comments
 (0)