1
+ function removeArg ( rawArgs , arg ) {
2
+ const matchRE = new RegExp ( `^--${ arg } ` )
3
+ const equalRE = new RegExp ( `^--${ arg } =` )
4
+ const i = rawArgs . findIndex ( arg => matchRE . test ( arg ) )
5
+ if ( i > - 1 ) {
6
+ rawArgs . splice ( i , equalRE . test ( rawArgs [ i ] ) ? 1 : 2 )
7
+ }
8
+ }
9
+
1
10
module . exports = ( api , options ) => {
2
11
const chalk = require ( 'chalk' )
3
12
4
13
function run ( command , args , rawArgs ) {
5
- if ( args . url ) {
6
- const i = rawArgs . findIndex ( arg => / ^ - - u r l / . test ( arg ) )
7
- rawArgs . splice ( i , / ^ - - u r l = / . test ( rawArgs [ i ] ) ? 1 : 2 )
8
- }
14
+ removeArg ( rawArgs , 'url' )
15
+ removeArg ( rawArgs , 'mode' )
9
16
10
17
const serverPromise = args . url
11
18
? Promise . resolve ( { url : args . url } )
12
- : api . service . run ( 'serve' , { mode : 'production' } )
19
+ : api . service . run ( 'serve' , { mode : args . mode || 'production' } )
13
20
14
21
return serverPromise . then ( ( { url, server } ) => {
15
22
const { info } = require ( '@vue/cli-shared-utils' )
@@ -39,13 +46,17 @@ module.exports = (api, options) => {
39
46
} )
40
47
}
41
48
49
+ const commandOptions = {
50
+ '--mode' : 'specify the mode the dev server should run in. (default: production)' ,
51
+ '--url' : 'run e2e tests against given url instead of auto-starting dev server'
52
+ }
53
+
42
54
api . registerCommand ( 'e2e' , {
43
55
description : 'run e2e tests headlessly with `cypress run`' ,
44
56
usage : 'vue-cli-service e2e [options]' ,
45
- options : {
46
- '--url' : 'run e2e tests against given url instead of auto-starting dev server' ,
57
+ options : Object . assign ( {
47
58
'-s, --spec' : 'runs a specific spec file. defaults to "all"'
48
- } ,
59
+ } , commandOptions ) ,
49
60
details :
50
61
`All Cypress CLI options are also supported:\n` +
51
62
chalk . yellow ( `https://docs.cypress.io/guides/guides/command-line.html#cypress-run` )
@@ -54,9 +65,7 @@ module.exports = (api, options) => {
54
65
api . registerCommand ( 'e2e:open' , {
55
66
description : 'run e2e tests in interactive mode with `cypress open`' ,
56
67
usage : 'vue-cli-service e2e:open [options]' ,
57
- options : {
58
- '--url' : 'run e2e tests against given url instead of auto-starting dev server'
59
- } ,
68
+ options : commandOptions ,
60
69
details :
61
70
`All Cypress CLI options are supported:\n` +
62
71
chalk . yellow ( `https://docs.cypress.io/guides/guides/command-line.html#cypress-open` )
0 commit comments