run-tests.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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. const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['start'], {
  6. env,
  7. });
  8. startServer.stderr.on('data', (data) => {
  9. // eslint-disable-next-line
  10. console.log(data);
  11. });
  12. startServer.on('exit', () => {
  13. kill(process.env.PORT || 8000);
  14. });
  15. // eslint-disable-next-line
  16. console.log('Starting development server for e2e tests...');
  17. startServer.stdout.on('data', (data) => {
  18. // eslint-disable-next-line
  19. console.log(data.toString());
  20. if (data.toString().indexOf('The app is running at') >= 0 ||
  21. data.toString().indexOf('Compiled with warnings') >= 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', () => {
  28. startServer.kill();
  29. });
  30. }
  31. });