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.

runTests.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @copyright 2018 Julius Härtl <jus@bitgrid.net>
  3. *
  4. * @author 2018 Julius Härtl <jus@bitgrid.net>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. const fs = require('fs')
  23. const Mocha = require('mocha')
  24. const testFolder = './test/'
  25. var tests = [
  26. 'install',
  27. 'login',
  28. 'files',
  29. 'public',
  30. 'settings',
  31. 'apps',
  32. ]
  33. var args = process.argv.slice(2);
  34. if (args.length > 0) {
  35. tests = args
  36. }
  37. var config = {
  38. tests: tests,
  39. pr: process.env.DRONE_PULL_REQUEST,
  40. repoUrl: process.env.DRONE_REPO_LINK,
  41. };
  42. console.log('=> Write test config');
  43. console.log(config);
  44. fs.writeFile('out/config.json', JSON.stringify(config), 'utf8', () => {});
  45. var mocha = new Mocha({
  46. timeout: 60000
  47. });
  48. let result = {};
  49. tests.forEach(async function (test) {
  50. mocha.addFile('./test/' + test + 'Spec.js')
  51. result[test] = {
  52. failures: [],
  53. passes: [],
  54. tests: [],
  55. pending: [],
  56. stats: {}
  57. }
  58. });
  59. // fixme fail if installation failed
  60. // write json to file
  61. function clean (test) {
  62. return {
  63. title: test.title,
  64. fullTitle: test.fullTitle(),
  65. duration: test.duration,
  66. currentRetry: test.currentRetry(),
  67. failedAction: test.failedAction,
  68. err: errorJSON(test.err || {})
  69. };
  70. }
  71. function errorJSON (err) {
  72. var res = {};
  73. Object.getOwnPropertyNames(err).forEach(function (key) {
  74. res[key] = err[key];
  75. }, err);
  76. return res;
  77. }
  78. mocha.run()
  79. .on('test', function (test) {
  80. })
  81. .on('suite end', function(suite) {
  82. if (result[suite.title] === undefined)
  83. return;
  84. result[suite.title].stats = suite.stats;
  85. })
  86. .on('test end', function (test) {
  87. result[test.parent.title].tests.push(test);
  88. })
  89. .on('pass', function (test) {
  90. result[test.parent.title].passes.push(test);
  91. })
  92. .on('fail', function (test) {
  93. result[test.parent.title].failures.push(test);
  94. })
  95. .on('pending', function (test) {
  96. result[test.parent.title].pending.push(test);
  97. })
  98. .on('end', function () {
  99. tests.forEach(function (test) {
  100. var json = JSON.stringify({
  101. stats: result[test].stats,
  102. tests: result[test].tests.map(clean),
  103. pending: result[test].pending.map(clean),
  104. failures: result[test].failures.map(clean),
  105. passes: result[test].passes.map(clean)
  106. }, null, 2);
  107. fs.writeFile(`out/${test}.json`, json, 'utf8', function () {
  108. console.log(`Written test result to out/${test}.json`)
  109. });
  110. });
  111. var errorMessage = 'This PR introduces some UI differences, please check at {LINK}, if there are regressions based on the changes.'
  112. fs.writeFile('out/GITHUB_COMMENT', errorMessage, 'utf8', () => {});
  113. });