feat: allow e2e plugins to sepcify which mode the server should start in

close #814
This commit is contained in:
Evan You
2018-02-12 15:53:31 -05:00
parent fd131060db
commit 8f8fe6dee7
2 changed files with 32 additions and 16 deletions

View File

@@ -1,15 +1,22 @@
function removeArg (rawArgs, arg) {
const matchRE = new RegExp(`^--${arg}`)
const equalRE = new RegExp(`^--${arg}=`)
const i = rawArgs.findIndex(arg => matchRE.test(arg))
if (i > -1) {
rawArgs.splice(i, equalRE.test(rawArgs[i]) ? 1 : 2)
}
}
module.exports = (api, options) => {
const chalk = require('chalk')
function run (command, args, rawArgs) {
if (args.url) {
const i = rawArgs.findIndex(arg => /^--url/.test(arg))
rawArgs.splice(i, /^--url=/.test(rawArgs[i]) ? 1 : 2)
}
removeArg(rawArgs, 'url')
removeArg(rawArgs, 'mode')
const serverPromise = args.url
? Promise.resolve({ url: args.url })
: api.service.run('serve', { mode: 'production' })
: api.service.run('serve', { mode: args.mode || 'production' })
return serverPromise.then(({ url, server }) => {
const { info } = require('@vue/cli-shared-utils')
@@ -39,13 +46,17 @@ module.exports = (api, options) => {
})
}
const commandOptions = {
'--mode': 'specify the mode the dev server should run in. (default: production)',
'--url': 'run e2e tests against given url instead of auto-starting dev server'
}
api.registerCommand('e2e', {
description: 'run e2e tests headlessly with `cypress run`',
usage: 'vue-cli-service e2e [options]',
options: {
'--url': 'run e2e tests against given url instead of auto-starting dev server',
options: Object.assign({
'-s, --spec': 'runs a specific spec file. defaults to "all"'
},
}, commandOptions),
details:
`All Cypress CLI options are also supported:\n` +
chalk.yellow(`https://docs.cypress.io/guides/guides/command-line.html#cypress-run`)
@@ -54,9 +65,7 @@ module.exports = (api, options) => {
api.registerCommand('e2e:open', {
description: 'run e2e tests in interactive mode with `cypress open`',
usage: 'vue-cli-service e2e:open [options]',
options: {
'--url': 'run e2e tests against given url instead of auto-starting dev server'
},
options: commandOptions,
details:
`All Cypress CLI options are supported:\n` +
chalk.yellow(`https://docs.cypress.io/guides/guides/command-line.html#cypress-open`)

View File

@@ -1,3 +1,12 @@
function removeArg (rawArgs, arg) {
const matchRE = new RegExp(`^--${arg}`)
const equalRE = new RegExp(`^--${arg}=`)
const i = rawArgs.findIndex(arg => matchRE.test(arg))
if (i > -1) {
rawArgs.splice(i, equalRE.test(rawArgs[i]) ? 1 : 2)
}
}
module.exports = (api, options) => {
api.registerCommand('e2e', {
description: 'run e2e tests with nightwatch',
@@ -12,14 +21,12 @@ module.exports = (api, options) => {
`All Nightwatch CLI options are also supported.\n` +
`https://github.com/nightwatchjs/nightwatch/blob/master/lib/runner/cli/cli.js`
}, (args, rawArgs) => {
if (args.url) {
const i = rawArgs.findIndex(arg => /^--url/.test(arg))
rawArgs = rawArgs.splice(i, 2)
}
removeArg(rawArgs, 'url')
removeArg(rawArgs, 'mode')
const serverPromise = args.url
? Promise.resolve({ url: args.url })
: api.service.run('serve', { mode: 'production' })
: api.service.run('serve', { mode: args.mode || 'production' })
return serverPromise.then(({ server, url }) => {
// expose dev server url to tests