tests_main.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.localStorage.clear();
  48. converse.initialize({
  49. prebind: false,
  50. xhr_user_search: false,
  51. auto_subscribe: false,
  52. animate: false,
  53. show_call_button: true,
  54. connection: mock.mock_connection,
  55. testing: true
  56. }, function (converse) {
  57. window.converse = converse;
  58. require([
  59. "jasmine-console-reporter",
  60. "jasmine-junit-reporter",
  61. "spec/converse",
  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. // Jasmine stuff
  69. var jasmineEnv = jasmine.getEnv();
  70. if (/PhantomJS/.test(navigator.userAgent)) {
  71. jasmineEnv.addReporter(new jasmine.TrivialReporter());
  72. jasmineEnv.addReporter(new jasmine.JUnitXmlReporter('./test-reports/'));
  73. jasmineEnv.addReporter(new jasmine.ConsoleReporter());
  74. jasmineEnv.updateInterval = 0;
  75. } else {
  76. var htmlReporter = new jasmine.HtmlReporter();
  77. jasmineEnv.addReporter(htmlReporter);
  78. jasmineEnv.addReporter(new jasmine.ConsoleReporter());
  79. jasmineEnv.specFilter = function(spec) {
  80. return htmlReporter.specFilter(spec);
  81. };
  82. jasmineEnv.updateInterval = 100;
  83. }
  84. jasmineEnv.execute();
  85. });
  86. });
  87. }
  88. );