tests_main.js 3.7 KB

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