Skip to content

Commit 8f8fe6d

Browse files
committed
feat: allow e2e plugins to sepcify which mode the server should start in
close #814
1 parent fd13106 commit 8f8fe6d

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

packages/@vue/cli-plugin-e2e-cypress/index.js

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
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+
110
module.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 => /^--url/.test(arg))
7-
rawArgs.splice(i, /^--url=/.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`)

packages/@vue/cli-plugin-e2e-nightwatch/index.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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+
110
module.exports = (api, options) => {
211
api.registerCommand('e2e', {
312
description: 'run e2e tests with nightwatch',
@@ -12,14 +21,12 @@ module.exports = (api, options) => {
1221
`All Nightwatch CLI options are also supported.\n` +
1322
`https://github.com/nightwatchjs/nightwatch/blob/master/lib/runner/cli/cli.js`
1423
}, (args, rawArgs) => {
15-
if (args.url) {
16-
const i = rawArgs.findIndex(arg => /^--url/.test(arg))
17-
rawArgs = rawArgs.splice(i, 2)
18-
}
24+
removeArg(rawArgs, 'url')
25+
removeArg(rawArgs, 'mode')
1926

2027
const serverPromise = args.url
2128
? Promise.resolve({ url: args.url })
22-
: api.service.run('serve', { mode: 'production' })
29+
: api.service.run('serve', { mode: args.mode || 'production' })
2330

2431
return serverPromise.then(({ server, url }) => {
2532
// expose dev server url to tests

0 commit comments

Comments
 (0)