run-tests.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  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. env.UMI_UI = 'none';
  8. env.PROGRESS = 'none';
  9. // flag to prevent multiple test
  10. let once = false;
  11. const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['run', 'serve'], {
  12. env,
  13. });
  14. startServer.stderr.on('data', (data) => {
  15. // eslint-disable-next-line
  16. console.log(data.toString());
  17. });
  18. startServer.on('exit', () => {
  19. kill(process.env.PORT || 8000);
  20. });
  21. console.log('Starting development server for e2e tests...');
  22. startServer.stdout.on('data', (data) => {
  23. console.log(data.toString());
  24. // hack code , wait umi
  25. if (!once && data.toString().indexOf('Serving your umi project!') >= 0) {
  26. // eslint-disable-next-line
  27. once = true;
  28. console.log('Development server is started, ready to run tests.');
  29. const testCmd = spawn(
  30. /^win/.test(process.platform) ? 'npm.cmd' : 'npm',
  31. ['run', 'playwright'],
  32. {
  33. stdio: 'inherit',
  34. },
  35. );
  36. testCmd.on('exit', (code) => {
  37. console.log(code);
  38. startServer.kill();
  39. process.exit(code);
  40. });
  41. }
  42. });