zone.configurations.api.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /**
  2. * @license
  3. * Copyright Google LLC 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. /**
  9. * Interface of `zone.js` configurations.
  10. *
  11. * You can define the following configurations on the `window/global` object before
  12. * importing `zone.js` to change `zone.js` default behaviors.
  13. */
  14. interface ZoneGlobalConfigurations {
  15. /**
  16. * Disable the monkey patch of the `Node.js` `EventEmitter` API.
  17. *
  18. * By default, `zone.js` monkey patches the `Node.js` `EventEmitter` APIs to make asynchronous
  19. * callbacks of those APIs in the same zone when scheduled.
  20. *
  21. * Consider the following example:
  22. *
  23. * ```
  24. * const EventEmitter = require('events');
  25. * class MyEmitter extends EventEmitter {}
  26. * const myEmitter = new MyEmitter();
  27. *
  28. * const zone = Zone.current.fork({name: 'myZone'});
  29. * zone.run(() => {
  30. * myEmitter.on('event', () => {
  31. * console.log('an event occurs in the zone', Zone.current.name);
  32. * // the callback runs in the zone when it is scheduled,
  33. * // so the output is 'an event occurs in the zone myZone'.
  34. * });
  35. * });
  36. * myEmitter.emit('event');
  37. * ```
  38. *
  39. * If you set `__Zone_disable_EventEmitter = true` before importing `zone.js`,
  40. * `zone.js` does not monkey patch the `EventEmitter` APIs and the above code
  41. * outputs 'an event occurred <root>'.
  42. */
  43. __Zone_disable_EventEmitter?: boolean;
  44. /**
  45. * Disable the monkey patch of the `Node.js` `fs` API.
  46. *
  47. * By default, `zone.js` monkey patches `Node.js` `fs` APIs to make asynchronous callbacks of
  48. * those APIs in the same zone when scheduled.
  49. *
  50. * Consider the following example:
  51. *
  52. * ```
  53. * const fs = require('fs');
  54. *
  55. * const zone = Zone.current.fork({name: 'myZone'});
  56. * zone.run(() => {
  57. * fs.stat('/tmp/world', (err, stats) => {
  58. * console.log('fs.stats() callback is invoked in the zone', Zone.current.name);
  59. * // since the callback of the `fs.stat()` runs in the same zone
  60. * // when it is called, so the output is 'fs.stats() callback is invoked in the zone myZone'.
  61. * });
  62. * });
  63. * ```
  64. *
  65. * If you set `__Zone_disable_fs = true` before importing `zone.js`,
  66. * `zone.js` does not monkey patch the `fs` API and the above code
  67. * outputs 'get stats occurred <root>'.
  68. */
  69. __Zone_disable_fs?: boolean;
  70. /**
  71. * Disable the monkey patch of the `Node.js` `timer` API.
  72. *
  73. * By default, `zone.js` monkey patches the `Node.js` `timer` APIs to make asynchronous
  74. * callbacks of those APIs in the same zone when scheduled.
  75. *
  76. * Consider the following example:
  77. *
  78. * ```
  79. * const zone = Zone.current.fork({name: 'myZone'});
  80. * zone.run(() => {
  81. * setTimeout(() => {
  82. * console.log('setTimeout() callback is invoked in the zone', Zone.current.name);
  83. * // since the callback of `setTimeout()` runs in the same zone
  84. * // when it is scheduled, so the output is 'setTimeout() callback is invoked in the zone
  85. * // myZone'.
  86. * });
  87. * });
  88. * ```
  89. *
  90. * If you set `__Zone_disable_timers = true` before importing `zone.js`,
  91. * `zone.js` does not monkey patch the `timer` APIs and the above code
  92. * outputs 'timeout <root>'.
  93. */
  94. __Zone_disable_node_timers?: boolean;
  95. /**
  96. * Disable the monkey patch of the `Node.js` `process.nextTick()` API.
  97. *
  98. * By default, `zone.js` monkey patches the `Node.js` `process.nextTick()` API to make the
  99. * callback in the same zone when calling `process.nextTick()`.
  100. *
  101. * Consider the following example:
  102. *
  103. * ```
  104. * const zone = Zone.current.fork({name: 'myZone'});
  105. * zone.run(() => {
  106. * process.nextTick(() => {
  107. * console.log('process.nextTick() callback is invoked in the zone', Zone.current.name);
  108. * // since the callback of `process.nextTick()` runs in the same zone
  109. * // when it is scheduled, so the output is 'process.nextTick() callback is invoked in the
  110. * // zone myZone'.
  111. * });
  112. * });
  113. * ```
  114. *
  115. * If you set `__Zone_disable_nextTick = true` before importing `zone.js`,
  116. * `zone.js` does not monkey patch the `process.nextTick()` API and the above code
  117. * outputs 'nextTick <root>'.
  118. */
  119. __Zone_disable_nextTick?: boolean;
  120. /**
  121. * Disable the monkey patch of the `Node.js` `crypto` API.
  122. *
  123. * By default, `zone.js` monkey patches the `Node.js` `crypto` APIs to make asynchronous callbacks
  124. * of those APIs in the same zone when called.
  125. *
  126. * Consider the following example:
  127. *
  128. * ```
  129. * const crypto = require('crypto');
  130. *
  131. * const zone = Zone.current.fork({name: 'myZone'});
  132. * zone.run(() => {
  133. * crypto.randomBytes(() => {
  134. * console.log('crypto.randomBytes() callback is invoked in the zone', Zone.current.name);
  135. * // since the callback of `crypto.randomBytes()` runs in the same zone
  136. * // when it is called, so the output is 'crypto.randomBytes() callback is invoked in the
  137. * // zone myZone'.
  138. * });
  139. * });
  140. * ```
  141. *
  142. * If you set `__Zone_disable_crypto = true` before importing `zone.js`,
  143. * `zone.js` does not monkey patch the `crypto` API and the above code
  144. * outputs 'crypto <root>'.
  145. */
  146. __Zone_disable_crypto?: boolean;
  147. /**
  148. * Disable the monkey patch of the `Object.defineProperty()` API.
  149. *
  150. * Note: This configuration is available only in the legacy bundle (dist/zone.js). This module is
  151. * not available in the evergreen bundle (zone-evergreen.js).
  152. *
  153. * In the legacy browser, the default behavior of `zone.js` is to monkey patch
  154. * `Object.defineProperty()` and `Object.create()` to try to ensure PropertyDescriptor parameter's
  155. * configurable property to be true. This patch is only needed in some old mobile browsers.
  156. *
  157. * If you set `__Zone_disable_defineProperty = true` before importing `zone.js`,
  158. * `zone.js` does not monkey patch the `Object.defineProperty()` API and does not
  159. * modify desc.configurable to true.
  160. *
  161. */
  162. __Zone_disable_defineProperty?: boolean;
  163. /**
  164. * Disable the monkey patch of the browser `registerElement()` API.
  165. *
  166. * NOTE: This configuration is only available in the legacy bundle (dist/zone.js), this
  167. * module is not available in the evergreen bundle (zone-evergreen.js).
  168. *
  169. * In the legacy browser, the default behavior of `zone.js` is to monkey patch the
  170. * `registerElement()` API to make asynchronous callbacks of the API in the same zone when
  171. * `registerElement()` is called.
  172. *
  173. * Consider the following example:
  174. *
  175. * ```
  176. * const proto = Object.create(HTMLElement.prototype);
  177. * proto.createdCallback = function() {
  178. * console.log('createdCallback is invoked in the zone', Zone.current.name);
  179. * };
  180. * proto.attachedCallback = function() {
  181. * console.log('attachedCallback is invoked in the zone', Zone.current.name);
  182. * };
  183. * proto.detachedCallback = function() {
  184. * console.log('detachedCallback is invoked in the zone', Zone.current.name);
  185. * };
  186. * proto.attributeChangedCallback = function() {
  187. * console.log('attributeChangedCallback is invoked in the zone', Zone.current.name);
  188. * };
  189. *
  190. * const zone = Zone.current.fork({name: 'myZone'});
  191. * zone.run(() => {
  192. * document.registerElement('x-elem', {prototype: proto});
  193. * });
  194. * ```
  195. *
  196. * When these callbacks are invoked, those callbacks will be in the zone when
  197. * `registerElement()` is called.
  198. *
  199. * If you set `__Zone_disable_registerElement = true` before importing `zone.js`,
  200. * `zone.js` does not monkey patch `registerElement()` API and the above code
  201. * outputs '<root>'.
  202. */
  203. __Zone_disable_registerElement?: boolean;
  204. /**
  205. * Disable the monkey patch of the browser legacy `EventTarget` API.
  206. *
  207. * NOTE: This configuration is only available in the legacy bundle (dist/zone.js), this module
  208. * is not available in the evergreen bundle (zone-evergreen.js).
  209. *
  210. * In some old browsers, the `EventTarget` is not available, so `zone.js` cannot directly monkey
  211. * patch the `EventTarget`. Instead, `zone.js` patches all known HTML elements' prototypes (such
  212. * as `HtmlDivElement`). The callback of the `addEventListener()` will be in the same zone when
  213. * the `addEventListener()` is called.
  214. *
  215. * Consider the following example:
  216. *
  217. * ```
  218. * const zone = Zone.current.fork({name: 'myZone'});
  219. * zone.run(() => {
  220. * div.addEventListener('click', () => {
  221. * console.log('div click event listener is invoked in the zone', Zone.current.name);
  222. * // the output is 'div click event listener is invoked in the zone myZone'.
  223. * });
  224. * });
  225. * ```
  226. *
  227. * If you set `__Zone_disable_EventTargetLegacy = true` before importing `zone.js`
  228. * In some old browsers, where `EventTarget` is not available, if you set
  229. * `__Zone_disable_EventTargetLegacy = true` before importing `zone.js`, `zone.js` does not monkey
  230. * patch all HTML element APIs and the above code outputs 'clicked <root>'.
  231. */
  232. __Zone_disable_EventTargetLegacy?: boolean;
  233. /**
  234. * Disable the monkey patch of the browser `timer` APIs.
  235. *
  236. * By default, `zone.js` monkey patches browser timer
  237. * APIs (`setTimeout()`/`setInterval()`/`setImmediate()`) to make asynchronous callbacks of those
  238. * APIs in the same zone when scheduled.
  239. *
  240. * Consider the following example:
  241. *
  242. * ```
  243. * const zone = Zone.current.fork({name: 'myZone'});
  244. * zone.run(() => {
  245. * setTimeout(() => {
  246. * console.log('setTimeout() callback is invoked in the zone', Zone.current.name);
  247. * // since the callback of `setTimeout()` runs in the same zone
  248. * // when it is scheduled, so the output is 'setTimeout() callback is invoked in the zone
  249. * // myZone'.
  250. * });
  251. * });
  252. * ```
  253. *
  254. * If you set `__Zone_disable_timers = true` before importing `zone.js`,
  255. * `zone.js` does not monkey patch `timer` API and the above code
  256. * outputs 'timeout <root>'.
  257. *
  258. */
  259. __Zone_disable_timers?: boolean;
  260. /**
  261. * Disable the monkey patch of the browser `requestAnimationFrame()` API.
  262. *
  263. * By default, `zone.js` monkey patches the browser `requestAnimationFrame()` API
  264. * to make the asynchronous callback of the `requestAnimationFrame()` in the same zone when
  265. * scheduled.
  266. *
  267. * Consider the following example:
  268. *
  269. * ```
  270. * const zone = Zone.current.fork({name: 'myZone'});
  271. * zone.run(() => {
  272. * requestAnimationFrame(() => {
  273. * console.log('requestAnimationFrame() callback is invoked in the zone', Zone.current.name);
  274. * // since the callback of `requestAnimationFrame()` will be in the same zone
  275. * // when it is scheduled, so the output will be 'requestAnimationFrame() callback is invoked
  276. * // in the zone myZone'
  277. * });
  278. * });
  279. * ```
  280. *
  281. * If you set `__Zone_disable_requestAnimationFrame = true` before importing `zone.js`,
  282. * `zone.js` does not monkey patch the `requestAnimationFrame()` API and the above code
  283. * outputs 'raf <root>'.
  284. */
  285. __Zone_disable_requestAnimationFrame?: boolean;
  286. /**
  287. *
  288. * Disable the monkey patching of the browser's `queueMicrotask()` API.
  289. *
  290. * By default, `zone.js` monkey patches the browser's `queueMicrotask()` API
  291. * to ensure that `queueMicrotask()` callback is invoked in the same zone as zone used to invoke
  292. * `queueMicrotask()`. And also the callback is running as `microTask` like
  293. * `Promise.prototype.then()`.
  294. *
  295. * Consider the following example:
  296. *
  297. * ```
  298. * const zone = Zone.current.fork({name: 'myZone'});
  299. * zone.run(() => {
  300. * queueMicrotask(() => {
  301. * console.log('queueMicrotask() callback is invoked in the zone', Zone.current.name);
  302. * // Since `queueMicrotask()` was invoked in `myZone`, same zone is restored
  303. * // when 'queueMicrotask() callback is invoked, resulting in `myZone` being console logged.
  304. * });
  305. * });
  306. * ```
  307. *
  308. * If you set `__Zone_disable_queueMicrotask = true` before importing `zone.js`,
  309. * `zone.js` does not monkey patch the `queueMicrotask()` API and the above code
  310. * output will change to: 'queueMicrotask() callback is invoked in the zone <root>'.
  311. */
  312. __Zone_disable_queueMicrotask?: boolean;
  313. /**
  314. *
  315. * Disable the monkey patch of the browser blocking APIs(`alert()`/`prompt()`/`confirm()`).
  316. */
  317. __Zone_disable_blocking?: boolean;
  318. /**
  319. * Disable the monkey patch of the browser `EventTarget` APIs.
  320. *
  321. * By default, `zone.js` monkey patches EventTarget APIs. The callbacks of the
  322. * `addEventListener()` run in the same zone when the `addEventListener()` is called.
  323. *
  324. * Consider the following example:
  325. *
  326. * ```
  327. * const zone = Zone.current.fork({name: 'myZone'});
  328. * zone.run(() => {
  329. * div.addEventListener('click', () => {
  330. * console.log('div event listener is invoked in the zone', Zone.current.name);
  331. * // the output is 'div event listener is invoked in the zone myZone'.
  332. * });
  333. * });
  334. * ```
  335. *
  336. * If you set `__Zone_disable_EventTarget = true` before importing `zone.js`,
  337. * `zone.js` does not monkey patch EventTarget API and the above code
  338. * outputs 'clicked <root>'.
  339. *
  340. */
  341. __Zone_disable_EventTarget?: boolean;
  342. /**
  343. * Disable the monkey patch of the browser `FileReader` APIs.
  344. */
  345. __Zone_disable_FileReader?: boolean;
  346. /**
  347. * Disable the monkey patch of the browser `MutationObserver` APIs.
  348. */
  349. __Zone_disable_MutationObserver?: boolean;
  350. /**
  351. * Disable the monkey patch of the browser `IntersectionObserver` APIs.
  352. */
  353. __Zone_disable_IntersectionObserver?: boolean;
  354. /**
  355. * Disable the monkey patch of the browser onProperty APIs(such as onclick).
  356. *
  357. * By default, `zone.js` monkey patches onXXX properties (such as onclick). The callbacks of onXXX
  358. * properties run in the same zone when the onXXX properties is set.
  359. *
  360. * Consider the following example:
  361. *
  362. * ```
  363. * const zone = Zone.current.fork({name: 'myZone'});
  364. * zone.run(() => {
  365. * div.onclick = () => {
  366. * console.log('div click event listener is invoked in the zone', Zone.current.name);
  367. * // the output will be 'div click event listener is invoked in the zone myZone'
  368. * }
  369. * });
  370. * ```
  371. *
  372. * If you set `__Zone_disable_on_property = true` before importing `zone.js`,
  373. * `zone.js` does not monkey patch onXXX properties and the above code
  374. * outputs 'clicked <root>'.
  375. *
  376. */
  377. __Zone_disable_on_property?: boolean;
  378. /**
  379. * Disable the monkey patch of the browser `customElements` APIs.
  380. *
  381. * By default, `zone.js` monkey patches `customElements` APIs to make callbacks run in the
  382. * same zone when the `customElements.define()` is called.
  383. *
  384. * Consider the following example:
  385. *
  386. * ```
  387. * class TestCustomElement extends HTMLElement {
  388. * constructor() { super(); }
  389. * connectedCallback() {}
  390. * disconnectedCallback() {}
  391. * attributeChangedCallback(attrName, oldVal, newVal) {}
  392. * adoptedCallback() {}
  393. * }
  394. *
  395. * const zone = Zone.fork({name: 'myZone'});
  396. * zone.run(() => {
  397. * customElements.define('x-elem', TestCustomElement);
  398. * });
  399. * ```
  400. *
  401. * All those callbacks defined in TestCustomElement runs in the zone when
  402. * the `customElements.define()` is called.
  403. *
  404. * If you set `__Zone_disable_customElements = true` before importing `zone.js`,
  405. * `zone.js` does not monkey patch `customElements` APIs and the above code
  406. * runs inside <root> zone.
  407. */
  408. __Zone_disable_customElements?: boolean;
  409. /**
  410. * Disable the monkey patch of the browser `XMLHttpRequest` APIs.
  411. *
  412. * By default, `zone.js` monkey patches `XMLHttpRequest` APIs to make XMLHttpRequest act
  413. * as macroTask.
  414. *
  415. * Consider the following example:
  416. *
  417. * ```
  418. * const zone = Zone.current.fork({
  419. * name: 'myZone',
  420. * onScheduleTask: (delegate, curr, target, task) => {
  421. * console.log('task is scheduled', task.type, task.source, task.zone.name);
  422. * return delegate.scheduleTask(target, task);
  423. * }
  424. * })
  425. * const xhr = new XMLHttpRequest();
  426. * zone.run(() => {
  427. * xhr.onload = function() {};
  428. * xhr.open('get', '/', true);
  429. * xhr.send();
  430. * });
  431. * ```
  432. *
  433. * In this example, the instance of XMLHttpRequest runs in the zone and acts as a macroTask. The
  434. * output is 'task is scheduled macroTask, XMLHttpRequest.send, zone'.
  435. *
  436. * If you set `__Zone_disable_XHR = true` before importing `zone.js`,
  437. * `zone.js` does not monkey patch `XMLHttpRequest` APIs and the above onScheduleTask callback
  438. * will not be called.
  439. *
  440. */
  441. __Zone_disable_XHR?: boolean;
  442. /**
  443. * Disable the monkey patch of the browser geolocation APIs.
  444. *
  445. * By default, `zone.js` monkey patches geolocation APIs to make callbacks run in the same zone
  446. * when those APIs are called.
  447. *
  448. * Consider the following examples:
  449. *
  450. * ```
  451. * const zone = Zone.current.fork({
  452. * name: 'myZone'
  453. * });
  454. *
  455. * zone.run(() => {
  456. * navigator.geolocation.getCurrentPosition(pos => {
  457. * console.log('navigator.getCurrentPosition() callback is invoked in the zone',
  458. * Zone.current.name);
  459. * // output is 'navigator.getCurrentPosition() callback is invoked in the zone myZone'.
  460. * }
  461. * });
  462. * ```
  463. *
  464. * If set you `__Zone_disable_geolocation = true` before importing `zone.js`,
  465. * `zone.js` does not monkey patch geolocation APIs and the above code
  466. * outputs 'getCurrentPosition <root>'.
  467. *
  468. */
  469. __Zone_disable_geolocation?: boolean;
  470. /**
  471. * Disable the monkey patch of the browser `canvas` APIs.
  472. *
  473. * By default, `zone.js` monkey patches `canvas` APIs to make callbacks run in the same zone when
  474. * those APIs are called.
  475. *
  476. * Consider the following example:
  477. *
  478. * ```
  479. * const zone = Zone.current.fork({
  480. * name: 'myZone'
  481. * });
  482. *
  483. * zone.run(() => {
  484. * canvas.toBlob(blog => {
  485. * console.log('canvas.toBlob() callback is invoked in the zone', Zone.current.name);
  486. * // output is 'canvas.toBlob() callback is invoked in the zone myZone'.
  487. * }
  488. * });
  489. * ```
  490. *
  491. * If you set `__Zone_disable_canvas = true` before importing `zone.js`,
  492. * `zone.js` does not monkey patch `canvas` APIs and the above code
  493. * outputs 'canvas.toBlob <root>'.
  494. */
  495. __Zone_disable_canvas?: boolean;
  496. /**
  497. * Disable the `Promise` monkey patch.
  498. *
  499. * By default, `zone.js` monkey patches `Promise` APIs to make the `then()/catch()` callbacks in
  500. * the same zone when those callbacks are called.
  501. *
  502. * Consider the following examples:
  503. *
  504. * ```
  505. * const zone = Zone.current.fork({name: 'myZone'});
  506. *
  507. * const p = Promise.resolve(1);
  508. *
  509. * zone.run(() => {
  510. * p.then(() => {
  511. * console.log('then() callback is invoked in the zone', Zone.current.name);
  512. * // output is 'then() callback is invoked in the zone myZone'.
  513. * });
  514. * });
  515. * ```
  516. *
  517. * If you set `__Zone_disable_ZoneAwarePromise = true` before importing `zone.js`,
  518. * `zone.js` does not monkey patch `Promise` APIs and the above code
  519. * outputs 'promise then callback <root>'.
  520. */
  521. __Zone_disable_ZoneAwarePromise?: boolean;
  522. /**
  523. * Define event names that users don't want monkey patched by the `zone.js`.
  524. *
  525. * By default, `zone.js` monkey patches EventTarget.addEventListener(). The event listener
  526. * callback runs in the same zone when the addEventListener() is called.
  527. *
  528. * Sometimes, you don't want all of the event names used in this patched version because it
  529. * impacts performance. For example, you might want `scroll` or `mousemove` event listeners to run
  530. * the native `addEventListener()` for better performance.
  531. *
  532. * Users can achieve this goal by defining `__zone_symbol__UNPATCHED_EVENTS = ['scroll',
  533. * 'mousemove'];` before importing `zone.js`.
  534. */
  535. __zone_symbol__UNPATCHED_EVENTS?: string[];
  536. /**
  537. * Define the event names of the passive listeners.
  538. *
  539. * To add passive event listeners, you can use `elem.addEventListener('scroll', listener,
  540. * {passive: true});` or implement your own `EventManagerPlugin`.
  541. *
  542. * You can also define a global variable as follows:
  543. *
  544. * ```
  545. * __zone_symbol__PASSIVE_EVENTS = ['scroll'];
  546. * ```
  547. *
  548. * The preceding code makes all scroll event listeners passive.
  549. */
  550. __zone_symbol__PASSIVE_EVENTS?: string[];
  551. /**
  552. * Disable wrapping uncaught promise rejection.
  553. *
  554. * By default, `zone.js` wraps the uncaught promise rejection in a new `Error` object
  555. * which contains additional information such as a value of the rejection and a stack trace.
  556. *
  557. * If you set `__zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION = true;` before
  558. * importing `zone.js`, `zone.js` will not wrap the uncaught promise rejection.
  559. */
  560. __zone_symbol__DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION?: boolean;
  561. }
  562. /**
  563. * Interface of `zone-testing.js` test configurations.
  564. *
  565. * You can define the following configurations on the `window` or `global` object before
  566. * importing `zone-testing.js` to change `zone-testing.js` default behaviors in the test runner.
  567. */
  568. interface ZoneTestConfigurations {
  569. /**
  570. * Disable the Jasmine integration.
  571. *
  572. * In the `zone-testing.js` bundle, by default, `zone-testing.js` monkey patches Jasmine APIs
  573. * to make Jasmine APIs run in specified zone.
  574. *
  575. * 1. Make the `describe()`/`xdescribe()`/`fdescribe()` methods run in the syncTestZone.
  576. * 2. Make the `it()`/`xit()`/`fit()`/`beforeEach()`/`afterEach()`/`beforeAll()`/`afterAll()`
  577. * methods run in the ProxyZone.
  578. *
  579. * With this patch, `async()`/`fakeAsync()` can work with the Jasmine runner.
  580. *
  581. * If you set `__Zone_disable_jasmine = true` before importing `zone-testing.js`,
  582. * `zone-testing.js` does not monkey patch the jasmine APIs and the `async()`/`fakeAsync()` cannot
  583. * work with the Jasmine runner any longer.
  584. */
  585. __Zone_disable_jasmine?: boolean;
  586. /**
  587. * Disable the Mocha integration.
  588. *
  589. * In the `zone-testing.js` bundle, by default, `zone-testing.js` monkey patches the Mocha APIs
  590. * to make Mocha APIs run in the specified zone.
  591. *
  592. * 1. Make the `describe()`/`xdescribe()`/`fdescribe()` methods run in the syncTestZone.
  593. * 2. Make the `it()`/`xit()`/`fit()`/`beforeEach()`/`afterEach()`/`beforeAll()`/`afterAll()`
  594. * methods run in the ProxyZone.
  595. *
  596. * With this patch, `async()`/`fakeAsync()` can work with the Mocha runner.
  597. *
  598. * If you set `__Zone_disable_mocha = true` before importing `zone-testing.js`,
  599. * `zone-testing.js` does not monkey patch the Mocha APIs and the `async()/`fakeAsync()` can not
  600. * work with the Mocha runner any longer.
  601. */
  602. __Zone_disable_mocha?: boolean;
  603. /**
  604. * Disable the Jest integration.
  605. *
  606. * In the `zone-testing.js` bundle, by default, `zone-testing.js` monkey patches Jest APIs
  607. * to make Jest APIs run in the specified zone.
  608. *
  609. * 1. Make the `describe()`/`xdescribe()`/`fdescribe()` methods run in the syncTestZone.
  610. * 2. Make the `it()`/`xit()`/`fit()`/`beforeEach()`/`afterEach()`/`before()`/`after()` methods
  611. * run in the ProxyZone.
  612. *
  613. * With this patch, `async()`/`fakeAsync()` can work with the Jest runner.
  614. *
  615. * If you set `__Zone_disable_jest = true` before importing `zone-testing.js`,
  616. * `zone-testing.js` does not monkey patch the jest APIs and `async()`/`fakeAsync()` cannot
  617. * work with the Jest runner any longer.
  618. */
  619. __Zone_disable_jest?: boolean;
  620. /**
  621. * Disable monkey patch the jasmine clock APIs.
  622. *
  623. * By default, `zone-testing.js` monkey patches the `jasmine.clock()` API,
  624. * so the `jasmine.clock()` can work with the `fakeAsync()/tick()` API.
  625. *
  626. * Consider the following example:
  627. *
  628. * ```
  629. * describe('jasmine.clock integration', () => {
  630. * beforeEach(() => {
  631. * jasmine.clock().install();
  632. * });
  633. * afterEach(() => {
  634. * jasmine.clock().uninstall();
  635. * });
  636. * it('fakeAsync test', fakeAsync(() => {
  637. * setTimeout(spy, 100);
  638. * expect(spy).not.toHaveBeenCalled();
  639. * jasmine.clock().tick(100);
  640. * expect(spy).toHaveBeenCalled();
  641. * }));
  642. * });
  643. * ```
  644. *
  645. * In the `fakeAsync()` method, `jasmine.clock().tick()` works just like `tick()`.
  646. *
  647. * If you set `__zone_symbol__fakeAsyncDisablePatchingClock = true` before importing
  648. * `zone-testing.js`,`zone-testing.js` does not monkey patch the `jasmine.clock()` APIs and the
  649. * `jasmine.clock()` cannot work with `fakeAsync()` any longer.
  650. */
  651. __zone_symbol__fakeAsyncDisablePatchingClock?: boolean;
  652. /**
  653. * Enable auto running into `fakeAsync()` when installing the `jasmine.clock()`.
  654. *
  655. * By default, `zone-testing.js` does not automatically run into `fakeAsync()`
  656. * if the `jasmine.clock().install()` is called.
  657. *
  658. * Consider the following example:
  659. *
  660. * ```
  661. * describe('jasmine.clock integration', () => {
  662. * beforeEach(() => {
  663. * jasmine.clock().install();
  664. * });
  665. * afterEach(() => {
  666. * jasmine.clock().uninstall();
  667. * });
  668. * it('fakeAsync test', fakeAsync(() => {
  669. * setTimeout(spy, 100);
  670. * expect(spy).not.toHaveBeenCalled();
  671. * jasmine.clock().tick(100);
  672. * expect(spy).toHaveBeenCalled();
  673. * }));
  674. * });
  675. * ```
  676. *
  677. * You must run `fakeAsync()` to make test cases in the `FakeAsyncTestZone`.
  678. *
  679. * If you set `__zone_symbol__fakeAsyncAutoFakeAsyncWhenClockPatched = true` before importing
  680. * `zone-testing.js`, `zone-testing.js` can run test case automatically in the
  681. * `FakeAsyncTestZone` without calling the `fakeAsync()`.
  682. *
  683. * Consider the following example:
  684. *
  685. * ```
  686. * describe('jasmine.clock integration', () => {
  687. * beforeEach(() => {
  688. * jasmine.clock().install();
  689. * });
  690. * afterEach(() => {
  691. * jasmine.clock().uninstall();
  692. * });
  693. * it('fakeAsync test', () => { // here we don't need to call fakeAsync
  694. * setTimeout(spy, 100);
  695. * expect(spy).not.toHaveBeenCalled();
  696. * jasmine.clock().tick(100);
  697. * expect(spy).toHaveBeenCalled();
  698. * });
  699. * });
  700. * ```
  701. *
  702. */
  703. __zone_symbol__fakeAsyncAutoFakeAsyncWhenClockPatched?: boolean;
  704. /**
  705. * Enable waiting for the unresolved promise in the `async()` test.
  706. *
  707. * In the `async()` test, `AsyncTestZone` waits for all the asynchronous tasks to finish. By
  708. * default, if some promises remain unresolved, `AsyncTestZone` does not wait and reports that it
  709. * received an unexpected result.
  710. *
  711. * Consider the following example:
  712. *
  713. * ```
  714. * describe('wait never resolved promise', () => {
  715. * it('async with never resolved promise test', async(() => {
  716. * const p = new Promise(() => {});
  717. * p.then(() => {
  718. * // do some expectation.
  719. * });
  720. * }))
  721. * });
  722. * ```
  723. *
  724. * By default, this case passes, because the callback of `p.then()` is never called. Because `p`
  725. * is an unresolved promise, there is no pending asynchronous task, which means the `async()`
  726. * method does not wait.
  727. *
  728. * If you set `__zone_symbol__supportWaitUnResolvedChainedPromise = true`, the above case
  729. * times out, because `async()` will wait for the unresolved promise.
  730. */
  731. __zone_symbol__supportWaitUnResolvedChainedPromise?: boolean;
  732. }
  733. /**
  734. * The interface of the `zone.js` runtime configurations.
  735. *
  736. * These configurations can be defined on the `Zone` object after
  737. * importing zone.js to change behaviors. The differences between
  738. * the `ZoneRuntimeConfigurations` and the `ZoneGlobalConfigurations` are,
  739. *
  740. * 1. `ZoneGlobalConfigurations` must be defined on the `global/window` object before importing
  741. * `zone.js`. The value of the configuration cannot be changed at runtime.
  742. *
  743. * 2. `ZoneRuntimeConfigurations` must be defined on the `Zone` object after importing `zone.js`.
  744. * You can change the value of this configuration at runtime.
  745. *
  746. */
  747. interface ZoneRuntimeConfigurations {
  748. /**
  749. * Ignore outputting errors to the console when uncaught Promise errors occur.
  750. *
  751. * By default, if an uncaught Promise error occurs, `zone.js` outputs the
  752. * error to the console by calling `console.error()`.
  753. *
  754. * If you set `__zone_symbol__ignoreConsoleErrorUncaughtError = true`, `zone.js` does not output
  755. * the uncaught error to `console.error()`.
  756. */
  757. __zone_symbol__ignoreConsoleErrorUncaughtError?: boolean;
  758. }