selenium-webdriver 3.5.0 → 4.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/CHANGES.md +246 -0
  2. package/LICENSE +1 -1
  3. package/NOTICE +1 -1
  4. package/README.md +40 -40
  5. package/chrome.js +118 -134
  6. package/edge.js +43 -117
  7. package/example/chrome_android.js +8 -9
  8. package/example/chrome_mobile_emulation.js +8 -9
  9. package/example/firefox_channels.js +23 -19
  10. package/example/google_search.js +3 -3
  11. package/example/google_search_test.js +38 -27
  12. package/example/{chrome_headless.js → headless.js} +15 -7
  13. package/example/logging.js +40 -7
  14. package/firefox.js +789 -0
  15. package/http/index.js +62 -9
  16. package/http/util.js +11 -6
  17. package/ie.js +83 -97
  18. package/index.js +198 -114
  19. package/io/exec.js +29 -15
  20. package/io/index.js +1 -1
  21. package/io/zip.js +1 -1
  22. package/lib/actions.js +68 -63
  23. package/lib/atoms/get-attribute.js +86 -0
  24. package/lib/atoms/is-displayed.js +76 -76
  25. package/lib/by.js +7 -4
  26. package/lib/capabilities.js +310 -210
  27. package/lib/command.js +27 -51
  28. package/lib/error.js +100 -41
  29. package/lib/http.js +161 -120
  30. package/lib/input.js +1044 -8
  31. package/lib/logging.js +1 -5
  32. package/lib/promise.js +222 -3331
  33. package/lib/proxy.js +134 -39
  34. package/lib/session.js +2 -2
  35. package/lib/symbols.js +0 -0
  36. package/lib/until.js +1 -1
  37. package/lib/webdriver.js +717 -953
  38. package/net/index.js +21 -25
  39. package/net/portprober.js +51 -68
  40. package/package.json +17 -12
  41. package/proxy.js +0 -0
  42. package/remote/index.js +63 -44
  43. package/safari.js +41 -128
  44. package/testing/index.js +386 -315
  45. package/.npmignore +0 -2
  46. package/example/async_await_test.js +0 -68
  47. package/example/google_search_generator.js +0 -50
  48. package/example/parallel_flows.js +0 -54
  49. package/firefox/binary.js +0 -344
  50. package/firefox/extension.js +0 -224
  51. package/firefox/index.js +0 -626
  52. package/firefox/profile.js +0 -394
  53. package/lib/README +0 -5
  54. package/lib/atoms/getAttribute.js +0 -9
  55. package/lib/devmode.js +0 -34
  56. package/lib/events.js +0 -210
  57. package/lib/firefox/webdriver.json +0 -70
  58. package/lib/test/build.js +0 -151
  59. package/lib/test/data/ClickTest_testClicksASurroundingStrongTag.html +0 -11
  60. package/lib/test/data/Page.aspx +0 -17
  61. package/lib/test/data/Page.aspx.cs +0 -22
  62. package/lib/test/data/Redirect.aspx +0 -11
  63. package/lib/test/data/Redirect.aspx.cs +0 -9
  64. package/lib/test/data/Settings.StyleCop +0 -759
  65. package/lib/test/data/Web.Config +0 -59
  66. package/lib/test/data/actualXhtmlPage.xhtml +0 -14
  67. package/lib/test/data/ajaxy_page.html +0 -81
  68. package/lib/test/data/alerts.html +0 -85
  69. package/lib/test/data/banner.gif +0 -0
  70. package/lib/test/data/beach.jpg +0 -0
  71. package/lib/test/data/blank.html +0 -1
  72. package/lib/test/data/bodyTypingTest.html +0 -41
  73. package/lib/test/data/booleanAttributes.html +0 -19
  74. package/lib/test/data/child/childPage.html +0 -8
  75. package/lib/test/data/child/grandchild/grandchildPage.html +0 -8
  76. package/lib/test/data/clickEventPage.html +0 -26
  77. package/lib/test/data/click_frames.html +0 -10
  78. package/lib/test/data/click_jacker.html +0 -38
  79. package/lib/test/data/click_out_of_bounds.html +0 -23
  80. package/lib/test/data/click_out_of_bounds_overflow.html +0 -85
  81. package/lib/test/data/click_rtl.html +0 -19
  82. package/lib/test/data/click_source.html +0 -18
  83. package/lib/test/data/click_tests/click_iframe.html +0 -6
  84. package/lib/test/data/click_tests/click_in_iframe.html +0 -8
  85. package/lib/test/data/click_tests/disabled_element.html +0 -12
  86. package/lib/test/data/click_tests/disappearing_element.html +0 -62
  87. package/lib/test/data/click_tests/google_map.html +0 -15
  88. package/lib/test/data/click_tests/google_map.png +0 -0
  89. package/lib/test/data/click_tests/html5_submit_buttons.html +0 -16
  90. package/lib/test/data/click_tests/issue5237.html +0 -9
  91. package/lib/test/data/click_tests/issue5237_frame.html +0 -1
  92. package/lib/test/data/click_tests/issue5237_target.html +0 -10
  93. package/lib/test/data/click_tests/link_that_wraps.html +0 -11
  94. package/lib/test/data/click_tests/mapped_page1.html +0 -9
  95. package/lib/test/data/click_tests/mapped_page2.html +0 -9
  96. package/lib/test/data/click_tests/mapped_page3.html +0 -9
  97. package/lib/test/data/click_tests/overlapping_elements.html +0 -70
  98. package/lib/test/data/click_tests/partially_overlapping_elements.html +0 -124
  99. package/lib/test/data/click_tests/span_that_wraps.html +0 -11
  100. package/lib/test/data/click_tests/submitted_page.html +0 -9
  101. package/lib/test/data/click_tests/wrapped_overlapping_elements.html +0 -13
  102. package/lib/test/data/click_too_big.html +0 -10
  103. package/lib/test/data/click_too_big_in_frame.html +0 -11
  104. package/lib/test/data/clicks.html +0 -35
  105. package/lib/test/data/closeable_window.html +0 -8
  106. package/lib/test/data/cn-test.html +0 -156
  107. package/lib/test/data/colorPage.html +0 -20
  108. package/lib/test/data/cookies.html +0 -30
  109. package/lib/test/data/coordinates_tests/element_in_frame.html +0 -9
  110. package/lib/test/data/coordinates_tests/element_in_nested_frame.html +0 -9
  111. package/lib/test/data/coordinates_tests/page_with_element_out_of_view.html +0 -11
  112. package/lib/test/data/coordinates_tests/page_with_empty_element.html +0 -10
  113. package/lib/test/data/coordinates_tests/page_with_fixed_element.html +0 -12
  114. package/lib/test/data/coordinates_tests/page_with_hidden_element.html +0 -10
  115. package/lib/test/data/coordinates_tests/page_with_invisible_element.html +0 -10
  116. package/lib/test/data/coordinates_tests/page_with_transparent_element.html +0 -10
  117. package/lib/test/data/coordinates_tests/simple_page.html +0 -10
  118. package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  119. package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  120. package/lib/test/data/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  121. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  122. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  123. package/lib/test/data/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  124. package/lib/test/data/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  125. package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  126. package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  127. package/lib/test/data/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  128. package/lib/test/data/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  129. package/lib/test/data/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  130. package/lib/test/data/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  131. package/lib/test/data/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  132. package/lib/test/data/css/ui-lightness/jquery-ui-1.8.10.custom.css +0 -573
  133. package/lib/test/data/cssTransform.html +0 -61
  134. package/lib/test/data/cssTransform2.html +0 -20
  135. package/lib/test/data/document_write_in_onload.html +0 -13
  136. package/lib/test/data/dragAndDropInsideScrolledDiv.html +0 -67
  137. package/lib/test/data/dragAndDropTest.html +0 -102
  138. package/lib/test/data/dragDropOverflow.html +0 -104
  139. package/lib/test/data/draggableLists.html +0 -67
  140. package/lib/test/data/droppableItems.html +0 -65
  141. package/lib/test/data/dynamic.html +0 -39
  142. package/lib/test/data/dynamicallyModifiedPage.html +0 -42
  143. package/lib/test/data/errors.html +0 -15
  144. package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
  145. package/lib/test/data/firefox/sample.xpi +0 -0
  146. package/lib/test/data/firefox/webextension.xpi +0 -0
  147. package/lib/test/data/fixedFooterNoScroll.html +0 -13
  148. package/lib/test/data/fixedFooterNoScrollQuirksMode.html +0 -12
  149. package/lib/test/data/formPage.html +0 -175
  150. package/lib/test/data/formSelectionPage.html +0 -46
  151. package/lib/test/data/form_handling_js_submit.html +0 -30
  152. package/lib/test/data/framePage3.html +0 -7
  153. package/lib/test/data/frameScrollChild.html +0 -26
  154. package/lib/test/data/frameScrollPage.html +0 -14
  155. package/lib/test/data/frameScrollParent.html +0 -11
  156. package/lib/test/data/frameWithAnimals.html +0 -11
  157. package/lib/test/data/frame_switching_tests/bug4876.html +0 -9
  158. package/lib/test/data/frame_switching_tests/bug4876_iframe.html +0 -9
  159. package/lib/test/data/frame_switching_tests/deletingFrame.html +0 -29
  160. package/lib/test/data/frame_switching_tests/deletingFrame_iframe.html +0 -8
  161. package/lib/test/data/frame_switching_tests/deletingFrame_iframe2.html +0 -7
  162. package/lib/test/data/frameset.html +0 -14
  163. package/lib/test/data/framesetPage2.html +0 -7
  164. package/lib/test/data/framesetPage3.html +0 -4
  165. package/lib/test/data/globalscope.html +0 -15
  166. package/lib/test/data/hidden.html +0 -5
  167. package/lib/test/data/hidden_partially.html +0 -45
  168. package/lib/test/data/html5/blue.jpg +0 -0
  169. package/lib/test/data/html5/database.js +0 -84
  170. package/lib/test/data/html5/geolocation.js +0 -18
  171. package/lib/test/data/html5/green.jpg +0 -0
  172. package/lib/test/data/html5/red.jpg +0 -0
  173. package/lib/test/data/html5/status.html +0 -1
  174. package/lib/test/data/html5/test.appcache +0 -11
  175. package/lib/test/data/html5/yellow.jpg +0 -0
  176. package/lib/test/data/html5Page.html +0 -32
  177. package/lib/test/data/icon.gif +0 -0
  178. package/lib/test/data/idElements.html +0 -2
  179. package/lib/test/data/iframeAtBottom.html +0 -15
  180. package/lib/test/data/iframeWithAlert.html +0 -1
  181. package/lib/test/data/iframeWithIframe.html +0 -1
  182. package/lib/test/data/iframes.html +0 -11
  183. package/lib/test/data/injectableContent.html +0 -22
  184. package/lib/test/data/javascriptEnhancedForm.html +0 -30
  185. package/lib/test/data/javascriptPage.html +0 -285
  186. package/lib/test/data/jquery-1.3.2.js +0 -4376
  187. package/lib/test/data/js/jquery-1.4.4.min.js +0 -167
  188. package/lib/test/data/js/jquery-ui-1.8.10.custom.min.js +0 -782
  189. package/lib/test/data/js/skins/lightgray/content.inline.min.css +0 -1
  190. package/lib/test/data/js/skins/lightgray/content.min.css +0 -1
  191. package/lib/test/data/js/skins/lightgray/fonts/readme.md +0 -1
  192. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.dev.svg +0 -175
  193. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.eot +0 -0
  194. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.svg +0 -62
  195. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.ttf +0 -0
  196. package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.woff +0 -0
  197. package/lib/test/data/js/skins/lightgray/fonts/tinymce.dev.svg +0 -153
  198. package/lib/test/data/js/skins/lightgray/fonts/tinymce.eot +0 -0
  199. package/lib/test/data/js/skins/lightgray/fonts/tinymce.svg +0 -63
  200. package/lib/test/data/js/skins/lightgray/fonts/tinymce.ttf +0 -0
  201. package/lib/test/data/js/skins/lightgray/fonts/tinymce.woff +0 -0
  202. package/lib/test/data/js/skins/lightgray/img/anchor.gif +0 -0
  203. package/lib/test/data/js/skins/lightgray/img/loader.gif +0 -0
  204. package/lib/test/data/js/skins/lightgray/img/object.gif +0 -0
  205. package/lib/test/data/js/skins/lightgray/img/trans.gif +0 -0
  206. package/lib/test/data/js/skins/lightgray/skin.ie7.min.css +0 -1
  207. package/lib/test/data/js/skins/lightgray/skin.min.css +0 -1
  208. package/lib/test/data/js/themes/modern/theme.min.js +0 -1
  209. package/lib/test/data/js/tinymce.min.js +0 -10
  210. package/lib/test/data/key_logger.html +0 -34
  211. package/lib/test/data/key_tests/remove_on_keypress.html +0 -36
  212. package/lib/test/data/keyboard_shortcut.html +0 -36
  213. package/lib/test/data/linked_image.html +0 -16
  214. package/lib/test/data/locators_tests/boolean_attribute_selected.html +0 -13
  215. package/lib/test/data/locators_tests/boolean_attribute_selected_html4.html +0 -13
  216. package/lib/test/data/longContentPage.html +0 -55
  217. package/lib/test/data/macbeth.html +0 -5255
  218. package/lib/test/data/map.png +0 -0
  219. package/lib/test/data/map_visibility.html +0 -8
  220. package/lib/test/data/markerTransparent.png +0 -0
  221. package/lib/test/data/messages.html +0 -15
  222. package/lib/test/data/meta-redirect.html +0 -11
  223. package/lib/test/data/missedJsReference.html +0 -11
  224. package/lib/test/data/modal_dialogs/modal_1.html +0 -21
  225. package/lib/test/data/modal_dialogs/modal_2.html +0 -21
  226. package/lib/test/data/modal_dialogs/modal_3.html +0 -15
  227. package/lib/test/data/modal_dialogs/modalindex.html +0 -21
  228. package/lib/test/data/mouseOver.html +0 -17
  229. package/lib/test/data/mousePositionTracker.html +0 -33
  230. package/lib/test/data/nestedElements.html +0 -164
  231. package/lib/test/data/overflow/x_auto_y_auto.html +0 -30
  232. package/lib/test/data/overflow/x_auto_y_hidden.html +0 -30
  233. package/lib/test/data/overflow/x_auto_y_scroll.html +0 -30
  234. package/lib/test/data/overflow/x_hidden_y_auto.html +0 -30
  235. package/lib/test/data/overflow/x_hidden_y_hidden.html +0 -30
  236. package/lib/test/data/overflow/x_hidden_y_scroll.html +0 -30
  237. package/lib/test/data/overflow/x_scroll_y_auto.html +0 -30
  238. package/lib/test/data/overflow/x_scroll_y_hidden.html +0 -30
  239. package/lib/test/data/overflow/x_scroll_y_scroll.html +0 -30
  240. package/lib/test/data/overflow-body.html +0 -15
  241. package/lib/test/data/pageWithOnBeforeUnloadMessage.html +0 -20
  242. package/lib/test/data/pageWithOnLoad.html +0 -6
  243. package/lib/test/data/pageWithOnUnload.html +0 -6
  244. package/lib/test/data/page_with_link_to_slow_loading_page.html +0 -6
  245. package/lib/test/data/plain.txt +0 -1
  246. package/lib/test/data/proxy/page1.html +0 -20
  247. package/lib/test/data/proxy/page2.html +0 -24
  248. package/lib/test/data/proxy/page3.html +0 -5
  249. package/lib/test/data/readOnlyPage.html +0 -24
  250. package/lib/test/data/rectangles.html +0 -40
  251. package/lib/test/data/resultPage.html +0 -25
  252. package/lib/test/data/rich_text.html +0 -161
  253. package/lib/test/data/safari/frames_benchmark.html +0 -31
  254. package/lib/test/data/screen/screen.css +0 -19
  255. package/lib/test/data/screen/screen.html +0 -72
  256. package/lib/test/data/screen/screen.js +0 -7
  257. package/lib/test/data/screen/screen_frame1.html +0 -72
  258. package/lib/test/data/screen/screen_frame2.html +0 -72
  259. package/lib/test/data/screen/screen_frames.html +0 -11
  260. package/lib/test/data/screen/screen_iframes.html +0 -12
  261. package/lib/test/data/screen/screen_too_long.html +0 -68
  262. package/lib/test/data/screen/screen_x_long.html +0 -72
  263. package/lib/test/data/screen/screen_x_too_long.html +0 -72
  264. package/lib/test/data/screen/screen_y_long.html +0 -72
  265. package/lib/test/data/screen/screen_y_too_long.html +0 -72
  266. package/lib/test/data/scroll.html +0 -27
  267. package/lib/test/data/scroll2.html +0 -21
  268. package/lib/test/data/scroll3.html +0 -8
  269. package/lib/test/data/scroll4.html +0 -7
  270. package/lib/test/data/scroll5.html +0 -18
  271. package/lib/test/data/scrolling_tests/frame_with_height_above_200.html +0 -26
  272. package/lib/test/data/scrolling_tests/frame_with_height_above_2000.html +0 -26
  273. package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame.html +0 -11
  274. package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html +0 -12
  275. package/lib/test/data/scrolling_tests/frame_with_small_height.html +0 -10
  276. package/lib/test/data/scrolling_tests/page_with_double_overflow_auto.html +0 -19
  277. package/lib/test/data/scrolling_tests/page_with_frame_out_of_view.html +0 -12
  278. package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames.html +0 -11
  279. package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html +0 -12
  280. package/lib/test/data/scrolling_tests/page_with_non_scrolling_frame.html +0 -11
  281. package/lib/test/data/scrolling_tests/page_with_scrolling_frame.html +0 -11
  282. package/lib/test/data/scrolling_tests/page_with_scrolling_frame_out_of_view.html +0 -12
  283. package/lib/test/data/scrolling_tests/page_with_tall_frame.html +0 -11
  284. package/lib/test/data/scrolling_tests/page_with_y_overflow_auto.html +0 -14
  285. package/lib/test/data/scrolling_tests/target_page.html +0 -9
  286. package/lib/test/data/selectPage.html +0 -58
  287. package/lib/test/data/selectableItems.html +0 -65
  288. package/lib/test/data/sessionCookie.html +0 -21
  289. package/lib/test/data/sessionCookieDest.html +0 -34
  290. package/lib/test/data/simple.xml +0 -5
  291. package/lib/test/data/simpleTest.html +0 -98
  292. package/lib/test/data/single_text_input.html +0 -12
  293. package/lib/test/data/slowLoadingAlert.html +0 -10
  294. package/lib/test/data/slowLoadingResourcePage.html +0 -12
  295. package/lib/test/data/slow_loading_iframes.html +0 -14
  296. package/lib/test/data/styledPage.html +0 -28
  297. package/lib/test/data/svgPiechart.xhtml +0 -81
  298. package/lib/test/data/svgTest.svg +0 -4
  299. package/lib/test/data/tables.html +0 -36
  300. package/lib/test/data/tinymce.html +0 -10
  301. package/lib/test/data/transformable.xml +0 -11
  302. package/lib/test/data/transformable.xsl +0 -37
  303. package/lib/test/data/transparentUpload.html +0 -70
  304. package/lib/test/data/underscore.html +0 -9
  305. package/lib/test/data/unicode_ltr.html +0 -8
  306. package/lib/test/data/upload.html +0 -45
  307. package/lib/test/data/userDefinedProperty.html +0 -8
  308. package/lib/test/data/veryLargeCanvas.html +0 -81
  309. package/lib/test/data/visibility-css.html +0 -21
  310. package/lib/test/data/win32frameset.html +0 -8
  311. package/lib/test/data/window_switching_tests/page_with_frame.html +0 -12
  312. package/lib/test/data/window_switching_tests/simple_page.html +0 -9
  313. package/lib/test/data/xhtmlFormPage.xhtml +0 -17
  314. package/lib/test/data/xhtmlTest.html +0 -76
  315. package/lib/test/fileserver.js +0 -321
  316. package/lib/test/httpserver.js +0 -120
  317. package/lib/test/index.js +0 -270
  318. package/lib/test/promise.js +0 -79
  319. package/lib/test/resources.js +0 -44
  320. package/opera.js +0 -405
  321. package/phantomjs.js +0 -282
  322. package/test/actions_test.js +0 -52
  323. package/test/chrome/options_test.js +0 -227
  324. package/test/chrome/service_test.js +0 -45
  325. package/test/cookie_test.js +0 -214
  326. package/test/element_finding_test.js +0 -426
  327. package/test/execute_script_test.js +0 -350
  328. package/test/fingerprint_test.js +0 -62
  329. package/test/firefox/extension_test.js +0 -120
  330. package/test/firefox/firefox_test.js +0 -261
  331. package/test/firefox/profile_test.js +0 -140
  332. package/test/http/http_test.js +0 -223
  333. package/test/http/util_test.js +0 -178
  334. package/test/io/io_test.js +0 -360
  335. package/test/io/zip_test.js +0 -128
  336. package/test/lib/by_test.js +0 -160
  337. package/test/lib/capabilities_test.js +0 -111
  338. package/test/lib/error_test.js +0 -305
  339. package/test/lib/events_test.js +0 -177
  340. package/test/lib/http_test.js +0 -696
  341. package/test/lib/logging_test.js +0 -272
  342. package/test/lib/promise_aplus_test.js +0 -78
  343. package/test/lib/promise_error_test.js +0 -884
  344. package/test/lib/promise_flow_test.js +0 -2288
  345. package/test/lib/promise_generator_test.js +0 -310
  346. package/test/lib/promise_test.js +0 -1109
  347. package/test/lib/testutil.js +0 -90
  348. package/test/lib/until_test.js +0 -478
  349. package/test/lib/webdriver_test.js +0 -2311
  350. package/test/logging_test.js +0 -167
  351. package/test/net/index_test.js +0 -60
  352. package/test/net/portprober_test.js +0 -128
  353. package/test/page_loading_test.js +0 -166
  354. package/test/phantomjs/execute_phantomjs_test.js +0 -59
  355. package/test/proxy_test.js +0 -180
  356. package/test/rect_test.js +0 -60
  357. package/test/remote_test.js +0 -117
  358. package/test/safari_test.js +0 -108
  359. package/test/session_test.js +0 -99
  360. package/test/stale_element_test.js +0 -63
  361. package/test/tag_name_test.js +0 -36
  362. package/test/testing/assert_test.js +0 -373
  363. package/test/testing/index_test.js +0 -224
  364. package/test/upload_test.js +0 -86
  365. package/test/window_test.js +0 -161
  366. package/testing/assert.js +0 -378
