Best JavaScript code snippet using wpt
aborting.js
Source:aborting.js
...347 writer.write('a');348 const abortPromise = writer.abort('b');349 return flushAsyncEvents().then(() => {350 assert_array_equals(ws.events, ['write', 'a'], 'abort should not be called while write is in-flight');351 resolveWrite();352 return abortPromise.then(() => {353 assert_array_equals(ws.events, ['write', 'a', 'abort', 'b'], 'abort should be called after the write finishes');354 });355 });356 });357}, 'underlying abort() should not be called until underlying write() completes');358promise_test(() => {359 let resolveClose;360 const ws = recordingWritableStream({361 close() {362 return new Promise(resolve => {363 resolveClose = resolve;364 });365 }366 });367 const writer = ws.getWriter();368 return writer.ready.then(() => {369 writer.close();370 const abortPromise = writer.abort();371 return flushAsyncEvents().then(() => {372 assert_array_equals(ws.events, ['close'], 'abort should not be called while close is in-flight');373 resolveClose();374 return abortPromise.then(() => {375 assert_array_equals(ws.events, ['close'], 'abort should not be called');376 });377 });378 });379}, 'underlying abort() should not be called if underlying close() has started');380promise_test(t => {381 let rejectClose;382 let abortCalled = false;383 const ws = new WritableStream({384 close() {385 return new Promise((resolve, reject) => {386 rejectClose = reject;387 });388 },389 abort() {390 abortCalled = true;391 }392 });393 const writer = ws.getWriter();394 return writer.ready.then(() => {395 const closePromise = writer.close();396 const abortPromise = writer.abort();397 return flushAsyncEvents().then(() => {398 assert_false(abortCalled, 'underlying abort should not be called while close is in-flight');399 rejectClose(error1);400 return promise_rejects(t, error1, abortPromise, 'abort should reject with the same reason').then(() => {401 return promise_rejects(t, error1, closePromise, 'close should reject with the same reason');402 }).then(() => {403 assert_false(abortCalled, 'underlying abort should not be called after close completes');404 });405 });406 });407}, 'if underlying close() has started and then rejects, the abort() and close() promises should reject with the ' +408 'underlying close rejection reason');409promise_test(t => {410 let resolveWrite;411 const ws = recordingWritableStream({412 write() {413 return new Promise(resolve => {414 resolveWrite = resolve;415 });416 }417 });418 const writer = ws.getWriter();419 return writer.ready.then(() => {420 writer.write('a');421 const closePromise = writer.close();422 const abortPromise = writer.abort('b');423 return flushAsyncEvents().then(() => {424 assert_array_equals(ws.events, ['write', 'a'], 'abort should not be called while write is in-flight');425 resolveWrite();426 return abortPromise.then(() => {427 assert_array_equals(ws.events, ['write', 'a', 'abort', 'b'], 'abort should be called after write completes');428 return promise_rejects(t, new TypeError(), closePromise, 'promise returned by close() should be rejected');429 });430 });431 });432}, 'an abort() that happens during a write() should trigger the underlying abort() even with a close() queued');433promise_test(t => {434 const ws = new WritableStream({435 write() {436 return new Promise(() => {});437 }438 });439 const writer = ws.getWriter();440 return writer.ready.then(() => {441 writer.write('a');442 writer.abort();443 writer.releaseLock();444 const writer2 = ws.getWriter();445 return promise_rejects(t, new TypeError(), writer2.ready,446 'ready of the second writer should be rejected with a TypeError');447 });448}, 'if a writer is created for a stream with a pending abort, its ready should be rejected with a TypeError');449promise_test(() => {450 const ws = new WritableStream();451 const writer = ws.getWriter();452 return writer.ready.then(() => {453 const closePromise = writer.close();454 const abortPromise = writer.abort();455 const events = [];456 return Promise.all([457 closePromise.then(() => { events.push('close'); }),458 abortPromise.then(() => { events.push('abort'); })459 ]).then(() => {460 assert_array_equals(events, ['close', 'abort']);461 });462 });463}, 'writer close() promise should resolve before abort() promise');464promise_test(t => {465 const ws = new WritableStream({466 write(chunk, controller) {467 controller.error(error1);468 return new Promise(() => {});469 }470 });471 const writer = ws.getWriter();472 return writer.ready.then(() => {473 writer.write('a');474 return promise_rejects(t, error1, writer.ready, 'writer.ready should reject');475 });476}, 'writer.ready should reject on controller error without waiting for underlying write');477promise_test(t => {478 let rejectWrite;479 const ws = new WritableStream({480 write() {481 return new Promise((resolve, reject) => {482 rejectWrite = reject;483 });484 }485 });486 let writePromise;487 let abortPromise;488 const events = [];489 const writer = ws.getWriter();490 writer.closed.catch(() => {491 events.push('closed');492 });493 // Wait for ws to start494 return flushAsyncEvents().then(() => {495 writePromise = writer.write('a');496 writePromise.catch(() => {497 events.push('writePromise');498 });499 abortPromise = writer.abort(error1);500 abortPromise.then(() => {501 events.push('abortPromise');502 });503 const writePromise2 = writer.write('a');504 return Promise.all([505 promise_rejects(t, new TypeError(), writePromise2, 'writePromise2 must reject with an error indicating abort'),506 promise_rejects(t, new TypeError(), writer.ready, 'writer.ready must reject with an error indicating abort'),507 flushAsyncEvents()508 ]);509 }).then(() => {510 assert_array_equals(events, [], 'writePromise, abortPromise and writer.closed must not be rejected yet');511 rejectWrite(error2);512 return Promise.all([513 promise_rejects(t, error2, writePromise,514 'writePromise must reject with the error returned from the sink\'s write method'),515 abortPromise,516 promise_rejects(t, new TypeError(), writer.closed,517 'writer.closed must reject with an error indicating abort'),518 flushAsyncEvents()519 ]);520 }).then(() => {521 assert_array_equals(events, ['writePromise', 'abortPromise', 'closed'],522 'writePromise, abortPromise and writer.closed must settle');523 const writePromise3 = writer.write('a');524 return Promise.all([525 promise_rejects(t, new TypeError(), writePromise3,526 'writePromise3 must reject with an error indicating abort'),527 promise_rejects(t, new TypeError(), writer.ready,528 'writer.ready must be still rejected with the error indicating abort')529 ]);530 }).then(() => {531 writer.releaseLock();532 return Promise.all([533 promise_rejects(t, new TypeError(), writer.ready,534 'writer.ready must be rejected with an error indicating release'),535 promise_rejects(t, new TypeError(), writer.closed,536 'writer.closed must be rejected with an error indicating release')537 ]);538 });539}, 'writer.abort() while there is an in-flight write, and then finish the write with rejection');540promise_test(t => {541 let resolveWrite;542 let controller;543 const ws = new WritableStream({544 write(chunk, c) {545 controller = c;546 return new Promise(resolve => {547 resolveWrite = resolve;548 });549 }550 });551 let writePromise;552 let abortPromise;553 const events = [];554 const writer = ws.getWriter();555 writer.closed.catch(() => {556 events.push('closed');557 });558 // Wait for ws to start559 return flushAsyncEvents().then(() => {560 writePromise = writer.write('a');561 writePromise.then(() => {562 events.push('writePromise');563 });564 abortPromise = writer.abort(error1);565 abortPromise.then(() => {566 events.push('abortPromise');567 });568 const writePromise2 = writer.write('a');569 return Promise.all([570 promise_rejects(t, new TypeError(), writePromise2, 'writePromise2 must reject with an error indicating abort'),571 promise_rejects(t, new TypeError(), writer.ready, 'writer.ready must reject with an error indicating abort'),572 flushAsyncEvents()573 ]);574 }).then(() => {575 assert_array_equals(events, [], 'writePromise, abortPromise and writer.closed must not be fulfilled/rejected yet');576 // This error is too late to change anything. abort() has already changed the stream state to 'erroring'.577 controller.error(error2);578 const writePromise3 = writer.write('a');579 return Promise.all([580 promise_rejects(t, new TypeError(), writePromise3,581 'writePromise3 must reject with an error indicating abort'),582 promise_rejects(t, new TypeError(), writer.ready,583 'writer.ready must be still rejected with the error indicating abort'),584 flushAsyncEvents()585 ]);586 }).then(() => {587 assert_array_equals(588 events, [],589 'writePromise, abortPromise and writer.closed must not be fulfilled/rejected yet even after ' +590 'controller.error() call');591 resolveWrite();592 return Promise.all([593 writePromise,594 abortPromise,595 promise_rejects(t, new TypeError(), writer.closed,596 'writer.closed must reject with an error indicating abort'),597 flushAsyncEvents()598 ]);599 }).then(() => {600 assert_array_equals(events, ['writePromise', 'abortPromise', 'closed'],601 'writePromise, abortPromise and writer.closed must settle');602 const writePromise4 = writer.write('a');603 return Promise.all([604 writePromise,605 promise_rejects(t, new TypeError(), writePromise4,606 'writePromise4 must reject with an error indicating abort'),607 promise_rejects(t, new TypeError(), writer.ready,608 'writer.ready must be still rejected with the error indicating abort')609 ]);610 }).then(() => {611 writer.releaseLock();612 return Promise.all([613 promise_rejects(t, new TypeError(), writer.ready,614 'writer.ready must be rejected with an error indicating release'),615 promise_rejects(t, new TypeError(), writer.closed,616 'writer.closed must be rejected with an error indicating release')617 ]);618 });619}, 'writer.abort(), controller.error() while there is an in-flight write, and then finish the write');620promise_test(t => {621 let resolveClose;622 let controller;623 const ws = new WritableStream({624 start(c) {625 controller = c;626 },627 close() {628 return new Promise(resolve => {629 resolveClose = resolve;630 });631 }632 });633 let closePromise;634 let abortPromise;635 const events = [];636 const writer = ws.getWriter();637 writer.closed.then(() => {638 events.push('closed');639 });640 // Wait for ws to start641 return flushAsyncEvents().then(() => {642 closePromise = writer.close();643 closePromise.then(() => {644 events.push('closePromise');645 });646 abortPromise = writer.abort(error1);647 abortPromise.then(() => {648 events.push('abortPromise');649 });650 return Promise.all([651 promise_rejects(t, new TypeError(), writer.close(),652 'writer.close() must reject with an error indicating already closing'),653 promise_rejects(t, new TypeError(), writer.ready, 'writer.ready must reject with an error indicating abort'),654 flushAsyncEvents()655 ]);656 }).then(() => {657 assert_array_equals(events, [], 'closePromise, abortPromise and writer.closed must not be fulfilled/rejected yet');658 controller.error(error2);659 return Promise.all([660 promise_rejects(t, new TypeError(), writer.close(),661 'writer.close() must reject with an error indicating already closing'),662 promise_rejects(t, new TypeError(), writer.ready,663 'writer.ready must be still rejected with the error indicating abort'),664 flushAsyncEvents()665 ]);666 }).then(() => {667 assert_array_equals(668 events, [],669 'closePromise, abortPromise and writer.closed must not be fulfilled/rejected yet even after ' +670 'controller.error() call');671 resolveClose();672 return Promise.all([673 closePromise,674 abortPromise,675 writer.closed,676 flushAsyncEvents()677 ]);678 }).then(() => {679 assert_array_equals(events, ['closePromise', 'abortPromise', 'closed'],680 'closedPromise, abortPromise and writer.closed must fulfill');681 return Promise.all([682 promise_rejects(t, new TypeError(), writer.close(),683 'writer.close() must reject with an error indicating already closing'),684 promise_rejects(t, new TypeError(), writer.ready,685 'writer.ready must be still rejected with the error indicating abort')686 ]);687 }).then(() => {688 writer.releaseLock();689 return Promise.all([690 promise_rejects(t, new TypeError(), writer.close(),691 'writer.close() must reject with an error indicating release'),692 promise_rejects(t, new TypeError(), writer.ready,693 'writer.ready must be rejected with an error indicating release'),694 promise_rejects(t, new TypeError(), writer.closed,695 'writer.closed must be rejected with an error indicating release')696 ]);697 });698}, 'writer.abort(), controller.error() while there is an in-flight close, and then finish the close');699promise_test(t => {700 let resolveWrite;701 let controller;702 const ws = recordingWritableStream({703 write(chunk, c) {704 controller = c;705 return new Promise(resolve => {706 resolveWrite = resolve;707 });708 }709 });710 let writePromise;711 let abortPromise;712 const events = [];713 const writer = ws.getWriter();714 writer.closed.catch(() => {715 events.push('closed');716 });717 // Wait for ws to start718 return flushAsyncEvents().then(() => {719 writePromise = writer.write('a');720 writePromise.then(() => {721 events.push('writePromise');722 });723 controller.error(error2);724 const writePromise2 = writer.write('a');725 return Promise.all([726 promise_rejects(t, error2, writePromise2,727 'writePromise2 must reject with the error passed to the controller\'s error method'),728 promise_rejects(t, error2, writer.ready,729 'writer.ready must reject with the error passed to the controller\'s error method'),730 flushAsyncEvents()731 ]);732 }).then(() => {733 assert_array_equals(events, [], 'writePromise and writer.closed must not be fulfilled/rejected yet');734 abortPromise = writer.abort(error1);735 abortPromise.catch(() => {736 events.push('abortPromise');737 });738 const writePromise3 = writer.write('a');739 return Promise.all([740 promise_rejects(t, error2, writePromise3,741 'writePromise3 must reject with the error passed to the controller\'s error method'),742 flushAsyncEvents()743 ]);744 }).then(() => {745 assert_array_equals(746 events, [],747 'writePromise and writer.closed must not be fulfilled/rejected yet even after writer.abort()');748 resolveWrite();749 return Promise.all([750 promise_rejects(t, error2, abortPromise,751 'abort() must reject with the error passed to the controller\'s error method'),752 promise_rejects(t, error2, writer.closed,753 'writer.closed must reject with the error passed to the controller\'s error method'),754 flushAsyncEvents()755 ]);756 }).then(() => {757 assert_array_equals(events, ['writePromise', 'abortPromise', 'closed'],758 'writePromise, abortPromise and writer.closed must fulfill/reject');759 assert_array_equals(ws.events, ['write', 'a'], 'sink abort() should not be called');760 const writePromise4 = writer.write('a');761 return Promise.all([762 writePromise,763 promise_rejects(t, error2, writePromise4,764 'writePromise4 must reject with the error passed to the controller\'s error method'),765 promise_rejects(t, error2, writer.ready,766 'writer.ready must be still rejected with the error passed to the controller\'s error method')767 ]);768 }).then(() => {769 writer.releaseLock();770 return Promise.all([771 promise_rejects(t, new TypeError(), writer.ready,772 'writer.ready must be rejected with an error indicating release'),773 promise_rejects(t, new TypeError(), writer.closed,774 'writer.closed must be rejected with an error indicating release')775 ]);776 });777}, 'controller.error(), writer.abort() while there is an in-flight write, and then finish the write');778promise_test(t => {779 let resolveClose;780 let controller;781 const ws = new WritableStream({782 start(c) {783 controller = c;784 },785 close() {786 return new Promise(resolve => {787 resolveClose = resolve;788 });789 }790 });791 let closePromise;792 let abortPromise;793 const events = [];794 const writer = ws.getWriter();795 writer.closed.then(() => {796 events.push('closed');797 });798 // Wait for ws to start799 return flushAsyncEvents().then(() => {800 closePromise = writer.close();801 closePromise.then(() => {802 events.push('closePromise');803 });804 controller.error(error2);805 return flushAsyncEvents();806 }).then(() => {807 assert_array_equals(events, [], 'closePromise must not be fulfilled/rejected yet');808 abortPromise = writer.abort(error1);809 abortPromise.then(() => {810 events.push('abortPromise');811 });812 return Promise.all([813 promise_rejects(t, error2, writer.ready,814 'writer.ready must reject with the error passed to the controller\'s error method'),815 flushAsyncEvents()816 ]);817 }).then(() => {818 assert_array_equals(819 events, [],820 'closePromise and writer.closed must not be fulfilled/rejected yet even after writer.abort()');821 resolveClose();822 return Promise.all([823 closePromise,824 promise_rejects(t, error2, writer.ready,825 'writer.ready must be still rejected with the error passed to the controller\'s error method'),826 writer.closed,827 flushAsyncEvents()828 ]);829 }).then(() => {830 assert_array_equals(events, ['closePromise', 'abortPromise', 'closed'],831 'abortPromise, closePromise and writer.closed must fulfill/reject');832 }).then(() => {833 writer.releaseLock();834 return Promise.all([835 promise_rejects(t, new TypeError(), writer.ready,836 'writer.ready must be rejected with an error indicating release'),837 promise_rejects(t, new TypeError(), writer.closed,838 'writer.closed must be rejected with an error indicating release')839 ]);840 });841}, 'controller.error(), writer.abort() while there is an in-flight close, and then finish the close');842promise_test(t => {843 let resolveWrite;844 const ws = new WritableStream({845 write() {846 return new Promise(resolve => {847 resolveWrite = resolve;848 });849 }850 });851 const writer = ws.getWriter();852 return writer.ready.then(() => {853 const writePromise = writer.write('a');854 const closed = writer.closed;855 const abortPromise = writer.abort();856 writer.releaseLock();857 resolveWrite();858 return Promise.all([859 writePromise,860 abortPromise,861 promise_rejects(t, new TypeError(), closed, 'closed should reject')]);862 });863}, 'releaseLock() while aborting should reject the original closed promise');864// TODO(ricea): Consider removing this test if it is no longer useful.865promise_test(t => {866 let resolveWrite;867 let resolveAbort;868 let resolveAbortStarted;869 const abortStarted = new Promise(resolve => {870 resolveAbortStarted = resolve;871 });872 const ws = new WritableStream({873 write() {874 return new Promise(resolve => {875 resolveWrite = resolve;876 });877 },878 abort() {879 resolveAbortStarted();880 return new Promise(resolve => {881 resolveAbort = resolve;882 });883 }884 });885 const writer = ws.getWriter();886 return writer.ready.then(() => {887 const writePromise = writer.write('a');888 const closed = writer.closed;889 const abortPromise = writer.abort();890 resolveWrite();891 return abortStarted.then(() => {892 writer.releaseLock();893 assert_equals(writer.closed, closed, 'closed promise should not have changed');894 resolveAbort();895 return Promise.all([896 writePromise,897 abortPromise,898 promise_rejects(t, new TypeError(), closed, 'closed should reject')]);899 });900 });901}, 'releaseLock() during delayed async abort() should reject the writer.closed promise');902promise_test(() => {903 let resolveStart;904 const ws = recordingWritableStream({905 start() {906 return new Promise(resolve => {907 resolveStart = resolve;908 });909 }910 });911 const abortPromise = ws.abort('done');912 return flushAsyncEvents().then(() => {913 assert_array_equals(ws.events, [], 'abort() should not be called during start()');914 resolveStart();915 return abortPromise.then(() => {916 assert_array_equals(ws.events, ['abort', 'done'], 'abort() should be called after start() is done');917 });918 });919}, 'sink abort() should not be called until sink start() is done');920promise_test(() => {921 let resolveStart;922 let controller;923 const ws = recordingWritableStream({924 start(c) {925 controller = c;926 return new Promise(resolve => {927 resolveStart = resolve;928 });929 }930 });931 const abortPromise = ws.abort('done');932 controller.error(error1);933 resolveStart();934 return abortPromise.then(() =>935 assert_array_equals(ws.events, ['abort', 'done'],936 'abort() should still be called if start() errors the controller'));937}, 'if start attempts to error the controller after abort() has been called, then it should lose');938promise_test(() => {939 const ws = recordingWritableStream({940 start() {941 return Promise.reject(error1);942 }943 });944 return ws.abort('done').then(() =>945 assert_array_equals(ws.events, ['abort', 'done'], 'abort() should still be called if start() rejects'));946}, 'stream abort() promise should still resolve if sink start() rejects');947promise_test(t => {948 const ws = new WritableStream();949 const writer = ws.getWriter();950 const writerReady1 = writer.ready;951 writer.abort('a');952 const writerReady2 = writer.ready;953 assert_not_equals(writerReady1, writerReady2, 'abort() should replace the ready promise with a rejected one');954 return Promise.all([writerReady1,955 promise_rejects(t, new TypeError(), writerReady2, 'writerReady2 should reject')]);956}, 'writer abort() during sink start() should replace the writer.ready promise synchronously');957promise_test(t => {958 const events = [];959 const ws = recordingWritableStream();960 const writer = ws.getWriter();961 const writePromise1 = writer.write(1);962 const abortPromise = writer.abort('a');963 const writePromise2 = writer.write(2);964 const closePromise = writer.close();965 writePromise1.catch(() => events.push('write1'));966 abortPromise.then(() => events.push('abort'));967 writePromise2.catch(() => events.push('write2'));968 closePromise.catch(() => events.push('close'));969 return Promise.all([970 promise_rejects(t, new TypeError(), writePromise1, 'first write() should reject'),971 abortPromise,972 promise_rejects(t, new TypeError(), writePromise2, 'second write() should reject'),973 promise_rejects(t, new TypeError(), closePromise, 'close() should reject')974 ])975 .then(() => {976 assert_array_equals(events, ['write2', 'write1', 'abort', 'close'],977 'promises should resolve in the standard order');978 assert_array_equals(ws.events, ['abort', 'a'], 'underlying sink write() should not be called');979 });980}, 'promises returned from other writer methods should be rejected when writer abort() happens during sink start()');981promise_test(t => {982 let writeReject;983 let controller;984 const ws = new WritableStream({985 write(chunk, c) {986 controller = c;987 return new Promise((resolve, reject) => {988 writeReject = reject;989 });990 }991 });992 const writer = ws.getWriter();993 return writer.ready.then(() => {994 const writePromise = writer.write('a');995 const abortPromise = writer.abort();996 controller.error(error1);997 writeReject(error2);998 return Promise.all([999 promise_rejects(t, error2, writePromise, 'write() should reject with error2'),1000 abortPromise1001 ]);1002 });1003}, 'abort() should succeed despite rejection from write');1004promise_test(t => {1005 let closeReject;1006 let controller;1007 const ws = new WritableStream({1008 start(c) {1009 controller = c;1010 },1011 close() {1012 return new Promise((resolve, reject) => {1013 closeReject = reject;1014 });1015 }1016 });1017 const writer = ws.getWriter();1018 return writer.ready.then(() => {1019 const closePromise = writer.close();1020 const abortPromise = writer.abort();1021 controller.error(error1);1022 closeReject(error2);1023 return Promise.all([1024 promise_rejects(t, error2, closePromise, 'close() should reject with error2'),1025 promise_rejects(t, error2, abortPromise, 'abort() should reject with error2')1026 ]);1027 });1028}, 'abort() should be rejected with the rejection returned from close()');1029promise_test(t => {1030 let rejectWrite;1031 const ws = recordingWritableStream({1032 write() {1033 return new Promise((resolve, reject) => {1034 rejectWrite = reject;1035 });1036 }1037 });1038 const writer = ws.getWriter();1039 return writer.ready.then(() => {1040 const writePromise = writer.write('1');1041 const abortPromise = writer.abort(error2);1042 rejectWrite(error1);1043 return Promise.all([1044 promise_rejects(t, error1, writePromise, 'write should reject'),1045 abortPromise,1046 promise_rejects(t, new TypeError(), writer.closed, 'closed should reject with TypeError')1047 ]);1048 }).then(() => {1049 assert_array_equals(ws.events, ['write', '1', 'abort', error2], 'abort sink method should be called');1050 });1051}, 'a rejecting sink.write() should not prevent sink.abort() from being called');1052promise_test(() => {1053 const ws = recordingWritableStream({1054 start() {1055 return Promise.reject(error1);1056 }1057 });1058 return ws.abort(error2)1059 .then(() => {1060 assert_array_equals(ws.events, ['abort', error2]);1061 });1062}, 'when start errors after stream abort(), underlying sink abort() should be called anyway');1063promise_test(t => {1064 const ws = new WritableStream();1065 const abortPromise1 = ws.abort();1066 const abortPromise2 = ws.abort();1067 return Promise.all([1068 abortPromise1,1069 promise_rejects(t, new TypeError(), abortPromise2, 'second abort() should reject')1070 ]);1071}, 'when calling abort() twice on the same stream, the second call should reject');1072promise_test(t => {1073 let controller;1074 let resolveWrite;1075 const ws = recordingWritableStream({1076 start(c) {1077 controller = c;1078 },1079 write() {1080 return new Promise(resolve => {1081 resolveWrite = resolve;1082 });1083 }1084 });1085 const writer = ws.getWriter();1086 return writer.ready.then(() => {1087 const writePromise = writer.write('chunk');1088 controller.error(error1);1089 const abortPromise = writer.abort(error2);1090 resolveWrite();1091 return Promise.all([1092 writePromise,1093 promise_rejects(t, error1, abortPromise, 'abort() should reject')1094 ]).then(() => {1095 assert_array_equals(ws.events, ['write', 'chunk'], 'sink abort() should not be called');1096 });1097 });1098}, 'sink abort() should not be called if stream was erroring due to controller.error() before abort() was called');1099promise_test(t => {1100 let resolveWrite;1101 let size = 1;1102 const ws = recordingWritableStream({1103 write() {1104 return new Promise(resolve => {1105 resolveWrite = resolve;1106 });1107 }1108 }, {1109 size() {1110 return size;1111 },1112 highWaterMark: 11113 });1114 const writer = ws.getWriter();1115 return writer.ready.then(() => {1116 const writePromise1 = writer.write('chunk1');1117 size = NaN;1118 const writePromise2 = writer.write('chunk2');1119 const abortPromise = writer.abort(error2);1120 resolveWrite();1121 return Promise.all([1122 writePromise1,1123 promise_rejects(t, new RangeError(), writePromise2, 'second write() should reject'),1124 promise_rejects(t, new RangeError(), abortPromise, 'abort() should reject')1125 ]).then(() => {1126 assert_array_equals(ws.events, ['write', 'chunk1'], 'sink abort() should not be called');1127 });1128 });1129}, 'sink abort() should not be called if stream was erroring due to bad strategy before abort() was called');...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 wpt.getTestResults(data.data.testId, function(err, data) {4 wpt.resolveWrite(data.data.median.firstView, function(err, data) {5 console.log(data);6 });7 });8});
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools('Albert Einstein');3wp.resolveWrite('Albert Einstein', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10{11 "extract": "Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. Einstein is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed \"the world's most famous equation\"). He received the 1921 Nobel Prize in Physics \"for his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect\", a pivotal step in the development of quantum theory.",
Using AI Code Generation
1var wptools = require('wptools');2wptools.resolveWrite('test.js', 'test2.js', function(err) {3 if(err) {4 console.log(err);5 }6});
Using AI Code Generation
1wptools.resolveWrite("Barack Obama", "en", function(err, resp) {2 console.log(resp);3});4{ title: 'Barack Obama',5 titles: { canonical: 'Barack Obama', normalized: 'Barack Obama', display: 'Barack Obama' },6 page_image: 'Barack Obama official portrait.jpg' }
Using AI Code Generation
1const wptools = require('wp-tools');2 .then(() => {3 console.log('File written successfully');4 wptools.resolveRead('nodejs.html')5 .then((data) => {6 console.log(data);7 })8 .catch((err) => {9 console.log(err);10 });11 })12 .catch((err) => {13 console.log(err);14 });15const wptools = require('wp-tools');16 .then(() => {17 console.log('File written successfully');18 wptools.resolveRead('nodejs.html')19 .then((data) => {20 console.log(data);21 })22 .catch((err) => {23 console.log(err);24 });25 })26 .catch((err) => {27 console.log(err);28 });29const wptools = require('wp-tools');30 .then((data) => {31 console.log(data);32 })33 .catch((err) => {34 console.log(err);35 });36### `resolve(url, filename)`37### `resolveRead(filename)`38### `resolveWrite(url, filename)`
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!