run-tests.js 1.1 KB

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