2
0

main.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. i18n: window.locales.en,
  43. auto_subscribe: false,
  44. animate: false,
  45. connection: mock.mock_connection,
  46. no_trimming: true,
  47. debug: false
  48. }, function (converse) {
  49. window.converse = converse;
  50. window.crypto = {
  51. getRandomValues: function (buf) {
  52. var i;
  53. for (i=0, len=buf.length; i<len; i++) {
  54. buf[i] = Math.floor(Math.random()*256);
  55. }
  56. }
  57. };
  58. require([
  59. "console-runner",
  60. "mockup/mockup"
  61. ], function () {
  62. // Make sure this callback is only called once.
  63. delete converse.callback;
  64. // Stub the trimChat method. It causes havoc when running with
  65. // phantomJS.
  66. converse.ChatBoxViews.prototype.trimChat = function () {};
  67. // Jasmine stuff
  68. var jasmineEnv = jasmine.getEnv();
  69. var reporter;
  70. if (/PhantomJS/.test(navigator.userAgent)) {
  71. reporter = new jasmine.ConsoleReporter();
  72. window.console_reporter = reporter;
  73. jasmineEnv.addReporter(reporter);
  74. jasmineEnv.updateInterval = 0;
  75. } else {
  76. reporter = new jasmine.HtmlReporter();
  77. jasmineEnv.addReporter(reporter);
  78. jasmineEnv.specFilter = function(spec) {
  79. return reporter.specFilter(spec);
  80. };
  81. jasmineEnv.updateInterval = 0;
  82. }
  83. jasmineEnv.execute();
  84. });
  85. });
  86. }
  87. );