main.js 4.0 KB

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