25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
1.4 KiB

  1. /* eslint-disable eslint-comments/disable-enable-pair */
  2. /* eslint-disable @typescript-eslint/no-var-requires */
  3. /* eslint-disable eslint-comments/no-unlimited-disable */
  4. const { spawn } = require('child_process');
  5. // eslint-disable-next-line import/no-extraneous-dependencies
  6. const { kill } = require('cross-port-killer');
  7. const env = Object.create(process.env);
  8. env.BROWSER = 'none';
  9. env.TEST = true;
  10. env.UMI_UI = 'none';
  11. env.PROGRESS = 'none';
  12. // flag to prevent multiple test
  13. let once = false;
  14. const startServer = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['run', 'serve'], {
  15. env,
  16. });
  17. startServer.stderr.on('data', (data) => {
  18. // eslint-disable-next-line
  19. console.log(data.toString());
  20. });
  21. startServer.on('exit', () => {
  22. kill(process.env.PORT || 44324);
  23. });
  24. console.log('Starting development server for e2e tests...');
  25. startServer.stdout.on('data', (data) => {
  26. console.log(data.toString());
  27. // hack code , wait umi
  28. if (!once && data.toString().indexOf('Serving your umi project!') >= 0) {
  29. // eslint-disable-next-line
  30. once = true;
  31. console.log('Development server is started, ready to run tests.');
  32. const testCmd = spawn(
  33. /^win/.test(process.platform) ? 'npm.cmd' : 'npm',
  34. ['test', '--', '--maxWorkers=1', '--runInBand'],
  35. {
  36. stdio: 'inherit',
  37. },
  38. );
  39. testCmd.on('exit', (code) => {
  40. console.log(code);
  41. startServer.kill();
  42. process.exit(code);
  43. });
  44. }
  45. });