runner.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // 1. start the dev server using production config
  2. process.env.NODE_ENV = 'testing'
  3. const webpack = require('webpack')
  4. const DevServer = require('webpack-dev-server')
  5. const webpackConfig = require('../../build/webpack.prod.conf')
  6. const devConfigPromise = require('../../build/webpack.dev.conf')
  7. let server
  8. devConfigPromise.then(devConfig => {
  9. const devServerOptions = devConfig.devServer
  10. const compiler = webpack(webpackConfig)
  11. server = new DevServer(compiler, devServerOptions)
  12. const port = devServerOptions.port
  13. const host = devServerOptions.host
  14. return server.listen(port, host)
  15. })
  16. .then(() => {
  17. // 2. run the nightwatch test suite against it
  18. // to run in additional browsers:
  19. // 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
  20. // 2. add it to the --env flag below
  21. // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
  22. // For more information on Nightwatch's config file, see
  23. // http://nightwatchjs.org/guide#settings-file
  24. let opts = process.argv.slice(2)
  25. if (opts.indexOf('--config') === -1) {
  26. opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js'])
  27. }
  28. if (opts.indexOf('--env') === -1) {
  29. opts = opts.concat(['--env', 'chrome'])
  30. }
  31. const spawn = require('cross-spawn')
  32. const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' })
  33. runner.on('exit', function (code) {
  34. server.close()
  35. process.exit(code)
  36. })
  37. runner.on('error', function (err) {
  38. server.close()
  39. throw err
  40. })
  41. })