@@ -1,884 +0,0 @@
1
- // Licensed to the Software Freedom Conservancy (SFC) under one
2
- // or more contributor license agreements. See the NOTICE file
3
- // distributed with this work for additional information
4
- // regarding copyright ownership. The SFC licenses this file
5
- // to you under the Apache License, Version 2.0 (the
6
- // "License"); you may not use this file except in compliance
7
- // with the License. You may obtain a copy of the License at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // Unless required by applicable law or agreed to in writing,
12
- // software distributed under the License is distributed on an
13
- // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- // KIND, either express or implied. See the License for the
15
- // specific language governing permissions and limitations
16
- // under the License.
17
-
18
- /**
19
- * @fileoverview Contains tests against promise error handling. Many tests use
20
- * NativePromise to control test termination independent of promise
21
- * (and notably promise.ControlFlow).
22
- */
23
-
24
- 'use strict';
25
-
26
- const testutil = require('./testutil');
27
-
28
- const assert = require('assert');
29
- const promise = require('../../lib/promise');
30
- const {enablePromiseManager} = require('../../lib/test/promise');
31
-
32
- const NativePromise = Promise;
33
- const StubError = testutil.StubError;
34
- const throwStubError = testutil.throwStubError;
35
- const assertIsStubError = testutil.assertIsStubError;
36
-
37
- describe('promise error handling', function() {
38
- enablePromiseManager(() => {
39
- var flow, uncaughtExceptions;
40
-
41
- beforeEach(function setUp() {
42
- if (promise.USE_PROMISE_MANAGER) {
43
- flow = promise.controlFlow();
44
- uncaughtExceptions = [];
45
- flow.on('uncaughtException', onUncaughtException);
46
- }
47
- });
48
-
49
- afterEach(function tearDown() {
50
- if (promise.USE_PROMISE_MANAGER) {
51
- return waitForIdle(flow).then(function() {
52
- assert.deepEqual(
53
- [], uncaughtExceptions, 'There were uncaught exceptions');
54
- flow.reset();
55
- });
56
- }
57
- });
58
-
59
- function onUncaughtException(e) {
60
- uncaughtExceptions.push(e);
61
- }
62
-
63
- function waitForAbort(opt_flow, opt_n) {
64
- var n = opt_n || 1;
65
- var theFlow = opt_flow || flow;
66
- theFlow.removeAllListeners(
67
- promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION);
68
- return new NativePromise(function(fulfill, reject) {
69
- theFlow.once('idle', function() {
70
- reject(Error('expected flow to report an unhandled error'));
71
- });
72
-
73
- var errors = [];
74
- theFlow.on('uncaughtException', onError);
75
- function onError(e) {
76
- errors.push(e);
77
- if (errors.length === n) {
78
- theFlow.removeListener('uncaughtException', onError);
79
- fulfill(n === 1 ? errors[0] : errors);
80
- }
81
- }
82
- });
83
- }
84
-
85
- function waitForIdle(opt_flow) {
86
- var theFlow = opt_flow || flow;
87
- return new NativePromise(function(fulfill, reject) {
88
- if (theFlow.isIdle()) {
89
- fulfill();
90
- return;
91
- }
92
- theFlow.once('idle', fulfill);
93
- theFlow.once('uncaughtException', reject);
94
- });
95
- }
96
-
97
- it('testRejectedPromiseTriggersErrorCallback', function() {
98
- return promise.rejected(new StubError).
99
- then(assert.fail, assertIsStubError);
100
- });
101
-
102
- describe('callback throws trigger subsequent error callback', function() {
103
- it('fulfilled promise', function() {
104
- return promise.fulfilled().
105
- then(throwStubError).
106
- then(assert.fail, assertIsStubError);
107
- });
108
-
109
- it('rejected promise', function() {
110
- var e = Error('not the droids you are looking for');
111
- return promise.rejected(e).
112
- then(assert.fail, throwStubError).
113
- then(assert.fail, assertIsStubError);
114
- });
115
- });
116
-
117
- describe('callback returns rejected promise triggers subsequent errback', function() {
118
- it('from fulfilled callback', function() {
119
- return promise.fulfilled().then(function() {
120
- return promise.rejected(new StubError);
121
- }).then(assert.fail, assertIsStubError);
122
- });
123
-
124
- it('from rejected callback', function() {
125
- var e = Error('not the droids you are looking for');
126
- return promise.rejected(e).
127
- then(assert.fail, function() {
128
- return promise.rejected(new StubError);
129
- }).
130
- then(assert.fail, assertIsStubError);
131
- });
132
- });
133
-
134
- it('testReportsUnhandledRejectionsThroughTheControlFlow', function() {
135
- promise.rejected(new StubError);
136
- return waitForAbort().then(assertIsStubError);
137
- });
138
-
139
- describe('multiple unhandled rejections outside a task', function() {
140
- it('are reported in order they occurred', function() {
141
- var e1 = Error('error 1');
142
- var e2 = Error('error 2');
143
-
144
- promise.rejected(e1);
145
- promise.rejected(e2);
146
-
147
- return waitForAbort(flow).then(function(error) {
148
- assert.ok(
149
- error instanceof promise.MultipleUnhandledRejectionError);
150
- // TODO: switch to Array.from when we drop node 0.12.x
151
- var errors = [];
152
- for (var e of error.errors) {
153
- errors.push(e);
154
- }
155
- assert.deepEqual([e1, e2], errors);
156
- });
157
- });
158
- });
159
-
160
- describe('does not report unhandled rejection when', function() {
161
- it('handler added before next tick', function() {
162
- promise.rejected(new StubError).then(assert.fail, assertIsStubError);
163
- return waitForIdle();
164
- });
165
-
166
- it('added async but before next tick', function() {
167
- var called = false;
168
- return new NativePromise(function(fulfill, reject) {
169
- var aPromise;
170
- NativePromise.resolve().then(function() {
171
- aPromise.then(assert.fail, function(e) {
172
- called = true;
173
- assertIsStubError(e);
174
- });
175
- waitForIdle().then(fulfill, reject);
176
- });
177
- aPromise = promise.rejected(new StubError);
178
- }).then(function() {
179
- assert.ok(called);
180
- })
181
- });
182
- });
183
-
184
- it('testTaskThrows', function() {
185
- return flow.execute(throwStubError).then(assert.fail, assertIsStubError);
186
- });
187
-
188
- it('testTaskReturnsRejectedPromise', function() {
189
- return flow.execute(function() {
190
- return promise.rejected(new StubError)
191
- }).then(assert.fail, assertIsStubError);
192
- });
193
-
194
- it('testTaskHasUnhandledRejection', function() {
195
- return flow.execute(function() {
196
- promise.rejected(new StubError)
197
- }).then(assert.fail, assertIsStubError);
198
- });
199
-
200
- it('testTaskfails_returnedPromiseIsUnhandled', function() {
201
- flow.execute(throwStubError);
202
- return waitForAbort().then(assertIsStubError);
203
- });
204
-
205
- it('testTaskHasUnhandledRejection_cancelsRemainingSubTasks', function() {
206
- var seen = [];
207
- flow.execute(function() {
208
- promise.rejected(new StubError);
209
-
210
- flow.execute(() => seen.push('a'))
211
- .then(() => seen.push('b'), (e) => seen.push(e));
212
- flow.execute(() => seen.push('c'))
213
- .then(() => seen.push('b'), (e) => seen.push(e));
214
- });
215
-
216
- return waitForAbort()
217
- .then(assertIsStubError)
218
- .then(() => assert.deepEqual([], seen));
219
- });
220
-
221
- describe('nested task failures', function() {
222
- it('returns up to paren', function() {
223
- return flow.execute(function() {
224
- return flow.execute(function() {
225
- return flow.execute(throwStubError);
226
- });
227
- }).then(assert.fail, assertIsStubError);
228
- });
229
-
230
- it('task throws; uncaught error bubbles up', function() {
231
- flow.execute(function() {
232
- flow.execute(function() {
233
- flow.execute(throwStubError);
234
- });
235
- });
236
- return waitForAbort().then(assertIsStubError);
237
- });
238
-
239
- it('task throws; uncaught error bubbles up; is caught at root', function() {
240
- flow.execute(function() {
241
- flow.execute(function() {
242
- flow.execute(throwStubError);
243
- });
244
- }).then(assert.fail, assertIsStubError);
245
- return waitForIdle();
246
- });
247
-
248
- it('unhandled rejection bubbles up', function() {
249
- flow.execute(function() {
250
- flow.execute(function() {
251
- flow.execute(function() {
252
- promise.rejected(new StubError);
253
- });
254
- });
255
- });
256
- return waitForAbort().then(assertIsStubError);
257
- });
258
-
259
- it('unhandled rejection bubbles up; caught at root', function() {
260
- flow.execute(function() {
261
- flow.execute(function() {
262
- promise.rejected(new StubError);
263
- });
264
- }).then(assert.fail, assertIsStubError);
265
- return waitForIdle();
266
- });
267
-
268
- it('mixtureof hanging and free subtasks', function() {
269
- flow.execute(function() {
270
- return flow.execute(function() {
271
- flow.execute(throwStubError);
272
- });
273
- });
274
- return waitForAbort().then(assertIsStubError);
275
- });
276
-
277
- it('cancels remaining tasks', function() {
278
- var seen = [];
279
- flow.execute(function() {
280
- flow.execute(() => promise.rejected(new StubError));
281
- flow.execute(() => seen.push('a'))
282
- .then(() => seen.push('b'), (e) => seen.push(e));
283
- flow.execute(() => seen.push('c'))
284
- .then(() => seen.push('b'), (e) => seen.push(e));
285
- });
286
-
287
- return waitForAbort()
288
- .then(assertIsStubError)
289
- .then(() => assert.deepEqual([], seen));
290
- });
291
- });
292
-
293
- it('testTaskReturnsPromiseLikeObjectThatInvokesErrback', function() {
294
- return flow.execute(function() {
295
- return {
296
- 'then': function(_, errback) {
297
- errback('abc123');
298
- }
299
- };
300
- }).then(assert.fail, function(value) {
301
- assert.equal('abc123', value);
302
- });
303
- });
304
-
305
- describe('ControlFlow#wait();', function() {
306
- describe('condition throws;', function() {
307
- it('failure is caught', function() {
308
- return flow.wait(throwStubError, 50).then(assert.fail, assertIsStubError);
309
- });
310
-
311
- it('failure is not caught', function() {
312
- flow.wait(throwStubError, 50);
313
- return waitForAbort().then(assertIsStubError);
314
- });
315
- });
316
-
317
- describe('condition returns promise', function() {
318
- it('failure is caught', function() {
319
- return flow.wait(function() {
320
- return promise.rejected(new StubError);
321
- }, 50).then(assert.fail, assertIsStubError);
322
- });
323
-
324
- it('failure is not caught', function() {
325
- flow.wait(function() {
326
- return promise.rejected(new StubError);
327
- }, 50);
328
- return waitForAbort().then(assertIsStubError);
329
- });
330
- });
331
-
332
- describe('condition has unhandled promise rejection', function() {
333
- it('failure is caught', function() {
334
- return flow.wait(function() {
335
- promise.rejected(new StubError);
336
- }, 50).then(assert.fail, assertIsStubError);
337
- });
338
-
339
- it('failure is not caught', function() {
340
- flow.wait(function() {
341
- promise.rejected(new StubError);
342
- }, 50);
343
- return waitForAbort().then(assertIsStubError);
344
- });
345
- });
346
-
347
- describe('condition has subtask failure', function() {
348
- it('failure is caught', function() {
349
- return flow.wait(function() {
350
- flow.execute(function() {
351
- flow.execute(throwStubError);
352
- });
353
- }, 50).then(assert.fail, assertIsStubError);
354
- });
355
-
356
- it('failure is not caught', function() {
357
- flow.wait(function() {
358
- flow.execute(function() {
359
- flow.execute(throwStubError);
360
- });
361
- }, 50);
362
- return waitForAbort().then(assertIsStubError);
363
- });
364
- });
365
- });
366
-
367
- describe('errback throws a new error', function() {
368
- it('start with normal promise', function() {
369
- var error = Error('an error');
370
- return promise.rejected(error).
371
- catch(function(e) {
372
- assert.equal(e, error);
373
- throw new StubError;
374
- }).
375
- catch(assertIsStubError);
376
- });
377
-
378
- it('start with task result', function() {
379
- var error = Error('an error');
380
- return flow.execute(function() {
381
- throw error;
382
- }).
383
- catch(function(e) {
384
- assert.equal(e, error);
385
- throw new StubError;
386
- }).
387
- catch(assertIsStubError);
388
- });
389
-
390
- it('start with normal promise; uncaught error', function() {
391
- var error = Error('an error');
392
- promise.rejected(error).
393
- catch(function(e) {
394
- assert.equal(e, error);
395
- throw new StubError;
396
- });
397
- return waitForAbort().then(assertIsStubError);
398
- });
399
-
400
- it('start with task result; uncaught error', function() {
401
- var error = Error('an error');
402
- flow.execute(function() {
403
- throw error;
404
- }).
405
- catch(function(e) {
406
- assert.equal(e, error);
407
- throw new StubError;
408
- });
409
- return waitForAbort().then(assertIsStubError);
410
- });
411
- });
412
-
413
- it('thrownPromiseCausesCallbackRejection', function() {
414
- let p = promise.fulfilled(1234);
415
- return promise.fulfilled().then(function() {
416
- throw p;
417
- }).then(assert.fail, function(value) {
418
- assert.strictEqual(p, value);
419
- });
420
- });
421
-
422
- describe('task throws promise', function() {
423
- it('promise was fulfilled', function() {
424
- var toThrow = promise.fulfilled(1234);
425
- flow.execute(function() {
426
- throw toThrow;
427
- }).then(assert.fail, function(value) {
428
- assert.equal(toThrow, value);
429
- return toThrow;
430
- }).then(function(value) {
431
- assert.equal(1234, value);
432
- });
433
- return waitForIdle();
434
- });
435
-
436
- it('promise was rejected', function() {
437
- var toThrow = promise.rejected(new StubError);
438
- toThrow.catch(function() {}); // For tearDown.
439
- flow.execute(function() {
440
- throw toThrow;
441
- }).then(assert.fail, function(e) {
442
- assert.equal(toThrow, e);
443
- return e;
444
- }).then(assert.fail, assertIsStubError);
445
- return waitForIdle();
446
- });
447
- });
448
-
449
- it('testFailsTaskIfThereIsAnUnhandledErrorWhileWaitingOnTaskResult', function() {
450
- var d = promise.defer();
451
- flow.execute(function() {
452
- promise.rejected(new StubError);
453
- return d.promise;
454
- }).then(assert.fail, assertIsStubError);
455
-
456
- return waitForIdle().then(function() {
457
- return d.promise;
458
- }).then(assert.fail, function(e) {
459
- assert.equal('CancellationError: StubError', e.toString());
460
- });
461
- });
462
-
463
- it('testFailsParentTaskIfAsyncScheduledTaskFails', function() {
464
- var d = promise.defer();
465
- flow.execute(function() {
466
- flow.execute(throwStubError);
467
- return d.promise;
468
- }).then(assert.fail, assertIsStubError);
469
-
470
- return waitForIdle().then(function() {
471
- return d.promise;
472
- }).then(assert.fail, function(e) {
473
- assert.equal('CancellationError: StubError', e.toString());
474
- });
475
- });
476
-
477
- describe('long stack traces', function() {
478
- afterEach(() => promise.LONG_STACK_TRACES = false);
479
-
480
- it('always includes task stacks in failures', function() {
481
- promise.LONG_STACK_TRACES = false;
482
- flow.execute(function() {
483
- flow.execute(function() {
484
- flow.execute(throwStubError, 'throw error');
485
- }, 'two');
486
- }, 'three').
487
- then(assert.fail, function(e) {
488
- assertIsStubError(e);
489
- if (typeof e.stack !== 'string') {
490
- return;
491
- }
492
- var messages = e.stack.split(/\n/).filter(function(line, index) {
493
- return /^From: /.test(line);
494
- });
495
- assert.deepEqual([
496
- 'From: Task: throw error',
497
- 'From: Task: two',
498
- 'From: Task: three'
499
- ], messages);
500
- });
501
- return waitForIdle();
502
- });
503
-
504
- it('does not include completed tasks', function () {
505
- flow.execute(function() {}, 'succeeds');
506
- flow.execute(throwStubError, 'kaboom').then(assert.fail, function(e) {
507
- assertIsStubError(e);
508
- if (typeof e.stack !== 'string') {
509
- return;
510
- }
511
- var messages = e.stack.split(/\n/).filter(function(line, index) {
512
- return /^From: /.test(line);
513
- });
514
- assert.deepEqual(['From: Task: kaboom'], messages);
515
- });
516
- return waitForIdle();
517
- });
518
-
519
- it('does not include promise chain when disabled', function() {
520
- promise.LONG_STACK_TRACES = false;
521
- flow.execute(function() {
522
- flow.execute(function() {
523
- return promise.fulfilled().
524
- then(function() {}).
525
- then(function() {}).
526
- then(throwStubError);
527
- }, 'eventually assert.fails');
528
- }, 'start').
529
- then(assert.fail, function(e) {
530
- assertIsStubError(e);
531
- if (typeof e.stack !== 'string') {
532
- return;
533
- }
534
- var messages = e.stack.split(/\n/).filter(function(line, index) {
535
- return /^From: /.test(line);
536
- });
537
- assert.deepEqual([
538
- 'From: Task: eventually assert.fails',
539
- 'From: Task: start'
540
- ], messages);
541
- });
542
- return waitForIdle();
543
- });
544
-
545
- it('includes promise chain when enabled', function() {
546
- promise.LONG_STACK_TRACES = true;
547
- flow.execute(function() {
548
- flow.execute(function() {
549
- return promise.fulfilled().
550
- then(function() {}).
551
- then(function() {}).
552
- then(throwStubError);
553
- }, 'eventually assert.fails');
554
- }, 'start').
555
- then(assert.fail, function(e) {
556
- assertIsStubError(e);
557
- if (typeof e.stack !== 'string') {
558
- return;
559
- }
560
- var messages = e.stack.split(/\n/).filter(function(line, index) {
561
- return /^From: /.test(line);
562
- });
563
- assert.deepEqual([
564
- 'From: Promise: then',
565
- 'From: Task: eventually assert.fails',
566
- 'From: Task: start'
567
- ], messages);
568
- });
569
- return waitForIdle();
570
- });
571
- });
572
-
573
- describe('frame cancels remaining tasks', function() {
574
- it('on unhandled task failure', function() {
575
- var run = false;
576
- return flow.execute(function() {
577
- flow.execute(throwStubError);
578
- flow.execute(function() { run = true; });
579
- }).then(assert.fail, function(e) {
580
- assertIsStubError(e);
581
- assert.ok(!run);
582
- });
583
- });
584
-
585
- it('on unhandled promise rejection', function() {
586
- var run = false;
587
- return flow.execute(function() {
588
- promise.rejected(new StubError);
589
- flow.execute(function() { run = true; });
590
- }).then(assert.fail, function(e) {
591
- assertIsStubError(e);
592
- assert.ok(!run);
593
- });
594
- });
595
-
596
- it('if task throws', function() {
597
- var run = false;
598
- return flow.execute(function() {
599
- flow.execute(function() { run = true; });
600
- throw new StubError;
601
- }).then(assert.fail, function(e) {
602
- assertIsStubError(e);
603
- assert.ok(!run);
604
- });
605
- });
606
-
607
- describe('task callbacks scheduled in another frame', function() {
608
- flow = promise.controlFlow();
609
- function noop() {}
610
-
611
- let subTask;
612
-
613
- before(function() {
614
- flow.execute(function() {
615
- // This task will be discarded and never run because of the error below.
616
- subTask = flow.execute(() => 'abc');
617
- throw new StubError('stub');
618
- }).catch(noop);
619
- });
620
-
621
- function assertCancellation(e) {
622
- assert.ok(e instanceof promise.CancellationError);
623
- assert.equal(
624
- 'Task was discarded due to a previous failure: stub', e.message);
625
- }
626
-
627
- it('are rejected with cancellation error', function() {
628
- let result;
629
- return Promise.resolve().then(function() {
630
- return flow.execute(function() {
631
- result = subTask.then(assert.fail);
632
- });
633
- })
634
- .then(() => result)
635
- .then(assert.fail, assertCancellation);
636
- });
637
-
638
- it('cancellation errors propagate through callbacks (1)', function() {
639
- let result;
640
- return Promise.resolve().then(function() {
641
- return flow.execute(function() {
642
- result = subTask
643
- .then(assert.fail, assertCancellation)
644
- .then(() => 'abc123');
645
- });
646
- })
647
- .then(() => result)
648
- .then(value => assert.equal('abc123', value));
649
- });
650
-
651
- it('cancellation errors propagate through callbacks (2)', function() {
652
- let result;
653
- return Promise.resolve().then(function() {
654
- return flow.execute(function() {
655
- result = subTask.then(assert.fail)
656
- .then(noop, assertCancellation)
657
- .then(() => 'fin');
658
- });
659
- })
660
- // Verify result actually computed successfully all the way through.
661
- .then(() => result)
662
- .then(value => assert.equal('fin', value));
663
- });
664
- });
665
- });
666
-
667
- it('testRegisteredTaskCallbacksAreDroppedWhenTaskIsCancelled_return', function() {
668
- var seen = [];
669
- return flow.execute(function() {
670
- flow.execute(throwStubError);
671
-
672
- flow.execute(function() {
673
- seen.push(1);
674
- }).then(function() {
675
- seen.push(2);
676
- }, function() {
677
- seen.push(3);
678
- });
679
- }).then(assert.fail, function(e) {
680
- assertIsStubError(e);
681
- assert.deepEqual([], seen);
682
- });
683
- });
684
-
685
- it('testRegisteredTaskCallbacksAreDroppedWhenTaskIsCancelled_withReturn', function() {
686
- var seen = [];
687
- return flow.execute(function() {
688
- flow.execute(throwStubError);
689
-
690
- return flow.execute(function() {
691
- seen.push(1);
692
- }).then(function() {
693
- seen.push(2);
694
- }, function() {
695
- seen.push(3);
696
- });
697
- }).then(assert.fail, function(e) {
698
- assertIsStubError(e);
699
- assert.deepEqual([], seen);
700
- });
701
- });
702
-
703
- it('testTasksWithinACallbackAreDroppedIfContainingTaskIsAborted', function() {
704
- var seen = [];
705
- return flow.execute(function() {
706
- flow.execute(throwStubError);
707
-
708
- // None of the callbacks on this promise should execute because the
709
- // task assert.failure above is never handled, causing the containing task to
710
- // abort.
711
- promise.fulfilled().then(function() {
712
- seen.push(1);
713
- return flow.execute(function() {
714
- seen.push(2);
715
- });
716
- }).finally(function() {
717
- seen.push(3);
718
- });
719
-
720
- }).then(assert.fail, function(e) {
721
- assertIsStubError(e);
722
- assert.deepEqual([], seen);
723
- });
724
- });
725
-
726
- it('testTaskIsCancelledAfterWaitTimeout', function() {
727
- var seen = [];
728
- return flow.execute(function() {
729
- flow.wait(function() {
730
- return promise.delayed(50);
731
- }, 5);
732
-
733
- return flow.execute(function() {
734
- seen.push(1);
735
- }).then(function() {
736
- seen.push(2);
737
- }, function() {
738
- seen.push(3);
739
- });
740
- }).then(assert.fail, function() {
741
- assert.deepEqual([], seen);
742
- });
743
- });
744
-
745
- describe('task callbacks get cancellation error if registered after task was cancelled', function() {
746
- it('(a)', function() {
747
- var task;
748
- flow.execute(function() {
749
- flow.execute(throwStubError);
750
- task = flow.execute(function() {});
751
- }).then(assert.fail, assertIsStubError);
752
- return waitForIdle().then(function() {
753
- return task.then(assert.fail, function(e) {
754
- assert.ok(e instanceof promise.CancellationError);
755
- });
756
- });
757
- });
758
-
759
- it('(b)', function() {
760
- var seen = [];
761
-
762
- var task;
763
- flow.execute(function() {
764
- flow.execute(throwStubError);
765
- task = flow.execute(function() {});
766
-
767
- task.then(() => seen.push(1))
768
- .then(() => seen.push(2));
769
- task.then(() => seen.push(3))
770
- .then(() => seen.push(4));
771
-
772
- }).then(assert.fail, assertIsStubError);
773
-
774
- return waitForIdle().then(function() {
775
- return task.then(assert.fail, function(e) {
776
- seen.push(5);
777
- assert.ok(e instanceof promise.CancellationError);
778
- });
779
- }).then(() => assert.deepEqual([5], seen));
780
- });
781
- });
782
-
783
- it('unhandledRejectionInParallelTaskQueue', function() {
784
- var seen = [];
785
- function schedule(name) {
786
- return flow.execute(() => seen.push(name), name);
787
- }
788
-
789
- flow.async(function() {
790
- schedule('a.1');
791
- flow.execute(throwStubError, 'a.2 (throws)');
792
- });
793
-
794
- var b3;
795
- flow.async(function() {
796
- schedule('b.1');
797
- schedule('b.2');
798
- b3 = schedule('b.3');
799
- });
800
-
801
- var c3;
802
- flow.async(function() {
803
- schedule('c.1');
804
- schedule('c.2');
805
- c3 = schedule('c.3');
806
- });
807
-
808
- function assertWasCancelled(p) {
809
- return p.then(assert.fail, function(e) {
810
- assert.ok(e instanceof promise.CancellationError);
811
- });
812
- }
813
-
814
- return waitForAbort()
815
- .then(function() {
816
- assert.deepEqual(['a.1', 'b.1', 'c.1', 'b.2', 'c.2'], seen);
817
- })
818
- .then(() => assertWasCancelled(b3))
819
- .then(() => assertWasCancelled(c3));
820
- });
821
-
822
- it('errorsInAsyncFunctionsAreReportedAsUnhandledRejection', function() {
823
- flow.removeAllListeners(); // For tearDown.
824
-
825
- var task;
826
- return new Promise(function(fulfill) {
827
- flow.once('uncaughtException', fulfill);
828
- flow.async(function() {
829
- task = flow.execute(function() {});
830
- throw Error('boom');
831
- });
832
- }).then(function(error) {
833
- assert.ok(error instanceof promise.CancellationError);
834
- return task.catch(function(error) {
835
- assert.ok(error instanceof promise.CancellationError);
836
- });
837
- });
838
- });
839
-
840
- describe('does not wait for values thrown from callbacks to be resolved', function() {
841
- it('(a)', function() {
842
- var p1 = promise.fulfilled();
843
- var reason = promise.fulfilled('should not see me');
844
- return p1.then(function() {
845
- throw reason;
846
- }).then(assert.fail, function(e) {
847
- assert.equal(reason, e);
848
- });
849
- });
850
-
851
- it('(b)', function() {
852
- var p1 = promise.fulfilled();
853
- var reason = promise.rejected('should not see me');
854
- reason.catch(function() {}); // For tearDown.
855
- return p1.then(function() {
856
- throw reason;
857
- }).then(assert.fail, function(e) {
858
- assert.equal(reason, e);
859
- });
860
- });
861
-
862
- it('(c)', function() {
863
- var p1 = promise.fulfilled();
864
- var reason = promise.defer();
865
- setTimeout(() => reason.fulfill('should not see me'), 100);
866
- return p1.then(function() {
867
- throw reason.promise;
868
- }).then(assert.fail, function(e) {
869
- assert.equal(reason.promise, e);
870
- });
871
- });
872
-
873
- it('(d)', function() {
874
- var p1 = promise.fulfilled();
875
- var reason = {then: function() {}}; // A thenable like object.
876
- return p1.then(function() {
877
- throw reason;
878
- }).then(assert.fail, function(e) {
879
- assert.equal(reason, e);
880
- });
881
- });
882
- });
883
- });
884
- });