a zip code crypto-currency system good for red ONLY

mocha-patch.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. (factory());
  12. }(this, (function () { 'use strict';
  13. /**
  14. * @license
  15. * Copyright Google Inc. All Rights Reserved.
  16. *
  17. * Use of this source code is governed by an MIT-style license that can be
  18. * found in the LICENSE file at https://angular.io/license
  19. */
  20. (function (context) {
  21. var Mocha = context.Mocha;
  22. if (typeof Mocha === 'undefined') {
  23. throw new Error('Missing Mocha.js');
  24. }
  25. if (typeof Zone === 'undefined') {
  26. throw new Error('Missing Zone.js');
  27. }
  28. var ProxyZoneSpec = Zone['ProxyZoneSpec'];
  29. var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
  30. if (!ProxyZoneSpec) {
  31. throw new Error('Missing ProxyZoneSpec');
  32. }
  33. if (Mocha['__zone_patch__']) {
  34. throw new Error('"Mocha" has already been patched with "Zone".');
  35. }
  36. Mocha['__zone_patch__'] = true;
  37. var rootZone = Zone.current;
  38. var syncZone = rootZone.fork(new SyncTestZoneSpec('Mocha.describe'));
  39. var testZone = null;
  40. var suiteZone = rootZone.fork(new ProxyZoneSpec());
  41. var mochaOriginal = {
  42. after: Mocha.after,
  43. afterEach: Mocha.afterEach,
  44. before: Mocha.before,
  45. beforeEach: Mocha.beforeEach,
  46. describe: Mocha.describe,
  47. it: Mocha.it
  48. };
  49. function modifyArguments(args, syncTest, asyncTest) {
  50. var _loop_1 = function (i) {
  51. var arg = args[i];
  52. if (typeof arg === 'function') {
  53. // The `done` callback is only passed through if the function expects at
  54. // least one argument.
  55. // Note we have to make a function with correct number of arguments,
  56. // otherwise mocha will
  57. // think that all functions are sync or async.
  58. args[i] = (arg.length === 0) ? syncTest(arg) : asyncTest(arg);
  59. // Mocha uses toString to view the test body in the result list, make sure we return the
  60. // correct function body
  61. args[i].toString = function () {
  62. return arg.toString();
  63. };
  64. }
  65. };
  66. for (var i = 0; i < args.length; i++) {
  67. _loop_1(i);
  68. }
  69. return args;
  70. }
  71. function wrapDescribeInZone(args) {
  72. var syncTest = function (fn) {
  73. return function () {
  74. return syncZone.run(fn, this, arguments);
  75. };
  76. };
  77. return modifyArguments(args, syncTest);
  78. }
  79. function wrapTestInZone(args) {
  80. var asyncTest = function (fn) {
  81. return function (done) {
  82. return testZone.run(fn, this, [done]);
  83. };
  84. };
  85. var syncTest = function (fn) {
  86. return function () {
  87. return testZone.run(fn, this);
  88. };
  89. };
  90. return modifyArguments(args, syncTest, asyncTest);
  91. }
  92. function wrapSuiteInZone(args) {
  93. var asyncTest = function (fn) {
  94. return function (done) {
  95. return suiteZone.run(fn, this, [done]);
  96. };
  97. };
  98. var syncTest = function (fn) {
  99. return function () {
  100. return suiteZone.run(fn, this);
  101. };
  102. };
  103. return modifyArguments(args, syncTest, asyncTest);
  104. }
  105. context.describe = context.suite = Mocha.describe = function () {
  106. return mochaOriginal.describe.apply(this, wrapDescribeInZone(arguments));
  107. };
  108. context.xdescribe = context.suite.skip = Mocha.describe.skip = function () {
  109. return mochaOriginal.describe.skip.apply(this, wrapDescribeInZone(arguments));
  110. };
  111. context.describe.only = context.suite.only = Mocha.describe.only = function () {
  112. return mochaOriginal.describe.only.apply(this, wrapDescribeInZone(arguments));
  113. };
  114. context.it = context.specify = context.test = Mocha.it = function () {
  115. return mochaOriginal.it.apply(this, wrapTestInZone(arguments));
  116. };
  117. context.xit = context.xspecify = Mocha.it.skip = function () {
  118. return mochaOriginal.it.skip.apply(this, wrapTestInZone(arguments));
  119. };
  120. context.it.only = context.test.only = Mocha.it.only = function () {
  121. return mochaOriginal.it.only.apply(this, wrapTestInZone(arguments));
  122. };
  123. context.after = context.suiteTeardown = Mocha.after = function () {
  124. return mochaOriginal.after.apply(this, wrapSuiteInZone(arguments));
  125. };
  126. context.afterEach = context.teardown = Mocha.afterEach = function () {
  127. return mochaOriginal.afterEach.apply(this, wrapTestInZone(arguments));
  128. };
  129. context.before = context.suiteSetup = Mocha.before = function () {
  130. return mochaOriginal.before.apply(this, wrapSuiteInZone(arguments));
  131. };
  132. context.beforeEach = context.setup = Mocha.beforeEach = function () {
  133. return mochaOriginal.beforeEach.apply(this, wrapTestInZone(arguments));
  134. };
  135. (function (originalRunTest, originalRun) {
  136. Mocha.Runner.prototype.runTest = function (fn) {
  137. var _this = this;
  138. Zone.current.scheduleMicroTask('mocha.forceTask', function () {
  139. originalRunTest.call(_this, fn);
  140. });
  141. };
  142. Mocha.Runner.prototype.run = function (fn) {
  143. this.on('test', function (e) {
  144. testZone = rootZone.fork(new ProxyZoneSpec());
  145. });
  146. this.on('fail', function (test, err) {
  147. var proxyZoneSpec = testZone && testZone.get('ProxyZoneSpec');
  148. if (proxyZoneSpec && err) {
  149. err.message += proxyZoneSpec.getAndClearPendingTasksInfo();
  150. }
  151. });
  152. return originalRun.call(this, fn);
  153. };
  154. })(Mocha.Runner.prototype.runTest, Mocha.Runner.prototype.run);
  155. })(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
  156. })));