Front end of the Slack clone application.

runner.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Run before window.onload to make sure the specs have access to describe()
  2. // and other mocha methods. All feels very hacky though :-/
  3. this.mocha.setup('bdd');
  4. function runTests() {
  5. var runner = this.mocha.run();
  6. var failedTests = [];
  7. runner.on('end', function(){
  8. window.mochaResults = runner.stats;
  9. window.mochaResults.reports = failedTests;
  10. });
  11. function flattenTitles(test) {
  12. var titles = [];
  13. while (test.parent.title) {
  14. titles.push(test.parent.title);
  15. test = test.parent;
  16. }
  17. return titles.reverse();
  18. }
  19. function logFailure(test, err) {
  20. failedTests.push({
  21. name: test.title,
  22. result: false,
  23. message: err.message,
  24. stack: err.stack,
  25. titles: flattenTitles(test)
  26. });
  27. }
  28. runner.on('fail', logFailure);
  29. }
  30. if (!Array.prototype.forEach) {
  31. Array.prototype.forEach = function(callback, thisArg) {
  32. if (typeof(callback) !== "function") {
  33. throw new TypeError(callback + " is not a function!");
  34. }
  35. var len = this.length;
  36. for (var i = 0; i < len; i++) {
  37. callback.call(thisArg, this[i], i, this);
  38. }
  39. };
  40. }
  41. var require = this.require;
  42. if (require) {
  43. requirejs.config({
  44. paths: {
  45. localforage: '/dist/localforage'
  46. }
  47. });
  48. require(['localforage'], function(localforage) {
  49. window.localforage = localforage;
  50. require([
  51. '/test/test.api.js',
  52. '/test/test.config.js',
  53. '/test/test.datatypes.js',
  54. '/test/test.drivers.js',
  55. '/test/test.iframes.js',
  56. '/test/test.webworkers.js'
  57. ], runTests);
  58. });
  59. } else if (this.addEventListener) {
  60. this.addEventListener('load', runTests);
  61. } else if (this.attachEvent) {
  62. this.attachEvent('onload', runTests);
  63. }