main.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Extra test dependencies
  2. config.paths.mock = "tests/mock";
  3. config.paths.utils = "tests/utils";
  4. config.paths.jasmine = "components/jasmine/lib/jasmine-core/jasmine";
  5. config.paths["jasmine-html"] = "components/jasmine/lib/jasmine-core/jasmine-html";
  6. config.paths["console-runner"] = "node_modules/phantom-jasmine/lib/console-runner";
  7. config.shim['jasmine-html'] = {
  8. deps: ['jasmine'],
  9. exports: 'jasmine'
  10. };
  11. require.config(config);
  12. // Polyfill 'bind' which is not available in phantomjs < 2.0
  13. if (!Function.prototype.bind) {
  14. Function.prototype.bind = function (oThis) {
  15. if (typeof this !== "function") {
  16. // closest thing possible to the ECMAScript 5 internal IsCallable function
  17. throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
  18. }
  19. var aArgs = Array.prototype.slice.call(arguments, 1),
  20. fToBind = this,
  21. fNOP = function () {},
  22. fBound = function () {
  23. return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
  24. aArgs.concat(Array.prototype.slice.call(arguments)));
  25. };
  26. fNOP.prototype = this.prototype;
  27. fBound.prototype = new fNOP();
  28. return fBound;
  29. };
  30. }
  31. require([
  32. "jquery",
  33. "converse",
  34. "mock",
  35. "jasmine-html"
  36. ], function($, converse, mock, jasmine) {
  37. // Set up converse.js
  38. window.converse_api = converse;
  39. window.localStorage.clear();
  40. converse.initialize({
  41. prebind: false,
  42. xhr_user_search: false,
  43. auto_subscribe: false,
  44. animate: false,
  45. connection: mock.mock_connection,
  46. no_trimming: true
  47. }, function (converse) {
  48. window.converse = converse;
  49. window.crypto = {
  50. getRandomValues: function (buf) {
  51. var i;
  52. for (i=0, len=buf.length; i<len; i++) {
  53. buf[i] = Math.floor(Math.random()*256);
  54. }
  55. }
  56. };
  57. require([
  58. "console-runner",
  59. "spec/converse",
  60. "spec/otr",
  61. "spec/eventemitter",
  62. "spec/controlbox",
  63. "spec/chatbox",
  64. "spec/chatroom"
  65. ], function () {
  66. // Make sure this callback is only called once.
  67. delete converse.callback;
  68. // Stub the trimChat method. It causes havoc when running with
  69. // phantomJS.
  70. converse.ChatBoxViews.prototype.trimChat = function () {};
  71. // Jasmine stuff
  72. var jasmineEnv = jasmine.getEnv();
  73. var reporter;
  74. if (/PhantomJS/.test(navigator.userAgent)) {
  75. reporter = new jasmine.ConsoleReporter();
  76. window.console_reporter = reporter;
  77. jasmineEnv.addReporter(reporter);
  78. jasmineEnv.updateInterval = 0;
  79. } else {
  80. reporter = new jasmine.HtmlReporter();
  81. jasmineEnv.addReporter(reporter);
  82. jasmineEnv.specFilter = function(spec) {
  83. return reporter.specFilter(spec);
  84. };
  85. jasmineEnv.updateInterval = 0;
  86. }
  87. jasmineEnv.execute();
  88. });
  89. });
  90. }
  91. );