You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.9 KiB

3 years ago
  1. // jshint esversion: 6, browser: false, node: true
  2. // This file is for automated testing, it should probably not be invoked for any other purpose.
  3. // It will:
  4. // 1. npm install
  5. // 2. bower install
  6. // 3. launch the server
  7. // 4. run the tests on the machine
  8. const Spawn = require('child_process').spawn;
  9. const processes = [];
  10. const killAll = (cb) => {
  11. processes.forEach((p) => { p.kill(); });
  12. setTimeout(() => {
  13. processes.forEach((p) => {
  14. console.log("Process [" + p.command + "] did not end, using kill-9");
  15. p.kill('SIGKILL');
  16. });
  17. cb();
  18. }, 10);
  19. };
  20. const error = (msg) => {
  21. killAll(() => {
  22. throw new Error(msg);
  23. });
  24. };
  25. const run = (cmd, args, cb) => {
  26. const proc = Spawn(cmd, args);
  27. processes.push(proc);
  28. proc.procName = cmd + ' ' + args.join(' ');
  29. console.log('>>' + proc.procName);
  30. proc.stdout.on('data', (data) => { process.stdout.write(data); });
  31. proc.stderr.on('data', (data) => { process.stderr.write(data); });
  32. proc.on('close', (code) => {
  33. const idx = processes.indexOf(proc);
  34. if (idx === -1) {
  35. error("process " + proc.procName + " disappeared from list");
  36. return;
  37. }
  38. processes.splice(idx, 1);
  39. if (code) {
  40. error("Process [" + proc.procName + "] ended with " + code);
  41. }
  42. cb();
  43. });
  44. };
  45. run('npm', ['install'], () => {
  46. const nThen = require('nthen');
  47. nThen((waitFor) => {
  48. if (process.platform === 'darwin') {
  49. run('bash', ['-c',
  50. 'ps -ef | grep -v grep | grep \'Google Chrome.app/Contents/MacOS/Google Chrome\'' +
  51. ' | awk \'{print $2}\' | while read x; do kill $x; done'
  52. ], waitFor());
  53. run('bash', ['-c',
  54. 'ps -ef | grep -v grep | grep \'/usr/bin/safaridriver\'' +
  55. ' | awk \'{print $2}\' | while read x; do kill $x; done'
  56. ], waitFor());
  57. run('bash', ['-c',
  58. 'ps -ef | grep -v grep | grep \'/Applications/Firefox.app/Contents/MacOS/firefox-bin\'' +
  59. ' | awk \'{print $2}\' | while read x; do kill $x; done'
  60. ], waitFor());
  61. run('bash', ['-c',
  62. 'lsof | grep \'TCP .*:hbci (LISTEN)\'' +
  63. ' | awk \'{print $2}\' | while read x; do kill $x; done'
  64. ], waitFor());
  65. run('bash', ['-c', 'rm -rf ./blob ./blobstage ./datastore'], waitFor());
  66. run('bash', ['-c', 'caffeinate -u -t 2'], waitFor());
  67. }
  68. }).nThen((waitFor) => {
  69. run('bower', ['install'], waitFor());
  70. }).nThen((waitFor) => {
  71. run('npm', ['run', 'fresh'], ()=>{});
  72. run('node', ['./scripts/TestSelenium.js'], waitFor());
  73. }).nThen((waitFor) => {
  74. if (process.platform === 'darwin') {
  75. run('bash', ['-c', 'pmset displaysleepnow'], waitFor());
  76. }
  77. }).nThen(killAll);
  78. });