|
| 1 | +module.exports = (api, options) => { |
| 2 | + api.registerCommand('e2e', { |
| 3 | + description: 'run e2e tests with nightwatch', |
| 4 | + options: { |
| 5 | + '--url': 'run e2e tests against given url instead of auto-starting dev server', |
| 6 | + '-e, --env': 'specify comma-delimited browser envs to run in (default: chrome)', |
| 7 | + '-t, --test': 'sepcify a test to run by name', |
| 8 | + '-f, --filter': 'glob to filter tests by filename' |
| 9 | + }, |
| 10 | + usage: 'vue-cli-service e2e [options]' |
| 11 | + }, (args, rawArgs) => { |
| 12 | + if (args.url) { |
| 13 | + const i = rawArgs.findIndex(arg => /^--url/.test(arg)) |
| 14 | + rawArgs = rawArgs.splice(i, 2) |
| 15 | + } |
| 16 | + |
| 17 | + const serverPromise = args.url |
| 18 | + ? Promise.resolve({ url: args.url }) |
| 19 | + : api.service.run('serve', { mode: 'production' }) |
| 20 | + |
| 21 | + return serverPromise.then(({ server, url }) => { |
| 22 | + // expose dev server url to tests |
| 23 | + process.env.VUE_DEV_SERVER_URL = url |
| 24 | + // expose user options to config file |
| 25 | + process.env.VUE_NIGHTWATCH_USER_OPTIONS = JSON.stringify(options.nightwatch || {}) |
| 26 | + |
| 27 | + rawArgs.push('--config', require.resolve('./nightwatch.config.js')) |
| 28 | + if (rawArgs.indexOf('--env') === -1) { |
| 29 | + rawArgs.push('--env', 'chrome') |
| 30 | + } |
| 31 | + |
| 32 | + const execa = require('execa') |
| 33 | + const nightWatchBinPath = require.resolve('nightwatch/bin/nightwatch') |
| 34 | + const runner = execa(nightWatchBinPath, rawArgs, { stdio: 'inherit' }) |
| 35 | + if (server) { |
| 36 | + runner.on('exit', () => server.close()) |
| 37 | + runner.on('error', () => server.close()) |
| 38 | + } |
| 39 | + return runner |
| 40 | + }) |
| 41 | + }) |
| 42 | +} |
0 commit comments