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.
- package/CHANGES.md +246 -0
- package/LICENSE +1 -1
- package/NOTICE +1 -1
- package/README.md +40 -40
- package/chrome.js +118 -134
- package/edge.js +43 -117
- package/example/chrome_android.js +8 -9
- package/example/chrome_mobile_emulation.js +8 -9
- package/example/firefox_channels.js +23 -19
- package/example/google_search.js +3 -3
- package/example/google_search_test.js +38 -27
- package/example/{chrome_headless.js → headless.js} +15 -7
- package/example/logging.js +40 -7
- package/firefox.js +789 -0
- package/http/index.js +62 -9
- package/http/util.js +11 -6
- package/ie.js +83 -97
- package/index.js +198 -114
- package/io/exec.js +29 -15
- package/io/index.js +1 -1
- package/io/zip.js +1 -1
- package/lib/actions.js +68 -63
- package/lib/atoms/get-attribute.js +86 -0
- package/lib/atoms/is-displayed.js +76 -76
- package/lib/by.js +7 -4
- package/lib/capabilities.js +310 -210
- package/lib/command.js +27 -51
- package/lib/error.js +100 -41
- package/lib/http.js +161 -120
- package/lib/input.js +1044 -8
- package/lib/logging.js +1 -5
- package/lib/promise.js +222 -3331
- package/lib/proxy.js +134 -39
- package/lib/session.js +2 -2
- package/lib/symbols.js +0 -0
- package/lib/until.js +1 -1
- package/lib/webdriver.js +717 -953
- package/net/index.js +21 -25
- package/net/portprober.js +51 -68
- package/package.json +17 -12
- package/proxy.js +0 -0
- package/remote/index.js +63 -44
- package/safari.js +41 -128
- package/testing/index.js +386 -315
- package/.npmignore +0 -2
- package/example/async_await_test.js +0 -68
- package/example/google_search_generator.js +0 -50
- package/example/parallel_flows.js +0 -54
- package/firefox/binary.js +0 -344
- package/firefox/extension.js +0 -224
- package/firefox/index.js +0 -626
- package/firefox/profile.js +0 -394
- package/lib/README +0 -5
- package/lib/atoms/getAttribute.js +0 -9
- package/lib/devmode.js +0 -34
- package/lib/events.js +0 -210
- package/lib/firefox/webdriver.json +0 -70
- package/lib/test/build.js +0 -151
- package/lib/test/data/ClickTest_testClicksASurroundingStrongTag.html +0 -11
- package/lib/test/data/Page.aspx +0 -17
- package/lib/test/data/Page.aspx.cs +0 -22
- package/lib/test/data/Redirect.aspx +0 -11
- package/lib/test/data/Redirect.aspx.cs +0 -9
- package/lib/test/data/Settings.StyleCop +0 -759
- package/lib/test/data/Web.Config +0 -59
- package/lib/test/data/actualXhtmlPage.xhtml +0 -14
- package/lib/test/data/ajaxy_page.html +0 -81
- package/lib/test/data/alerts.html +0 -85
- package/lib/test/data/banner.gif +0 -0
- package/lib/test/data/beach.jpg +0 -0
- package/lib/test/data/blank.html +0 -1
- package/lib/test/data/bodyTypingTest.html +0 -41
- package/lib/test/data/booleanAttributes.html +0 -19
- package/lib/test/data/child/childPage.html +0 -8
- package/lib/test/data/child/grandchild/grandchildPage.html +0 -8
- package/lib/test/data/clickEventPage.html +0 -26
- package/lib/test/data/click_frames.html +0 -10
- package/lib/test/data/click_jacker.html +0 -38
- package/lib/test/data/click_out_of_bounds.html +0 -23
- package/lib/test/data/click_out_of_bounds_overflow.html +0 -85
- package/lib/test/data/click_rtl.html +0 -19
- package/lib/test/data/click_source.html +0 -18
- package/lib/test/data/click_tests/click_iframe.html +0 -6
- package/lib/test/data/click_tests/click_in_iframe.html +0 -8
- package/lib/test/data/click_tests/disabled_element.html +0 -12
- package/lib/test/data/click_tests/disappearing_element.html +0 -62
- package/lib/test/data/click_tests/google_map.html +0 -15
- package/lib/test/data/click_tests/google_map.png +0 -0
- package/lib/test/data/click_tests/html5_submit_buttons.html +0 -16
- package/lib/test/data/click_tests/issue5237.html +0 -9
- package/lib/test/data/click_tests/issue5237_frame.html +0 -1
- package/lib/test/data/click_tests/issue5237_target.html +0 -10
- package/lib/test/data/click_tests/link_that_wraps.html +0 -11
- package/lib/test/data/click_tests/mapped_page1.html +0 -9
- package/lib/test/data/click_tests/mapped_page2.html +0 -9
- package/lib/test/data/click_tests/mapped_page3.html +0 -9
- package/lib/test/data/click_tests/overlapping_elements.html +0 -70
- package/lib/test/data/click_tests/partially_overlapping_elements.html +0 -124
- package/lib/test/data/click_tests/span_that_wraps.html +0 -11
- package/lib/test/data/click_tests/submitted_page.html +0 -9
- package/lib/test/data/click_tests/wrapped_overlapping_elements.html +0 -13
- package/lib/test/data/click_too_big.html +0 -10
- package/lib/test/data/click_too_big_in_frame.html +0 -11
- package/lib/test/data/clicks.html +0 -35
- package/lib/test/data/closeable_window.html +0 -8
- package/lib/test/data/cn-test.html +0 -156
- package/lib/test/data/colorPage.html +0 -20
- package/lib/test/data/cookies.html +0 -30
- package/lib/test/data/coordinates_tests/element_in_frame.html +0 -9
- package/lib/test/data/coordinates_tests/element_in_nested_frame.html +0 -9
- package/lib/test/data/coordinates_tests/page_with_element_out_of_view.html +0 -11
- package/lib/test/data/coordinates_tests/page_with_empty_element.html +0 -10
- package/lib/test/data/coordinates_tests/page_with_fixed_element.html +0 -12
- package/lib/test/data/coordinates_tests/page_with_hidden_element.html +0 -10
- package/lib/test/data/coordinates_tests/page_with_invisible_element.html +0 -10
- package/lib/test/data/coordinates_tests/page_with_transparent_element.html +0 -10
- package/lib/test/data/coordinates_tests/simple_page.html +0 -10
- package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
- package/lib/test/data/css/ui-lightness/jquery-ui-1.8.10.custom.css +0 -573
- package/lib/test/data/cssTransform.html +0 -61
- package/lib/test/data/cssTransform2.html +0 -20
- package/lib/test/data/document_write_in_onload.html +0 -13
- package/lib/test/data/dragAndDropInsideScrolledDiv.html +0 -67
- package/lib/test/data/dragAndDropTest.html +0 -102
- package/lib/test/data/dragDropOverflow.html +0 -104
- package/lib/test/data/draggableLists.html +0 -67
- package/lib/test/data/droppableItems.html +0 -65
- package/lib/test/data/dynamic.html +0 -39
- package/lib/test/data/dynamicallyModifiedPage.html +0 -42
- package/lib/test/data/errors.html +0 -15
- package/lib/test/data/firefox/jetpack-sample.xpi +0 -0
- package/lib/test/data/firefox/sample.xpi +0 -0
- package/lib/test/data/firefox/webextension.xpi +0 -0
- package/lib/test/data/fixedFooterNoScroll.html +0 -13
- package/lib/test/data/fixedFooterNoScrollQuirksMode.html +0 -12
- package/lib/test/data/formPage.html +0 -175
- package/lib/test/data/formSelectionPage.html +0 -46
- package/lib/test/data/form_handling_js_submit.html +0 -30
- package/lib/test/data/framePage3.html +0 -7
- package/lib/test/data/frameScrollChild.html +0 -26
- package/lib/test/data/frameScrollPage.html +0 -14
- package/lib/test/data/frameScrollParent.html +0 -11
- package/lib/test/data/frameWithAnimals.html +0 -11
- package/lib/test/data/frame_switching_tests/bug4876.html +0 -9
- package/lib/test/data/frame_switching_tests/bug4876_iframe.html +0 -9
- package/lib/test/data/frame_switching_tests/deletingFrame.html +0 -29
- package/lib/test/data/frame_switching_tests/deletingFrame_iframe.html +0 -8
- package/lib/test/data/frame_switching_tests/deletingFrame_iframe2.html +0 -7
- package/lib/test/data/frameset.html +0 -14
- package/lib/test/data/framesetPage2.html +0 -7
- package/lib/test/data/framesetPage3.html +0 -4
- package/lib/test/data/globalscope.html +0 -15
- package/lib/test/data/hidden.html +0 -5
- package/lib/test/data/hidden_partially.html +0 -45
- package/lib/test/data/html5/blue.jpg +0 -0
- package/lib/test/data/html5/database.js +0 -84
- package/lib/test/data/html5/geolocation.js +0 -18
- package/lib/test/data/html5/green.jpg +0 -0
- package/lib/test/data/html5/red.jpg +0 -0
- package/lib/test/data/html5/status.html +0 -1
- package/lib/test/data/html5/test.appcache +0 -11
- package/lib/test/data/html5/yellow.jpg +0 -0
- package/lib/test/data/html5Page.html +0 -32
- package/lib/test/data/icon.gif +0 -0
- package/lib/test/data/idElements.html +0 -2
- package/lib/test/data/iframeAtBottom.html +0 -15
- package/lib/test/data/iframeWithAlert.html +0 -1
- package/lib/test/data/iframeWithIframe.html +0 -1
- package/lib/test/data/iframes.html +0 -11
- package/lib/test/data/injectableContent.html +0 -22
- package/lib/test/data/javascriptEnhancedForm.html +0 -30
- package/lib/test/data/javascriptPage.html +0 -285
- package/lib/test/data/jquery-1.3.2.js +0 -4376
- package/lib/test/data/js/jquery-1.4.4.min.js +0 -167
- package/lib/test/data/js/jquery-ui-1.8.10.custom.min.js +0 -782
- package/lib/test/data/js/skins/lightgray/content.inline.min.css +0 -1
- package/lib/test/data/js/skins/lightgray/content.min.css +0 -1
- package/lib/test/data/js/skins/lightgray/fonts/readme.md +0 -1
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.dev.svg +0 -175
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.eot +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.svg +0 -62
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.ttf +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce-small.woff +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.dev.svg +0 -153
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.eot +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.svg +0 -63
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.ttf +0 -0
- package/lib/test/data/js/skins/lightgray/fonts/tinymce.woff +0 -0
- package/lib/test/data/js/skins/lightgray/img/anchor.gif +0 -0
- package/lib/test/data/js/skins/lightgray/img/loader.gif +0 -0
- package/lib/test/data/js/skins/lightgray/img/object.gif +0 -0
- package/lib/test/data/js/skins/lightgray/img/trans.gif +0 -0
- package/lib/test/data/js/skins/lightgray/skin.ie7.min.css +0 -1
- package/lib/test/data/js/skins/lightgray/skin.min.css +0 -1
- package/lib/test/data/js/themes/modern/theme.min.js +0 -1
- package/lib/test/data/js/tinymce.min.js +0 -10
- package/lib/test/data/key_logger.html +0 -34
- package/lib/test/data/key_tests/remove_on_keypress.html +0 -36
- package/lib/test/data/keyboard_shortcut.html +0 -36
- package/lib/test/data/linked_image.html +0 -16
- package/lib/test/data/locators_tests/boolean_attribute_selected.html +0 -13
- package/lib/test/data/locators_tests/boolean_attribute_selected_html4.html +0 -13
- package/lib/test/data/longContentPage.html +0 -55
- package/lib/test/data/macbeth.html +0 -5255
- package/lib/test/data/map.png +0 -0
- package/lib/test/data/map_visibility.html +0 -8
- package/lib/test/data/markerTransparent.png +0 -0
- package/lib/test/data/messages.html +0 -15
- package/lib/test/data/meta-redirect.html +0 -11
- package/lib/test/data/missedJsReference.html +0 -11
- package/lib/test/data/modal_dialogs/modal_1.html +0 -21
- package/lib/test/data/modal_dialogs/modal_2.html +0 -21
- package/lib/test/data/modal_dialogs/modal_3.html +0 -15
- package/lib/test/data/modal_dialogs/modalindex.html +0 -21
- package/lib/test/data/mouseOver.html +0 -17
- package/lib/test/data/mousePositionTracker.html +0 -33
- package/lib/test/data/nestedElements.html +0 -164
- package/lib/test/data/overflow/x_auto_y_auto.html +0 -30
- package/lib/test/data/overflow/x_auto_y_hidden.html +0 -30
- package/lib/test/data/overflow/x_auto_y_scroll.html +0 -30
- package/lib/test/data/overflow/x_hidden_y_auto.html +0 -30
- package/lib/test/data/overflow/x_hidden_y_hidden.html +0 -30
- package/lib/test/data/overflow/x_hidden_y_scroll.html +0 -30
- package/lib/test/data/overflow/x_scroll_y_auto.html +0 -30
- package/lib/test/data/overflow/x_scroll_y_hidden.html +0 -30
- package/lib/test/data/overflow/x_scroll_y_scroll.html +0 -30
- package/lib/test/data/overflow-body.html +0 -15
- package/lib/test/data/pageWithOnBeforeUnloadMessage.html +0 -20
- package/lib/test/data/pageWithOnLoad.html +0 -6
- package/lib/test/data/pageWithOnUnload.html +0 -6
- package/lib/test/data/page_with_link_to_slow_loading_page.html +0 -6
- package/lib/test/data/plain.txt +0 -1
- package/lib/test/data/proxy/page1.html +0 -20
- package/lib/test/data/proxy/page2.html +0 -24
- package/lib/test/data/proxy/page3.html +0 -5
- package/lib/test/data/readOnlyPage.html +0 -24
- package/lib/test/data/rectangles.html +0 -40
- package/lib/test/data/resultPage.html +0 -25
- package/lib/test/data/rich_text.html +0 -161
- package/lib/test/data/safari/frames_benchmark.html +0 -31
- package/lib/test/data/screen/screen.css +0 -19
- package/lib/test/data/screen/screen.html +0 -72
- package/lib/test/data/screen/screen.js +0 -7
- package/lib/test/data/screen/screen_frame1.html +0 -72
- package/lib/test/data/screen/screen_frame2.html +0 -72
- package/lib/test/data/screen/screen_frames.html +0 -11
- package/lib/test/data/screen/screen_iframes.html +0 -12
- package/lib/test/data/screen/screen_too_long.html +0 -68
- package/lib/test/data/screen/screen_x_long.html +0 -72
- package/lib/test/data/screen/screen_x_too_long.html +0 -72
- package/lib/test/data/screen/screen_y_long.html +0 -72
- package/lib/test/data/screen/screen_y_too_long.html +0 -72
- package/lib/test/data/scroll.html +0 -27
- package/lib/test/data/scroll2.html +0 -21
- package/lib/test/data/scroll3.html +0 -8
- package/lib/test/data/scroll4.html +0 -7
- package/lib/test/data/scroll5.html +0 -18
- package/lib/test/data/scrolling_tests/frame_with_height_above_200.html +0 -26
- package/lib/test/data/scrolling_tests/frame_with_height_above_2000.html +0 -26
- package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame.html +0 -11
- package/lib/test/data/scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/frame_with_small_height.html +0 -10
- package/lib/test/data/scrolling_tests/page_with_double_overflow_auto.html +0 -19
- package/lib/test/data/scrolling_tests/page_with_frame_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_nested_scrolling_frames_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/page_with_non_scrolling_frame.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_scrolling_frame.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_scrolling_frame_out_of_view.html +0 -12
- package/lib/test/data/scrolling_tests/page_with_tall_frame.html +0 -11
- package/lib/test/data/scrolling_tests/page_with_y_overflow_auto.html +0 -14
- package/lib/test/data/scrolling_tests/target_page.html +0 -9
- package/lib/test/data/selectPage.html +0 -58
- package/lib/test/data/selectableItems.html +0 -65
- package/lib/test/data/sessionCookie.html +0 -21
- package/lib/test/data/sessionCookieDest.html +0 -34
- package/lib/test/data/simple.xml +0 -5
- package/lib/test/data/simpleTest.html +0 -98
- package/lib/test/data/single_text_input.html +0 -12
- package/lib/test/data/slowLoadingAlert.html +0 -10
- package/lib/test/data/slowLoadingResourcePage.html +0 -12
- package/lib/test/data/slow_loading_iframes.html +0 -14
- package/lib/test/data/styledPage.html +0 -28
- package/lib/test/data/svgPiechart.xhtml +0 -81
- package/lib/test/data/svgTest.svg +0 -4
- package/lib/test/data/tables.html +0 -36
- package/lib/test/data/tinymce.html +0 -10
- package/lib/test/data/transformable.xml +0 -11
- package/lib/test/data/transformable.xsl +0 -37
- package/lib/test/data/transparentUpload.html +0 -70
- package/lib/test/data/underscore.html +0 -9
- package/lib/test/data/unicode_ltr.html +0 -8
- package/lib/test/data/upload.html +0 -45
- package/lib/test/data/userDefinedProperty.html +0 -8
- package/lib/test/data/veryLargeCanvas.html +0 -81
- package/lib/test/data/visibility-css.html +0 -21
- package/lib/test/data/win32frameset.html +0 -8
- package/lib/test/data/window_switching_tests/page_with_frame.html +0 -12
- package/lib/test/data/window_switching_tests/simple_page.html +0 -9
- package/lib/test/data/xhtmlFormPage.xhtml +0 -17
- package/lib/test/data/xhtmlTest.html +0 -76
- package/lib/test/fileserver.js +0 -321
- package/lib/test/httpserver.js +0 -120
- package/lib/test/index.js +0 -270
- package/lib/test/promise.js +0 -79
- package/lib/test/resources.js +0 -44
- package/opera.js +0 -405
- package/phantomjs.js +0 -282
- package/test/actions_test.js +0 -52
- package/test/chrome/options_test.js +0 -227
- package/test/chrome/service_test.js +0 -45
- package/test/cookie_test.js +0 -214
- package/test/element_finding_test.js +0 -426
- package/test/execute_script_test.js +0 -350
- package/test/fingerprint_test.js +0 -62
- package/test/firefox/extension_test.js +0 -120
- package/test/firefox/firefox_test.js +0 -261
- package/test/firefox/profile_test.js +0 -140
- package/test/http/http_test.js +0 -223
- package/test/http/util_test.js +0 -178
- package/test/io/io_test.js +0 -360
- package/test/io/zip_test.js +0 -128
- package/test/lib/by_test.js +0 -160
- package/test/lib/capabilities_test.js +0 -111
- package/test/lib/error_test.js +0 -305
- package/test/lib/events_test.js +0 -177
- package/test/lib/http_test.js +0 -696
- package/test/lib/logging_test.js +0 -272
- package/test/lib/promise_aplus_test.js +0 -78
- package/test/lib/promise_error_test.js +0 -884
- package/test/lib/promise_flow_test.js +0 -2288
- package/test/lib/promise_generator_test.js +0 -310
- package/test/lib/promise_test.js +0 -1109
- package/test/lib/testutil.js +0 -90
- package/test/lib/until_test.js +0 -478
- package/test/lib/webdriver_test.js +0 -2311
- package/test/logging_test.js +0 -167
- package/test/net/index_test.js +0 -60
- package/test/net/portprober_test.js +0 -128
- package/test/page_loading_test.js +0 -166
- package/test/phantomjs/execute_phantomjs_test.js +0 -59
- package/test/proxy_test.js +0 -180
- package/test/rect_test.js +0 -60
- package/test/remote_test.js +0 -117
- package/test/safari_test.js +0 -108
- package/test/session_test.js +0 -99
- package/test/stale_element_test.js +0 -63
- package/test/tag_name_test.js +0 -36
- package/test/testing/assert_test.js +0 -373
- package/test/testing/index_test.js +0 -224
- package/test/upload_test.js +0 -86
- package/test/window_test.js +0 -161
- package/testing/assert.js +0 -378
package/test/lib/promise_test.js
DELETED
|
@@ -1,1109 +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
|
-
'use strict';
|
|
19
|
-
|
|
20
|
-
const assert = require('assert');
|
|
21
|
-
|
|
22
|
-
const testutil = require('./testutil');
|
|
23
|
-
const promise = require('../../lib/promise');
|
|
24
|
-
const {enablePromiseManager, promiseManagerSuite} = require('../../lib/test/promise');
|
|
25
|
-
|
|
26
|
-
// Aliases for readability.
|
|
27
|
-
const NativePromise = Promise;
|
|
28
|
-
const StubError = testutil.StubError;
|
|
29
|
-
const assertIsStubError = testutil.assertIsStubError;
|
|
30
|
-
const callbackHelper = testutil.callbackHelper;
|
|
31
|
-
const callbackPair = testutil.callbackPair;
|
|
32
|
-
const throwStubError = testutil.throwStubError;
|
|
33
|
-
const fail = () => assert.fail();
|
|
34
|
-
|
|
35
|
-
// Refer to promise_aplus_test for promise compliance with standard behavior.
|
|
36
|
-
describe('promise', function() {
|
|
37
|
-
var app, uncaughtExceptions;
|
|
38
|
-
|
|
39
|
-
beforeEach(function setUp() {
|
|
40
|
-
if (promise.USE_PROMISE_MANAGER) {
|
|
41
|
-
promise.LONG_STACK_TRACES = false;
|
|
42
|
-
uncaughtExceptions = [];
|
|
43
|
-
|
|
44
|
-
app = promise.controlFlow();
|
|
45
|
-
app.on(promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION,
|
|
46
|
-
(e) => uncaughtExceptions.push(e));
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
afterEach(function tearDown() {
|
|
51
|
-
if (promise.USE_PROMISE_MANAGER) {
|
|
52
|
-
app.reset();
|
|
53
|
-
promise.setDefaultFlow(new promise.ControlFlow);
|
|
54
|
-
assert.deepEqual([], uncaughtExceptions,
|
|
55
|
-
'Did not expect any uncaught exceptions');
|
|
56
|
-
promise.LONG_STACK_TRACES = false;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const assertIsPromise = (p) => assert.ok(promise.isPromise(p));
|
|
61
|
-
const assertNotPromise = (v) => assert.ok(!promise.isPromise(v));
|
|
62
|
-
|
|
63
|
-
function defer() {
|
|
64
|
-
let d = {};
|
|
65
|
-
let promise = new Promise((resolve, reject) => {
|
|
66
|
-
Object.assign(d, {resolve, reject});
|
|
67
|
-
});
|
|
68
|
-
d.promise = promise;
|
|
69
|
-
return d;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function createRejectedPromise(reason) {
|
|
73
|
-
var p = Promise.reject(reason);
|
|
74
|
-
p.catch(function() {}); // Silence unhandled rejection handlers.
|
|
75
|
-
return p;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
enablePromiseManager(() => {
|
|
79
|
-
it('testCanDetectPromiseLikeObjects', function() {
|
|
80
|
-
assertIsPromise(new promise.Promise(function(fulfill) {
|
|
81
|
-
fulfill();
|
|
82
|
-
}));
|
|
83
|
-
assertIsPromise(new promise.Deferred().promise);
|
|
84
|
-
assertIsPromise(Promise.resolve(123));
|
|
85
|
-
assertIsPromise({then:function() {}});
|
|
86
|
-
|
|
87
|
-
assertNotPromise(new promise.Deferred());
|
|
88
|
-
assertNotPromise(undefined);
|
|
89
|
-
assertNotPromise(null);
|
|
90
|
-
assertNotPromise('');
|
|
91
|
-
assertNotPromise(true);
|
|
92
|
-
assertNotPromise(false);
|
|
93
|
-
assertNotPromise(1);
|
|
94
|
-
assertNotPromise({});
|
|
95
|
-
assertNotPromise({then:1});
|
|
96
|
-
assertNotPromise({then:true});
|
|
97
|
-
assertNotPromise({then:''});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('then', function() {
|
|
101
|
-
it('returnsOwnPromiseIfNoCallbacksWereGiven', function() {
|
|
102
|
-
var deferred = new promise.Deferred();
|
|
103
|
-
assert.equal(deferred.promise, deferred.promise.then());
|
|
104
|
-
assert.equal(deferred.promise, deferred.promise.catch());
|
|
105
|
-
assert.equal(deferred.promise, promise.when(deferred.promise));
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('stillConsideredUnHandledIfNoCallbacksWereGivenOnCallsToThen', function() {
|
|
109
|
-
promise.rejected(new StubError).then();
|
|
110
|
-
var handler = callbackHelper(assertIsStubError);
|
|
111
|
-
|
|
112
|
-
// so tearDown() doesn't throw
|
|
113
|
-
app.removeAllListeners();
|
|
114
|
-
app.on(promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION, handler);
|
|
115
|
-
return NativePromise.resolve()
|
|
116
|
-
// Macro yield so the uncaught exception has a chance to trigger.
|
|
117
|
-
.then(() => new NativePromise(resolve => setTimeout(resolve, 0)))
|
|
118
|
-
.then(() => handler.assertCalled());
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe('finally', function() {
|
|
123
|
-
it('nonFailingCallbackDoesNotSuppressOriginalError', function() {
|
|
124
|
-
var done = callbackHelper(assertIsStubError);
|
|
125
|
-
return promise.rejected(new StubError).
|
|
126
|
-
finally(function() {}).
|
|
127
|
-
catch(done).
|
|
128
|
-
finally(done.assertCalled);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('failingCallbackSuppressesOriginalError', function() {
|
|
132
|
-
var done = callbackHelper(assertIsStubError);
|
|
133
|
-
return promise.rejected(new Error('original')).
|
|
134
|
-
finally(throwStubError).
|
|
135
|
-
catch(done).
|
|
136
|
-
finally(done.assertCalled);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('callbackThrowsAfterFulfilledPromise', function() {
|
|
140
|
-
var done = callbackHelper(assertIsStubError);
|
|
141
|
-
return promise.fulfilled().
|
|
142
|
-
finally(throwStubError).
|
|
143
|
-
catch(done).
|
|
144
|
-
finally(done.assertCalled);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('callbackReturnsRejectedPromise', function() {
|
|
148
|
-
var done = callbackHelper(assertIsStubError);
|
|
149
|
-
return promise.fulfilled().
|
|
150
|
-
finally(function() {
|
|
151
|
-
return promise.rejected(new StubError);
|
|
152
|
-
}).
|
|
153
|
-
catch(done).
|
|
154
|
-
finally(done.assertCalled);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('cancel', function() {
|
|
159
|
-
it('passesTheCancellationReasonToReject', function() {
|
|
160
|
-
var d = new promise.Deferred();
|
|
161
|
-
var res = d.promise.then(assert.fail, function(e) {
|
|
162
|
-
assert.ok(e instanceof promise.CancellationError);
|
|
163
|
-
assert.equal('because i said so', e.message);
|
|
164
|
-
});
|
|
165
|
-
d.promise.cancel('because i said so');
|
|
166
|
-
return res;
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('can cancel original promise from its child;', function() {
|
|
170
|
-
it('child created by then()', function() {
|
|
171
|
-
var d = new promise.Deferred();
|
|
172
|
-
var p = d.promise.then(assert.fail, function(e) {
|
|
173
|
-
assert.ok(e instanceof promise.CancellationError);
|
|
174
|
-
assert.equal('because i said so', e.message);
|
|
175
|
-
return 123;
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
p.cancel('because i said so');
|
|
179
|
-
return p.then(v => assert.equal(123, v));
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('child linked by resolving with parent', function() {
|
|
183
|
-
let parent = promise.defer();
|
|
184
|
-
let child = new promise.Promise(resolve => resolve(parent.promise));
|
|
185
|
-
child.cancel('all done');
|
|
186
|
-
|
|
187
|
-
return parent.promise.then(
|
|
188
|
-
() => assert.fail('expected a cancellation'),
|
|
189
|
-
e => {
|
|
190
|
-
assert.ok(e instanceof promise.CancellationError);
|
|
191
|
-
assert.equal('all done', e.message);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('grand child through thenable chain', function() {
|
|
196
|
-
let p = new promise.Promise(function() {/* never resolve*/});
|
|
197
|
-
|
|
198
|
-
let noop = function() {};
|
|
199
|
-
let gc = p.then(noop).then(noop).then(noop);
|
|
200
|
-
gc.cancel('stop!');
|
|
201
|
-
|
|
202
|
-
return p.then(
|
|
203
|
-
() => assert.fail('expected to be cancelled'),
|
|
204
|
-
(e) => {
|
|
205
|
-
assert.ok(e instanceof promise.CancellationError);
|
|
206
|
-
assert.equal('stop!', e.message);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it('grand child through thenable chain started at resolve', function() {
|
|
211
|
-
function noop() {}
|
|
212
|
-
|
|
213
|
-
let parent = promise.defer();
|
|
214
|
-
let child = new promise.Promise(resolve => resolve(parent.promise));
|
|
215
|
-
let grandChild = child.then(noop).then(noop).then(noop);
|
|
216
|
-
grandChild.cancel('all done');
|
|
217
|
-
|
|
218
|
-
return parent.promise.then(
|
|
219
|
-
() => assert.fail('expected a cancellation'),
|
|
220
|
-
e => {
|
|
221
|
-
assert.ok(e instanceof promise.CancellationError);
|
|
222
|
-
assert.equal('all done', e.message);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('"parent" is a CancellableThenable', function() {
|
|
227
|
-
function noop() {}
|
|
228
|
-
|
|
229
|
-
class FakeThenable {
|
|
230
|
-
constructor(p) {
|
|
231
|
-
this.promise = p;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
cancel(reason) {
|
|
235
|
-
this.promise.cancel(reason);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
then(cb, eb) {
|
|
239
|
-
let result = this.promise.then(cb, eb);
|
|
240
|
-
return new FakeThenable(result);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
promise.CancellableThenable.addImplementation(FakeThenable);
|
|
244
|
-
|
|
245
|
-
let root = new promise.Promise(noop);
|
|
246
|
-
let thenable = new FakeThenable(root);
|
|
247
|
-
assert.ok(promise.Thenable.isImplementation(thenable));
|
|
248
|
-
assert.ok(promise.CancellableThenable.isImplementation(thenable));
|
|
249
|
-
|
|
250
|
-
let child = new promise.Promise(resolve => resolve(thenable));
|
|
251
|
-
assert.ok(child instanceof promise.Promise);
|
|
252
|
-
child.cancel('stop!');
|
|
253
|
-
|
|
254
|
-
function assertStopped(p) {
|
|
255
|
-
return p.then(
|
|
256
|
-
() => assert.fail('not stopped!'),
|
|
257
|
-
(e) => {
|
|
258
|
-
assert.ok(e instanceof promise.CancellationError);
|
|
259
|
-
assert.equal('stop!', e.message);
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return assertStopped(child).then(() => assertStopped(root));
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('canCancelATimeout', function() {
|
|
268
|
-
var p = promise.delayed(25)
|
|
269
|
-
.then(assert.fail, (e) => e instanceof promise.CancellationError);
|
|
270
|
-
setTimeout(() => p.cancel(), 20);
|
|
271
|
-
p.cancel();
|
|
272
|
-
return p;
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it('can cancel timeout from grandchild', function() {
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('cancelIsANoopOnceAPromiseHasBeenFulfilled', function() {
|
|
279
|
-
var p = promise.fulfilled(123);
|
|
280
|
-
p.cancel();
|
|
281
|
-
return p.then((v) => assert.equal(123, v));
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it('cancelIsANoopOnceAPromiseHasBeenRejected', function() {
|
|
285
|
-
var p = promise.rejected(new StubError);
|
|
286
|
-
p.cancel();
|
|
287
|
-
|
|
288
|
-
var pair = callbackPair(null, assertIsStubError);
|
|
289
|
-
return p.then(assert.fail, assertIsStubError);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('noopCancelTriggeredOnCallbackOfResolvedPromise', function() {
|
|
293
|
-
var d = promise.defer();
|
|
294
|
-
var p = d.promise.then();
|
|
295
|
-
|
|
296
|
-
d.fulfill();
|
|
297
|
-
p.cancel(); // This should not throw.
|
|
298
|
-
return p; // This should not trigger a failure.
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
promiseManagerSuite(() => {
|
|
304
|
-
describe('fulfilled', function() {
|
|
305
|
-
it('returns input value if it is already a valid promise', function() {
|
|
306
|
-
let p = promise.createPromise(function() {});
|
|
307
|
-
let r = promise.fulfilled(p);
|
|
308
|
-
assert.strictEqual(p, r);
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('creates a new promise fulfilled with input', function() {
|
|
312
|
-
return promise.fulfilled(1234).then(v => assert.equal(1234, v));
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('can convert thenables to valid promise', function() {
|
|
316
|
-
let thenable = {then: function(cb) {cb(1234)}};
|
|
317
|
-
let p = promise.fulfilled(thenable);
|
|
318
|
-
assert.notStrictEqual(thenable, p);
|
|
319
|
-
return p.then(v => assert.equal(1234, v));
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
describe('when', function() {
|
|
324
|
-
it('ReturnsAResolvedPromiseIfGivenANonPromiseValue', function() {
|
|
325
|
-
var ret = promise.when('abc');
|
|
326
|
-
assertIsPromise(ret);
|
|
327
|
-
return ret.then((value) => assert.equal('abc', value));
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
it('PassesRawErrorsToCallbacks', function() {
|
|
331
|
-
var error = new Error('boo!');
|
|
332
|
-
return promise.when(error, function(value) {
|
|
333
|
-
assert.equal(error, value);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('WaitsForValueToBeResolvedBeforeInvokingCallback', function() {
|
|
338
|
-
let d = defer();
|
|
339
|
-
let callback;
|
|
340
|
-
let result = promise.when(d.promise, callback = callbackHelper(function(value) {
|
|
341
|
-
assert.equal('hi', value);
|
|
342
|
-
}));
|
|
343
|
-
callback.assertNotCalled();
|
|
344
|
-
d.resolve('hi');
|
|
345
|
-
return result.then(callback.assertCalled);
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
describe('fullyResolved', function() {
|
|
350
|
-
it('primitives', function() {
|
|
351
|
-
function runTest(value) {
|
|
352
|
-
var callback, errback;
|
|
353
|
-
return promise.fullyResolved(value)
|
|
354
|
-
.then((resolved) => assert.equal(value, resolved));
|
|
355
|
-
}
|
|
356
|
-
return runTest(true)
|
|
357
|
-
.then(() => runTest(function() {}))
|
|
358
|
-
.then(() => runTest(null))
|
|
359
|
-
.then(() => runTest(123))
|
|
360
|
-
.then(() => runTest('foo bar'))
|
|
361
|
-
.then(() => runTest(undefined));
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it('arrayOfPrimitives', function() {
|
|
365
|
-
var fn = function() {};
|
|
366
|
-
var array = [true, fn, null, 123, '', undefined, 1];
|
|
367
|
-
return promise.fullyResolved(array).then(function(resolved) {
|
|
368
|
-
assert.equal(array, resolved);
|
|
369
|
-
assert.deepEqual([true, fn, null, 123, '', undefined, 1],
|
|
370
|
-
resolved);
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
it('nestedArrayOfPrimitives', function() {
|
|
375
|
-
var fn = function() {};
|
|
376
|
-
var array = [true, [fn, null, 123], '', undefined];
|
|
377
|
-
return promise.fullyResolved(array)
|
|
378
|
-
.then(function(resolved) {
|
|
379
|
-
assert.equal(array, resolved);
|
|
380
|
-
assert.deepEqual([true, [fn, null, 123], '', undefined], resolved);
|
|
381
|
-
assert.deepEqual([fn, null, 123], resolved[1]);
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
it('arrayWithPromisedPrimitive', function() {
|
|
386
|
-
return promise.fullyResolved([Promise.resolve(123)])
|
|
387
|
-
.then(function(resolved) {
|
|
388
|
-
assert.deepEqual([123], resolved);
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it('promiseResolvesToPrimitive', function() {
|
|
393
|
-
return promise.fullyResolved(Promise.resolve(123))
|
|
394
|
-
.then((resolved) => assert.equal(123, resolved));
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it('promiseResolvesToArray', function() {
|
|
398
|
-
var fn = function() {};
|
|
399
|
-
var array = [true, [fn, null, 123], '', undefined];
|
|
400
|
-
var aPromise = Promise.resolve(array);
|
|
401
|
-
|
|
402
|
-
var result = promise.fullyResolved(aPromise);
|
|
403
|
-
return result.then(function(resolved) {
|
|
404
|
-
assert.equal(array, resolved);
|
|
405
|
-
assert.deepEqual([true, [fn, null, 123], '', undefined],
|
|
406
|
-
resolved);
|
|
407
|
-
assert.deepEqual([fn, null, 123], resolved[1]);
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
it('promiseResolvesToArrayWithPromises', function() {
|
|
412
|
-
var nestedPromise = Promise.resolve(123);
|
|
413
|
-
var aPromise = Promise.resolve([true, nestedPromise]);
|
|
414
|
-
return promise.fullyResolved(aPromise)
|
|
415
|
-
.then(function(resolved) {
|
|
416
|
-
assert.deepEqual([true, 123], resolved);
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
it('rejectsIfArrayPromiseRejects', function() {
|
|
421
|
-
var nestedPromise = createRejectedPromise(new StubError);
|
|
422
|
-
var aPromise = Promise.resolve([true, nestedPromise]);
|
|
423
|
-
|
|
424
|
-
var pair = callbackPair(null, assertIsStubError);
|
|
425
|
-
return promise.fullyResolved(aPromise)
|
|
426
|
-
.then(assert.fail, assertIsStubError);
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
it('rejectsOnFirstArrayRejection', function() {
|
|
430
|
-
var e1 = new Error('foo');
|
|
431
|
-
var e2 = new Error('bar');
|
|
432
|
-
var aPromise = Promise.resolve([
|
|
433
|
-
createRejectedPromise(e1),
|
|
434
|
-
createRejectedPromise(e2)
|
|
435
|
-
]);
|
|
436
|
-
|
|
437
|
-
return promise.fullyResolved(aPromise)
|
|
438
|
-
.then(assert.fail, function(error) {
|
|
439
|
-
assert.strictEqual(e1, error);
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
it('rejectsIfNestedArrayPromiseRejects', function() {
|
|
444
|
-
var aPromise = Promise.resolve([
|
|
445
|
-
Promise.resolve([
|
|
446
|
-
createRejectedPromise(new StubError)
|
|
447
|
-
])
|
|
448
|
-
]);
|
|
449
|
-
|
|
450
|
-
return promise.fullyResolved(aPromise)
|
|
451
|
-
.then(assert.fail, assertIsStubError);
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
it('simpleHash', function() {
|
|
455
|
-
var hash = {'a': 123};
|
|
456
|
-
return promise.fullyResolved(hash)
|
|
457
|
-
.then(function(resolved) {
|
|
458
|
-
assert.strictEqual(hash, resolved);
|
|
459
|
-
assert.deepEqual(hash, {'a': 123});
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
it('nestedHash', function() {
|
|
464
|
-
var nestedHash = {'foo':'bar'};
|
|
465
|
-
var hash = {'a': 123, 'b': nestedHash};
|
|
466
|
-
|
|
467
|
-
return promise.fullyResolved(hash)
|
|
468
|
-
.then(function(resolved) {
|
|
469
|
-
assert.strictEqual(hash, resolved);
|
|
470
|
-
assert.deepEqual({'a': 123, 'b': {'foo': 'bar'}}, resolved);
|
|
471
|
-
assert.strictEqual(nestedHash, resolved['b']);
|
|
472
|
-
});
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
it('promiseResolvesToSimpleHash', function() {
|
|
476
|
-
var hash = {'a': 123};
|
|
477
|
-
var aPromise = Promise.resolve(hash);
|
|
478
|
-
|
|
479
|
-
return promise.fullyResolved(aPromise)
|
|
480
|
-
.then((resolved) => assert.strictEqual(hash, resolved));
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
it('promiseResolvesToNestedHash', function() {
|
|
484
|
-
var nestedHash = {'foo':'bar'};
|
|
485
|
-
var hash = {'a': 123, 'b': nestedHash};
|
|
486
|
-
var aPromise = Promise.resolve(hash);
|
|
487
|
-
|
|
488
|
-
return promise.fullyResolved(aPromise)
|
|
489
|
-
.then(function(resolved) {
|
|
490
|
-
assert.strictEqual(hash, resolved);
|
|
491
|
-
assert.strictEqual(nestedHash, resolved['b']);
|
|
492
|
-
assert.deepEqual(hash, {'a': 123, 'b': {'foo': 'bar'}});
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
it('promiseResolvesToHashWithPromises', function() {
|
|
497
|
-
var aPromise = Promise.resolve({
|
|
498
|
-
'a': Promise.resolve(123)
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
return promise.fullyResolved(aPromise)
|
|
502
|
-
.then(function(resolved) {
|
|
503
|
-
assert.deepEqual({'a': 123}, resolved);
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
it('rejectsIfHashPromiseRejects', function() {
|
|
508
|
-
var aPromise = Promise.resolve({
|
|
509
|
-
'a': createRejectedPromise(new StubError)
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
return promise.fullyResolved(aPromise)
|
|
513
|
-
.then(assert.fail, assertIsStubError);
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
it('rejectsIfNestedHashPromiseRejects', function() {
|
|
517
|
-
var aPromise = Promise.resolve({
|
|
518
|
-
'a': {'b': createRejectedPromise(new StubError)}
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
return promise.fullyResolved(aPromise)
|
|
522
|
-
.then(assert.fail, assertIsStubError);
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
it('instantiatedObject', function() {
|
|
526
|
-
function Foo() {
|
|
527
|
-
this.bar = 'baz';
|
|
528
|
-
}
|
|
529
|
-
var foo = new Foo;
|
|
530
|
-
|
|
531
|
-
return promise.fullyResolved(foo).then(function(resolvedFoo) {
|
|
532
|
-
assert.equal(foo, resolvedFoo);
|
|
533
|
-
assert.ok(resolvedFoo instanceof Foo);
|
|
534
|
-
assert.deepEqual(new Foo, resolvedFoo);
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
it('withEmptyArray', function() {
|
|
539
|
-
return promise.fullyResolved([]).then(function(resolved) {
|
|
540
|
-
assert.deepEqual([], resolved);
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
it('withEmptyHash', function() {
|
|
545
|
-
return promise.fullyResolved({}).then(function(resolved) {
|
|
546
|
-
assert.deepEqual({}, resolved);
|
|
547
|
-
});
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
it('arrayWithPromisedHash', function() {
|
|
551
|
-
var obj = {'foo': 'bar'};
|
|
552
|
-
var array = [Promise.resolve(obj)];
|
|
553
|
-
|
|
554
|
-
return promise.fullyResolved(array).then(function(resolved) {
|
|
555
|
-
assert.deepEqual(resolved, [obj]);
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
describe('checkedNodeCall', function() {
|
|
561
|
-
it('functionThrows', function() {
|
|
562
|
-
return promise.checkedNodeCall(throwStubError)
|
|
563
|
-
.then(assert.fail, assertIsStubError);
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
it('functionReturnsAnError', function() {
|
|
567
|
-
return promise.checkedNodeCall(function(callback) {
|
|
568
|
-
callback(new StubError);
|
|
569
|
-
}).then(assert.fail, assertIsStubError);
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
it('functionReturnsSuccess', function() {
|
|
573
|
-
var success = 'success!';
|
|
574
|
-
return promise.checkedNodeCall(function(callback) {
|
|
575
|
-
callback(null, success);
|
|
576
|
-
}).then((value) => assert.equal(success, value));
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
it('functionReturnsAndThrows', function() {
|
|
580
|
-
var error = new Error('boom');
|
|
581
|
-
var error2 = new Error('boom again');
|
|
582
|
-
return promise.checkedNodeCall(function(callback) {
|
|
583
|
-
callback(error);
|
|
584
|
-
throw error2;
|
|
585
|
-
}).then(assert.fail, (e) => assert.equal(error, e));
|
|
586
|
-
});
|
|
587
|
-
|
|
588
|
-
it('functionThrowsAndReturns', function() {
|
|
589
|
-
var error = new Error('boom');
|
|
590
|
-
var error2 = new Error('boom again');
|
|
591
|
-
return promise.checkedNodeCall(function(callback) {
|
|
592
|
-
setTimeout(() => callback(error), 10);
|
|
593
|
-
throw error2;
|
|
594
|
-
}).then(assert.fail, (e) => assert.equal(error2, e));
|
|
595
|
-
});
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
describe('all', function() {
|
|
599
|
-
it('(base case)', function() {
|
|
600
|
-
let deferredObjs = [defer(), defer()];
|
|
601
|
-
var a = [
|
|
602
|
-
0, 1,
|
|
603
|
-
deferredObjs[0].promise,
|
|
604
|
-
deferredObjs[1].promise,
|
|
605
|
-
4, 5, 6
|
|
606
|
-
];
|
|
607
|
-
delete a[5];
|
|
608
|
-
|
|
609
|
-
var pair = callbackPair(function(value) {
|
|
610
|
-
assert.deepEqual([0, 1, 2, 3, 4, undefined, 6], value);
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
var result = promise.all(a).then(pair.callback, pair.errback);
|
|
614
|
-
pair.assertNeither();
|
|
615
|
-
|
|
616
|
-
deferredObjs[0].resolve(2);
|
|
617
|
-
pair.assertNeither();
|
|
618
|
-
|
|
619
|
-
deferredObjs[1].resolve(3);
|
|
620
|
-
return result.then(() => pair.assertCallback());
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
it('empty array', function() {
|
|
624
|
-
return promise.all([]).then((a) => assert.deepEqual([], a));
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
it('usesFirstRejection', function() {
|
|
628
|
-
let deferredObjs = [defer(), defer()];
|
|
629
|
-
let a = [deferredObjs[0].promise, deferredObjs[1].promise];
|
|
630
|
-
|
|
631
|
-
var result = promise.all(a).then(assert.fail, assertIsStubError);
|
|
632
|
-
deferredObjs[1].reject(new StubError);
|
|
633
|
-
setTimeout(() => deferredObjs[0].reject(Error('ignored')), 0);
|
|
634
|
-
return result;
|
|
635
|
-
});
|
|
636
|
-
});
|
|
637
|
-
|
|
638
|
-
describe('map', function() {
|
|
639
|
-
it('(base case)', function() {
|
|
640
|
-
var a = [1, 2, 3];
|
|
641
|
-
return promise.map(a, function(value, index, a2) {
|
|
642
|
-
assert.equal(a, a2);
|
|
643
|
-
assert.equal('number', typeof index, 'not a number');
|
|
644
|
-
return value + 1;
|
|
645
|
-
}).then(function(value) {
|
|
646
|
-
assert.deepEqual([2, 3, 4], value);
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
it('omitsDeleted', function() {
|
|
651
|
-
var a = [0, 1, 2, 3, 4, 5, 6];
|
|
652
|
-
delete a[1];
|
|
653
|
-
delete a[3];
|
|
654
|
-
delete a[4];
|
|
655
|
-
delete a[6];
|
|
656
|
-
|
|
657
|
-
var expected = [0, 1, 4, 9, 16, 25, 36];
|
|
658
|
-
delete expected[1];
|
|
659
|
-
delete expected[3];
|
|
660
|
-
delete expected[4];
|
|
661
|
-
delete expected[6];
|
|
662
|
-
|
|
663
|
-
return promise.map(a, function(value) {
|
|
664
|
-
return value * value;
|
|
665
|
-
}).then(function(value) {
|
|
666
|
-
assert.deepEqual(expected, value);
|
|
667
|
-
});
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
it('emptyArray', function() {
|
|
671
|
-
return promise.map([], function(value) {
|
|
672
|
-
return value + 1;
|
|
673
|
-
}).then(function(value) {
|
|
674
|
-
assert.deepEqual([], value);
|
|
675
|
-
});
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
it('inputIsPromise', function() {
|
|
679
|
-
var input = defer();
|
|
680
|
-
var result = promise.map(input.promise, function(value) {
|
|
681
|
-
return value + 1;
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
var pair = callbackPair(function(value) {
|
|
685
|
-
assert.deepEqual([2, 3, 4], value);
|
|
686
|
-
});
|
|
687
|
-
result = result.then(pair.callback, pair.errback);
|
|
688
|
-
|
|
689
|
-
setTimeout(function() {
|
|
690
|
-
pair.assertNeither();
|
|
691
|
-
input.resolve([1, 2, 3]);
|
|
692
|
-
}, 10);
|
|
693
|
-
|
|
694
|
-
return result;
|
|
695
|
-
});
|
|
696
|
-
|
|
697
|
-
it('waitsForFunctionResultToResolve', function() {
|
|
698
|
-
var innerResults = [
|
|
699
|
-
defer(),
|
|
700
|
-
defer()
|
|
701
|
-
];
|
|
702
|
-
|
|
703
|
-
var result = promise.map([1, 2], function(value, index) {
|
|
704
|
-
return innerResults[index].promise;
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
var pair = callbackPair(function(value) {
|
|
708
|
-
assert.deepEqual(['a', 'b'], value);
|
|
709
|
-
});
|
|
710
|
-
result = result.then(pair.callback, pair.errback);
|
|
711
|
-
|
|
712
|
-
return NativePromise.resolve()
|
|
713
|
-
.then(function() {
|
|
714
|
-
pair.assertNeither();
|
|
715
|
-
innerResults[0].resolve('a');
|
|
716
|
-
})
|
|
717
|
-
.then(function() {
|
|
718
|
-
pair.assertNeither();
|
|
719
|
-
innerResults[1].resolve('b');
|
|
720
|
-
return result;
|
|
721
|
-
})
|
|
722
|
-
.then(pair.assertCallback);
|
|
723
|
-
});
|
|
724
|
-
|
|
725
|
-
it('rejectsPromiseIfFunctionThrows', function() {
|
|
726
|
-
return promise.map([1], throwStubError)
|
|
727
|
-
.then(assert.fail, assertIsStubError);
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
it('rejectsPromiseIfFunctionReturnsRejectedPromise', function() {
|
|
731
|
-
return promise.map([1], function() {
|
|
732
|
-
return createRejectedPromise(new StubError);
|
|
733
|
-
}).then(assert.fail, assertIsStubError);
|
|
734
|
-
});
|
|
735
|
-
|
|
736
|
-
it('stopsCallingFunctionIfPreviousIterationFailed', function() {
|
|
737
|
-
var count = 0;
|
|
738
|
-
return promise.map([1, 2, 3, 4], function() {
|
|
739
|
-
count++;
|
|
740
|
-
if (count == 3) {
|
|
741
|
-
throw new StubError;
|
|
742
|
-
}
|
|
743
|
-
}).then(assert.fail, function(e) {
|
|
744
|
-
assertIsStubError(e);
|
|
745
|
-
assert.equal(3, count);
|
|
746
|
-
});
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
it('rejectsWithFirstRejectedPromise', function() {
|
|
750
|
-
var innerResult = [
|
|
751
|
-
Promise.resolve(),
|
|
752
|
-
createRejectedPromise(new StubError),
|
|
753
|
-
createRejectedPromise(Error('should be ignored'))
|
|
754
|
-
];
|
|
755
|
-
var count = 0;
|
|
756
|
-
return promise.map([1, 2, 3, 4], function(value, index) {
|
|
757
|
-
count += 1;
|
|
758
|
-
return innerResult[index];
|
|
759
|
-
}).then(assert.fail, function(e) {
|
|
760
|
-
assertIsStubError(e);
|
|
761
|
-
assert.equal(2, count);
|
|
762
|
-
});
|
|
763
|
-
});
|
|
764
|
-
|
|
765
|
-
it('preservesOrderWhenMapReturnsPromise', function() {
|
|
766
|
-
var deferreds = [
|
|
767
|
-
defer(),
|
|
768
|
-
defer(),
|
|
769
|
-
defer(),
|
|
770
|
-
defer()
|
|
771
|
-
];
|
|
772
|
-
var result = promise.map(deferreds, function(value) {
|
|
773
|
-
return value.promise;
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
var pair = callbackPair(function(value) {
|
|
777
|
-
assert.deepEqual([0, 1, 2, 3], value);
|
|
778
|
-
});
|
|
779
|
-
result = result.then(pair.callback, pair.errback);
|
|
780
|
-
|
|
781
|
-
return Promise.resolve()
|
|
782
|
-
.then(function() {
|
|
783
|
-
pair.assertNeither();
|
|
784
|
-
for (let i = deferreds.length; i > 0; i -= 1) {
|
|
785
|
-
deferreds[i - 1].resolve(i - 1);
|
|
786
|
-
}
|
|
787
|
-
return result;
|
|
788
|
-
}).then(pair.assertCallback);
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
describe('filter', function() {
|
|
793
|
-
it('basicFiltering', function() {
|
|
794
|
-
var a = [0, 1, 2, 3];
|
|
795
|
-
return promise.filter(a, function(val, index, a2) {
|
|
796
|
-
assert.equal(a, a2);
|
|
797
|
-
assert.equal('number', typeof index, 'not a number');
|
|
798
|
-
return val > 1;
|
|
799
|
-
}).then(function(val) {
|
|
800
|
-
assert.deepEqual([2, 3], val);
|
|
801
|
-
});
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
it('omitsDeleted', function() {
|
|
805
|
-
var a = [0, 1, 2, 3, 4, 5, 6];
|
|
806
|
-
delete a[3];
|
|
807
|
-
delete a[4];
|
|
808
|
-
|
|
809
|
-
return promise.filter(a, function(value) {
|
|
810
|
-
return value > 1 && value < 6;
|
|
811
|
-
}).then(function(val) {
|
|
812
|
-
assert.deepEqual([2, 5], val);
|
|
813
|
-
});
|
|
814
|
-
});
|
|
815
|
-
|
|
816
|
-
it('preservesInputs', function() {
|
|
817
|
-
var a = [0, 1, 2, 3];
|
|
818
|
-
|
|
819
|
-
return promise.filter(a, function(value, i, a2) {
|
|
820
|
-
assert.equal(a, a2);
|
|
821
|
-
// Even if a function modifies the input array, the original value
|
|
822
|
-
// should be inserted into the new array.
|
|
823
|
-
a2[i] = a2[i] - 1;
|
|
824
|
-
return a2[i] >= 1;
|
|
825
|
-
}).then(function(val) {
|
|
826
|
-
assert.deepEqual([2, 3], val);
|
|
827
|
-
});
|
|
828
|
-
});
|
|
829
|
-
|
|
830
|
-
it('inputIsPromise', function() {
|
|
831
|
-
var input = defer();
|
|
832
|
-
var result = promise.filter(input.promise, function(value) {
|
|
833
|
-
return value > 1 && value < 3;
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
var pair = callbackPair(function(value) {
|
|
837
|
-
assert.deepEqual([2], value);
|
|
838
|
-
});
|
|
839
|
-
result = result.then(pair.callback, pair.errback);
|
|
840
|
-
return NativePromise.resolve()
|
|
841
|
-
.then(function() {
|
|
842
|
-
pair.assertNeither();
|
|
843
|
-
input.resolve([1, 2, 3]);
|
|
844
|
-
return result;
|
|
845
|
-
})
|
|
846
|
-
.then(pair.assertCallback);
|
|
847
|
-
});
|
|
848
|
-
|
|
849
|
-
it('waitsForFunctionResultToResolve', function() {
|
|
850
|
-
var innerResults = [
|
|
851
|
-
defer(),
|
|
852
|
-
defer()
|
|
853
|
-
];
|
|
854
|
-
|
|
855
|
-
var result = promise.filter([1, 2], function(value, index) {
|
|
856
|
-
return innerResults[index].promise;
|
|
857
|
-
});
|
|
858
|
-
|
|
859
|
-
var pair = callbackPair(function(value) {
|
|
860
|
-
assert.deepEqual([2], value);
|
|
861
|
-
});
|
|
862
|
-
result = result.then(pair.callback, pair.errback);
|
|
863
|
-
return NativePromise.resolve()
|
|
864
|
-
.then(function() {
|
|
865
|
-
pair.assertNeither();
|
|
866
|
-
innerResults[0].resolve(false);
|
|
867
|
-
})
|
|
868
|
-
.then(function() {
|
|
869
|
-
pair.assertNeither();
|
|
870
|
-
innerResults[1].resolve(true);
|
|
871
|
-
return result;
|
|
872
|
-
})
|
|
873
|
-
.then(pair.assertCallback);
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
it('rejectsPromiseIfFunctionReturnsRejectedPromise', function() {
|
|
877
|
-
return promise.filter([1], function() {
|
|
878
|
-
return createRejectedPromise(new StubError);
|
|
879
|
-
}).then(assert.fail, assertIsStubError);
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
it('stopsCallingFunctionIfPreviousIterationFailed', function() {
|
|
883
|
-
var count = 0;
|
|
884
|
-
return promise.filter([1, 2, 3, 4], function() {
|
|
885
|
-
count++;
|
|
886
|
-
if (count == 3) {
|
|
887
|
-
throw new StubError;
|
|
888
|
-
}
|
|
889
|
-
}).then(assert.fail, function(e) {
|
|
890
|
-
assertIsStubError(e);
|
|
891
|
-
assert.equal(3, count);
|
|
892
|
-
});
|
|
893
|
-
});
|
|
894
|
-
|
|
895
|
-
it('rejectsWithFirstRejectedPromise', function() {
|
|
896
|
-
var innerResult = [
|
|
897
|
-
Promise.resolve(),
|
|
898
|
-
createRejectedPromise(new StubError),
|
|
899
|
-
createRejectedPromise(Error('should be ignored'))
|
|
900
|
-
];
|
|
901
|
-
|
|
902
|
-
return promise.filter([1, 2, 3, 4], function(value, index) {
|
|
903
|
-
assert.ok(index < innerResult.length);
|
|
904
|
-
return innerResult[index];
|
|
905
|
-
}).then(assert.fail, assertIsStubError);
|
|
906
|
-
});
|
|
907
|
-
|
|
908
|
-
it('preservesOrderWhenFilterReturnsPromise', function() {
|
|
909
|
-
var deferreds = [
|
|
910
|
-
defer(),
|
|
911
|
-
defer(),
|
|
912
|
-
defer(),
|
|
913
|
-
defer()
|
|
914
|
-
];
|
|
915
|
-
var result = promise.filter([0, 1, 2, 3], function(value, index) {
|
|
916
|
-
return deferreds[index].promise;
|
|
917
|
-
});
|
|
918
|
-
|
|
919
|
-
var pair = callbackPair(function(value) {
|
|
920
|
-
assert.deepEqual([1, 2], value);
|
|
921
|
-
});
|
|
922
|
-
result = result.then(pair.callback, pair.errback);
|
|
923
|
-
|
|
924
|
-
return NativePromise.resolve()
|
|
925
|
-
.then(function() {
|
|
926
|
-
pair.assertNeither();
|
|
927
|
-
for (let i = deferreds.length - 1; i >= 0; i -= 1) {
|
|
928
|
-
deferreds[i].resolve(i > 0 && i < 3);
|
|
929
|
-
}
|
|
930
|
-
return result;
|
|
931
|
-
}).then(pair.assertCallback);
|
|
932
|
-
});
|
|
933
|
-
});
|
|
934
|
-
});
|
|
935
|
-
|
|
936
|
-
enablePromiseManager(() => {
|
|
937
|
-
it('firesUncaughtExceptionEventIfRejectionNeverHandled', function() {
|
|
938
|
-
promise.rejected(new StubError);
|
|
939
|
-
var handler = callbackHelper(assertIsStubError);
|
|
940
|
-
|
|
941
|
-
// so tearDown() doesn't throw
|
|
942
|
-
app.removeAllListeners();
|
|
943
|
-
app.on(promise.ControlFlow.EventType.UNCAUGHT_EXCEPTION, handler);
|
|
944
|
-
|
|
945
|
-
return NativePromise.resolve()
|
|
946
|
-
// Macro yield so the uncaught exception has a chance to trigger.
|
|
947
|
-
.then(() => new NativePromise(resolve => setTimeout(resolve, 0)))
|
|
948
|
-
.then(handler.assertCalled);
|
|
949
|
-
});
|
|
950
|
-
|
|
951
|
-
it('cannotResolveADeferredWithItself', function() {
|
|
952
|
-
var deferred = new promise.Deferred();
|
|
953
|
-
assert.throws(() => deferred.fulfill(deferred));
|
|
954
|
-
assert.throws(() => deferred.reject(deferred));
|
|
955
|
-
});
|
|
956
|
-
|
|
957
|
-
describe('testLongStackTraces', function() {
|
|
958
|
-
beforeEach(() => promise.LONG_STACK_TRACES = false);
|
|
959
|
-
afterEach(() => promise.LONG_STACK_TRACES = false);
|
|
960
|
-
|
|
961
|
-
it('doesNotAppendStackIfFeatureDisabled', function() {
|
|
962
|
-
promise.LONG_STACK_TRACES = false;
|
|
963
|
-
|
|
964
|
-
var error = Error('hello');
|
|
965
|
-
var originalStack = error.stack;
|
|
966
|
-
return promise.rejected(error).
|
|
967
|
-
then(fail).
|
|
968
|
-
then(fail).
|
|
969
|
-
then(fail).
|
|
970
|
-
then(fail, function(e) {
|
|
971
|
-
assert.equal(error, e);
|
|
972
|
-
assert.equal(originalStack, e.stack);
|
|
973
|
-
});
|
|
974
|
-
});
|
|
975
|
-
|
|
976
|
-
function getStackMessages(error) {
|
|
977
|
-
return error.stack.split(/\n/).filter(function(line) {
|
|
978
|
-
return /^From: /.test(line);
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
it('appendsInitialPromiseCreation_resolverThrows', function() {
|
|
983
|
-
promise.LONG_STACK_TRACES = true;
|
|
984
|
-
|
|
985
|
-
var error = Error('hello');
|
|
986
|
-
var originalStack = '(placeholder; will be overwritten later)';
|
|
987
|
-
|
|
988
|
-
return new promise.Promise(function() {
|
|
989
|
-
try {
|
|
990
|
-
throw error;
|
|
991
|
-
} catch (e) {
|
|
992
|
-
originalStack = e.stack;
|
|
993
|
-
throw e;
|
|
994
|
-
}
|
|
995
|
-
}).then(fail, function(e) {
|
|
996
|
-
assert.strictEqual(error, e);
|
|
997
|
-
if (typeof originalStack !== 'string') {
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
assert.notEqual(originalStack, e.stack);
|
|
1001
|
-
assert.equal(e.stack.indexOf(originalStack), 0,
|
|
1002
|
-
'should start with original stack');
|
|
1003
|
-
assert.deepEqual(['From: ManagedPromise: new'], getStackMessages(e));
|
|
1004
|
-
});
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
it('appendsInitialPromiseCreation_rejectCalled', function() {
|
|
1008
|
-
promise.LONG_STACK_TRACES = true;
|
|
1009
|
-
|
|
1010
|
-
var error = Error('hello');
|
|
1011
|
-
var originalStack = error.stack;
|
|
1012
|
-
|
|
1013
|
-
return new promise.Promise(function(_, reject) {
|
|
1014
|
-
reject(error);
|
|
1015
|
-
}).then(fail, function(e) {
|
|
1016
|
-
assert.equal(error, e);
|
|
1017
|
-
if (typeof originalStack !== 'string') {
|
|
1018
|
-
return;
|
|
1019
|
-
}
|
|
1020
|
-
assert.notEqual(originalStack, e.stack);
|
|
1021
|
-
assert.equal(e.stack.indexOf(originalStack), 0,
|
|
1022
|
-
'should start with original stack');
|
|
1023
|
-
assert.deepEqual(['From: ManagedPromise: new'], getStackMessages(e));
|
|
1024
|
-
});
|
|
1025
|
-
});
|
|
1026
|
-
|
|
1027
|
-
it('appendsEachStepToRejectionError', function() {
|
|
1028
|
-
promise.LONG_STACK_TRACES = true;
|
|
1029
|
-
|
|
1030
|
-
var error = Error('hello');
|
|
1031
|
-
var originalStack = '(placeholder; will be overwritten later)';
|
|
1032
|
-
|
|
1033
|
-
return new promise.Promise(function() {
|
|
1034
|
-
try {
|
|
1035
|
-
throw error;
|
|
1036
|
-
} catch (e) {
|
|
1037
|
-
originalStack = e.stack;
|
|
1038
|
-
throw e;
|
|
1039
|
-
}
|
|
1040
|
-
}).
|
|
1041
|
-
then(fail).
|
|
1042
|
-
catch(function(e) { throw e; }).
|
|
1043
|
-
then(fail).
|
|
1044
|
-
catch(function(e) { throw e; }).
|
|
1045
|
-
then(fail, function(e) {
|
|
1046
|
-
assert.equal(error, e);
|
|
1047
|
-
if (typeof originalStack !== 'string') {
|
|
1048
|
-
return;
|
|
1049
|
-
}
|
|
1050
|
-
assert.notEqual(originalStack, e.stack);
|
|
1051
|
-
assert.equal(e.stack.indexOf(originalStack), 0,
|
|
1052
|
-
'should start with original stack');
|
|
1053
|
-
assert.deepEqual([
|
|
1054
|
-
'From: ManagedPromise: new',
|
|
1055
|
-
'From: Promise: then',
|
|
1056
|
-
'From: Promise: catch',
|
|
1057
|
-
'From: Promise: then',
|
|
1058
|
-
'From: Promise: catch',
|
|
1059
|
-
], getStackMessages(e));
|
|
1060
|
-
});
|
|
1061
|
-
});
|
|
1062
|
-
|
|
1063
|
-
it('errorOccursInCallbackChain', function() {
|
|
1064
|
-
promise.LONG_STACK_TRACES = true;
|
|
1065
|
-
|
|
1066
|
-
var error = Error('hello');
|
|
1067
|
-
var originalStack = '(placeholder; will be overwritten later)';
|
|
1068
|
-
|
|
1069
|
-
return promise.fulfilled().
|
|
1070
|
-
then(function() {}).
|
|
1071
|
-
then(function() {}).
|
|
1072
|
-
then(function() {
|
|
1073
|
-
try {
|
|
1074
|
-
throw error;
|
|
1075
|
-
} catch (e) {
|
|
1076
|
-
originalStack = e.stack;
|
|
1077
|
-
throw e;
|
|
1078
|
-
}
|
|
1079
|
-
}).
|
|
1080
|
-
catch(function(e) { throw e; }).
|
|
1081
|
-
then(fail, function(e) {
|
|
1082
|
-
assert.equal(error, e);
|
|
1083
|
-
if (typeof originalStack !== 'string') {
|
|
1084
|
-
return;
|
|
1085
|
-
}
|
|
1086
|
-
assert.notEqual(originalStack, e.stack);
|
|
1087
|
-
assert.equal(e.stack.indexOf(originalStack), 0,
|
|
1088
|
-
'should start with original stack');
|
|
1089
|
-
assert.deepEqual([
|
|
1090
|
-
'From: Promise: then',
|
|
1091
|
-
'From: Promise: catch',
|
|
1092
|
-
], getStackMessages(e));
|
|
1093
|
-
});
|
|
1094
|
-
});
|
|
1095
|
-
});
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
it('testAddThenableImplementation', function() {
|
|
1099
|
-
function tmp() {}
|
|
1100
|
-
assert.ok(!promise.Thenable.isImplementation(new tmp()));
|
|
1101
|
-
promise.Thenable.addImplementation(tmp);
|
|
1102
|
-
assert.ok(promise.Thenable.isImplementation(new tmp()));
|
|
1103
|
-
|
|
1104
|
-
class tmpClass {}
|
|
1105
|
-
assert.ok(!promise.Thenable.isImplementation(new tmpClass()));
|
|
1106
|
-
promise.Thenable.addImplementation(tmpClass);
|
|
1107
|
-
assert.ok(promise.Thenable.isImplementation(new tmpClass()));
|
|
1108
|
-
});
|
|
1109
|
-
});
|