runner.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. }).then(() => {
  16. // 2. run the nightwatch test suite against it
  17. // to run in additional browsers:
  18. // 1. add an entry in test/e2e/nightwatch.conf.js under "test_settings"
  19. // 2. add it to the --env flag below
  20. // or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
  21. // For more information on Nightwatch's config file, see
  22. // http://nightwatchjs.org/guide#settings-file
  23. let opts = process.argv.slice(2)
  24. if (opts.indexOf('--config') === -1) {
  25. opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js'])
  26. }
  27. if (opts.indexOf('--env') === -1) {
  28. opts = opts.concat(['--env', 'chrome'])
  29. }
  30. const spawn = require('cross-spawn')
  31. const runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' })
  32. runner.on('exit', function (code) {
  33. server.close()
  34. process.exit(code)
  35. })
  36. runner.on('error', function (err) {
  37. server.close()
  38. throw err
  39. })
  40. })