run-tests.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 (
  22. data.toString().indexOf('Compiled successfully') >= 0 ||
  23. data.toString().indexOf('Compiled with warnings') >= 0
  24. ) {
  25. // eslint-disable-next-line
  26. console.log('Development server is started, ready to run tests.');
  27. const testCmd = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['test'], {
  28. stdio: 'inherit',
  29. });
  30. testCmd.on('exit', code => {
  31. startServer.kill();
  32. process.exit(code);
  33. });
  34. }
  35. });