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+
110module . exports = ( api , options ) => {
211 const chalk = require ( 'chalk' )
312
413 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' )
916
1017 const serverPromise = args . url
1118 ? Promise . resolve ( { url : args . url } )
12- : api . service . run ( 'serve' , { mode : 'production' } )
19+ : api . service . run ( 'serve' , { mode : args . mode || 'production' } )
1320
1421 return serverPromise . then ( ( { url, server } ) => {
1522 const { info } = require ( '@vue/cli-shared-utils' )
@@ -39,13 +46,17 @@ module.exports = (api, options) => {
3946 } )
4047 }
4148
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+
4254 api . registerCommand ( 'e2e' , {
4355 description : 'run e2e tests headlessly with `cypress run`' ,
4456 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 ( {
4758 '-s, --spec' : 'runs a specific spec file. defaults to "all"'
48- } ,
59+ } , commandOptions ) ,
4960 details :
5061 `All Cypress CLI options are also supported:\n` +
5162 chalk . yellow ( `https://docs.cypress.io/guides/guides/command-line.html#cypress-run` )
@@ -54,9 +65,7 @@ module.exports = (api, options) => {
5465 api . registerCommand ( 'e2e:open' , {
5566 description : 'run e2e tests in interactive mode with `cypress open`' ,
5667 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 ,
6069 details :
6170 `All Cypress CLI options are supported:\n` +
6271 chalk . yellow ( `https://docs.cypress.io/guides/guides/command-line.html#cypress-open` )
0 commit comments