Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

browser-entry.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. 'use strict';
  2. /* eslint no-unused-vars: off */
  3. /* eslint-env commonjs */
  4. /**
  5. * Shim process.stdout.
  6. */
  7. process.stdout = require('browser-stdout')({label: false});
  8. var Mocha = require('./lib/mocha');
  9. /**
  10. * Create a Mocha instance.
  11. *
  12. * @return {undefined}
  13. */
  14. var mocha = new Mocha({reporter: 'html'});
  15. /**
  16. * Save timer references to avoid Sinon interfering (see GH-237).
  17. */
  18. var Date = global.Date;
  19. var setTimeout = global.setTimeout;
  20. var setInterval = global.setInterval;
  21. var clearTimeout = global.clearTimeout;
  22. var clearInterval = global.clearInterval;
  23. var uncaughtExceptionHandlers = [];
  24. var originalOnerrorHandler = global.onerror;
  25. /**
  26. * Remove uncaughtException listener.
  27. * Revert to original onerror handler if previously defined.
  28. */
  29. process.removeListener = function(e, fn) {
  30. if (e === 'uncaughtException') {
  31. if (originalOnerrorHandler) {
  32. global.onerror = originalOnerrorHandler;
  33. } else {
  34. global.onerror = function() {};
  35. }
  36. var i = uncaughtExceptionHandlers.indexOf(fn);
  37. if (i !== -1) {
  38. uncaughtExceptionHandlers.splice(i, 1);
  39. }
  40. }
  41. };
  42. /**
  43. * Implements listenerCount for 'uncaughtException'.
  44. */
  45. process.listenerCount = function(name) {
  46. if (name === 'uncaughtException') {
  47. return uncaughtExceptionHandlers.length;
  48. }
  49. return 0;
  50. };
  51. /**
  52. * Implements uncaughtException listener.
  53. */
  54. process.on = function(e, fn) {
  55. if (e === 'uncaughtException') {
  56. global.onerror = function(err, url, line) {
  57. fn(new Error(err + ' (' + url + ':' + line + ')'));
  58. return !mocha.options.allowUncaught;
  59. };
  60. uncaughtExceptionHandlers.push(fn);
  61. }
  62. };
  63. // The BDD UI is registered by default, but no UI will be functional in the
  64. // browser without an explicit call to the overridden `mocha.ui` (see below).
  65. // Ensure that this default UI does not expose its methods to the global scope.
  66. mocha.suite.removeAllListeners('pre-require');
  67. var immediateQueue = [];
  68. var immediateTimeout;
  69. function timeslice() {
  70. var immediateStart = new Date().getTime();
  71. while (immediateQueue.length && new Date().getTime() - immediateStart < 100) {
  72. immediateQueue.shift()();
  73. }
  74. if (immediateQueue.length) {
  75. immediateTimeout = setTimeout(timeslice, 0);
  76. } else {
  77. immediateTimeout = null;
  78. }
  79. }
  80. /**
  81. * High-performance override of Runner.immediately.
  82. */
  83. Mocha.Runner.immediately = function(callback) {
  84. immediateQueue.push(callback);
  85. if (!immediateTimeout) {
  86. immediateTimeout = setTimeout(timeslice, 0);
  87. }
  88. };
  89. /**
  90. * Function to allow assertion libraries to throw errors directly into mocha.
  91. * This is useful when running tests in a browser because window.onerror will
  92. * only receive the 'message' attribute of the Error.
  93. */
  94. mocha.throwError = function(err) {
  95. uncaughtExceptionHandlers.forEach(function(fn) {
  96. fn(err);
  97. });
  98. throw err;
  99. };
  100. /**
  101. * Override ui to ensure that the ui functions are initialized.
  102. * Normally this would happen in Mocha.prototype.loadFiles.
  103. */
  104. mocha.ui = function(ui) {
  105. Mocha.prototype.ui.call(this, ui);
  106. this.suite.emit('pre-require', global, null, this);
  107. return this;
  108. };
  109. /**
  110. * Setup mocha with the given setting options.
  111. */
  112. mocha.setup = function(opts) {
  113. if (typeof opts === 'string') {
  114. opts = {ui: opts};
  115. }
  116. for (var opt in opts) {
  117. if (Object.prototype.hasOwnProperty.call(opts, opt)) {
  118. this[opt](opts[opt]);
  119. }
  120. }
  121. return this;
  122. };
  123. /**
  124. * Run mocha, returning the Runner.
  125. */
  126. mocha.run = function(fn) {
  127. var options = mocha.options;
  128. mocha.globals('location');
  129. var query = Mocha.utils.parseQuery(global.location.search || '');
  130. if (query.grep) {
  131. mocha.grep(query.grep);
  132. }
  133. if (query.fgrep) {
  134. mocha.fgrep(query.fgrep);
  135. }
  136. if (query.invert) {
  137. mocha.invert();
  138. }
  139. return Mocha.prototype.run.call(mocha, function(err) {
  140. // The DOM Document is not available in Web Workers.
  141. var document = global.document;
  142. if (
  143. document &&
  144. document.getElementById('mocha') &&
  145. options.noHighlighting !== true
  146. ) {
  147. Mocha.utils.highlightTags('code');
  148. }
  149. if (fn) {
  150. fn(err);
  151. }
  152. });
  153. };
  154. /**
  155. * Expose the process shim.
  156. * https://github.com/mochajs/mocha/pull/916
  157. */
  158. Mocha.process = process;
  159. /**
  160. * Expose mocha.
  161. */
  162. global.Mocha = Mocha;
  163. global.mocha = mocha;
  164. // this allows test/acceptance/required-tokens.js to pass; thus,
  165. // you can now do `const describe = require('mocha').describe` in a
  166. // browser context (assuming browserification). should fix #880
  167. module.exports = global;