main.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Extra test dependencies
  2. config.paths.mock = "tests/mock";
  3. config.paths.test_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. window.sessionStorage.clear();
  41. converse.initialize({
  42. auto_subscribe: false,
  43. animate: false,
  44. connection: mock.mock_connection,
  45. no_trimming: true,
  46. debug: 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. "spec/minchats",
  66. "spec/profiling",
  67. "spec/register"
  68. ], function () {
  69. // Make sure this callback is only called once.
  70. delete converse.callback;
  71. // Stub the trimChat method. It causes havoc when running with
  72. // phantomJS.
  73. converse.ChatBoxViews.prototype.trimChat = function () {};
  74. // Jasmine stuff
  75. var jasmineEnv = jasmine.getEnv();
  76. var reporter;
  77. if (/PhantomJS/.test(navigator.userAgent)) {
  78. reporter = new jasmine.ConsoleReporter();
  79. window.console_reporter = reporter;
  80. jasmineEnv.addReporter(reporter);
  81. jasmineEnv.updateInterval = 0;
  82. } else {
  83. reporter = new jasmine.HtmlReporter();
  84. jasmineEnv.addReporter(reporter);
  85. jasmineEnv.specFilter = function(spec) {
  86. return reporter.specFilter(spec);
  87. };
  88. jasmineEnv.updateInterval = 0;
  89. }
  90. jasmineEnv.execute();
  91. });
  92. });
  93. }
  94. );