run-tests.js 1022 B

123456789101112131415161718192021222324252627282930313233343536
  1. const { spawn } = require('child_process');
  2. const { kill } = require('cross-port-killer');
  3. const env = Object.create(process.env);
  4. env.BROWSER = 'none';
  5. env.TEST = true;
  6. const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['start'], {
  7. env,
  8. });
  9. startServer.stderr.on('data', data => {
  10. // eslint-disable-next-line
  11. console.log(data.toString());
  12. });
  13. startServer.on('exit', () => {
  14. kill(process.env.PORT || 8000);
  15. });
  16. // eslint-disable-next-line
  17. console.log('Starting development server for e2e tests...');
  18. startServer.stdout.on('data', data => {
  19. // eslint-disable-next-line
  20. console.log(data.toString());
  21. if (data.toString().indexOf('App running at') >= 0) {
  22. // eslint-disable-next-line
  23. console.log('Development server is started, ready to run tests.');
  24. const testCmd = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['test'], {
  25. stdio: 'inherit',
  26. });
  27. testCmd.on('exit', code => {
  28. startServer.kill();
  29. process.exit(code);
  30. });
  31. }
  32. });