How to use pipeTo method in wpt

Best JavaScript code snippet using wpt

error-propagation-backward.any.js

Source:error-propagation-backward.any.js Github

copy

Full Screen

...12 start() {13 return Promise.reject(error1);14 }15 });16 return promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the same error')17 .then(() => {18 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);19 assert_array_equals(ws.events, []);20 });21}, 'Errors must be propagated backward: starts errored; preventCancel omitted; fulfilled cancel promise');22promise_test(t => {23 const rs = recordingReadableStream();24 const ws = recordingWritableStream({25 write() {26 return Promise.reject(error1);27 }28 });29 const writer = ws.getWriter();30 return promise_rejects(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')31 .then(() => promise_rejects(t, error1, writer.closed, 'writer.closed must reject with the write error'))32 .then(() => {33 writer.releaseLock();34 return promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the write error')35 .then(() => {36 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);37 assert_array_equals(ws.events, ['write', 'Hello']);38 });39 });40}, 'Errors must be propagated backward: becomes errored before piping due to write; preventCancel omitted; ' +41 'fulfilled cancel promise');42promise_test(t => {43 const rs = recordingReadableStream({44 cancel() {45 throw error2;46 }47 });48 const ws = recordingWritableStream({49 write() {50 return Promise.reject(error1);51 }52 });53 const writer = ws.getWriter();54 return promise_rejects(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')55 .then(() => promise_rejects(t, error1, writer.closed, 'writer.closed must reject with the write error'))56 .then(() => {57 writer.releaseLock();58 return promise_rejects(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the cancel error')59 .then(() => {60 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);61 assert_array_equals(ws.events, ['write', 'Hello']);62 });63 });64}, 'Errors must be propagated backward: becomes errored before piping due to write; preventCancel omitted; rejected ' +65 'cancel promise');66for (const falsy of [undefined, null, false, +0, -0, NaN, '']) {67 const stringVersion = Object.is(falsy, -0) ? '-0' : String(falsy);68 promise_test(t => {69 const rs = recordingReadableStream();70 const ws = recordingWritableStream({71 write() {72 return Promise.reject(error1);73 }74 });75 const writer = ws.getWriter();76 return promise_rejects(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')77 .then(() => promise_rejects(t, error1, writer.closed, 'writer.closed must reject with the write error'))78 .then(() => {79 writer.releaseLock();80 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: falsy }),81 'pipeTo must reject with the write error')82 .then(() => {83 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);84 assert_array_equals(ws.events, ['write', 'Hello']);85 });86 });87 }, `Errors must be propagated backward: becomes errored before piping due to write; preventCancel = ` +88 `${stringVersion} (falsy); fulfilled cancel promise`);89}90for (const truthy of [true, 'a', 1, Symbol(), { }]) {91 promise_test(t => {92 const rs = recordingReadableStream();93 const ws = recordingWritableStream({94 write() {95 return Promise.reject(error1);96 }97 });98 const writer = ws.getWriter();99 return promise_rejects(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')100 .then(() => promise_rejects(t, error1, writer.closed, 'writer.closed must reject with the write error'))101 .then(() => {102 writer.releaseLock();103 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: truthy }),104 'pipeTo must reject with the write error')105 .then(() => {106 assert_array_equals(rs.eventsWithoutPulls, []);107 assert_array_equals(ws.events, ['write', 'Hello']);108 });109 });110 }, `Errors must be propagated backward: becomes errored before piping due to write; preventCancel = ` +111 `${String(truthy)} (truthy)`);112}113promise_test(t => {114 const rs = recordingReadableStream();115 const ws = recordingWritableStream({116 write() {117 return Promise.reject(error1);118 }119 });120 const writer = ws.getWriter();121 return promise_rejects(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')122 .then(() => promise_rejects(t, error1, writer.closed, 'writer.closed must reject with the write error'))123 .then(() => {124 writer.releaseLock();125 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true, preventAbort: true }),126 'pipeTo must reject with the write error')127 .then(() => {128 assert_array_equals(rs.eventsWithoutPulls, []);129 assert_array_equals(ws.events, ['write', 'Hello']);130 });131 });132}, 'Errors must be propagated backward: becomes errored before piping due to write, preventCancel = true; ' +133 'preventAbort = true');134promise_test(t => {135 const rs = recordingReadableStream();136 const ws = recordingWritableStream({137 write() {138 return Promise.reject(error1);139 }140 });141 const writer = ws.getWriter();142 return promise_rejects(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')143 .then(() => promise_rejects(t, error1, writer.closed, 'writer.closed must reject with the write error'))144 .then(() => {145 writer.releaseLock();146 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true, preventAbort: true, preventClose: true }),147 'pipeTo must reject with the write error')148 .then(() => {149 assert_array_equals(rs.eventsWithoutPulls, []);150 assert_array_equals(ws.events, ['write', 'Hello']);151 });152 });153}, 'Errors must be propagated backward: becomes errored before piping due to write; preventCancel = true, ' +154 'preventAbort = true, preventClose = true');155promise_test(t => {156 const rs = recordingReadableStream({157 start(controller) {158 controller.enqueue('Hello');159 }160 });161 const ws = recordingWritableStream({162 write() {163 throw error1;164 }165 });166 return promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the same error').then(() => {167 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);168 assert_array_equals(ws.events, ['write', 'Hello']);169 });170}, 'Errors must be propagated backward: becomes errored during piping due to write; preventCancel omitted; fulfilled ' +171 'cancel promise');172promise_test(t => {173 const rs = recordingReadableStream({174 start(controller) {175 controller.enqueue('Hello');176 },177 cancel() {178 throw error2;179 }180 });181 const ws = recordingWritableStream({182 write() {183 throw error1;184 }185 });186 return promise_rejects(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the cancel error').then(() => {187 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);188 assert_array_equals(ws.events, ['write', 'Hello']);189 });190}, 'Errors must be propagated backward: becomes errored during piping due to write; preventCancel omitted; rejected ' +191 'cancel promise');192promise_test(t => {193 const rs = recordingReadableStream({194 start(controller) {195 controller.enqueue('Hello');196 }197 });198 const ws = recordingWritableStream({199 write() {200 throw error1;201 }202 });203 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true }), 'pipeTo must reject with the same error')204 .then(() => {205 assert_array_equals(rs.eventsWithoutPulls, []);206 assert_array_equals(ws.events, ['write', 'Hello']);207 });208}, 'Errors must be propagated backward: becomes errored during piping due to write; preventCancel = true');209promise_test(t => {210 const rs = recordingReadableStream({211 start(controller) {212 controller.enqueue('a');213 controller.enqueue('b');214 controller.enqueue('c');215 }216 });217 const ws = recordingWritableStream({218 write() {219 if (ws.events.length > 2) {220 return delay(0).then(() => {221 throw error1;222 });223 }224 return undefined;225 }226 });227 return promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the same error').then(() => {228 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);229 assert_array_equals(ws.events, ['write', 'a', 'write', 'b']);230 });231}, 'Errors must be propagated backward: becomes errored during piping due to write, but async; preventCancel = ' +232 'false; fulfilled cancel promise');233promise_test(t => {234 const rs = recordingReadableStream({235 start(controller) {236 controller.enqueue('a');237 controller.enqueue('b');238 controller.enqueue('c');239 },240 cancel() {241 throw error2;242 }243 });244 const ws = recordingWritableStream({245 write() {246 if (ws.events.length > 2) {247 return delay(0).then(() => {248 throw error1;249 });250 }251 return undefined;252 }253 });254 return promise_rejects(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the cancel error').then(() => {255 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);256 assert_array_equals(ws.events, ['write', 'a', 'write', 'b']);257 });258}, 'Errors must be propagated backward: becomes errored during piping due to write, but async; preventCancel = ' +259 'false; rejected cancel promise');260promise_test(t => {261 const rs = recordingReadableStream({262 start(controller) {263 controller.enqueue('a');264 controller.enqueue('b');265 controller.enqueue('c');266 }267 });268 const ws = recordingWritableStream({269 write() {270 if (ws.events.length > 2) {271 return delay(0).then(() => {272 throw error1;273 });274 }275 return undefined;276 }277 });278 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true }), 'pipeTo must reject with the same error')279 .then(() => {280 assert_array_equals(rs.eventsWithoutPulls, []);281 assert_array_equals(ws.events, ['write', 'a', 'write', 'b']);282 });283}, 'Errors must be propagated backward: becomes errored during piping due to write, but async; preventCancel = true');284promise_test(t => {285 const rs = recordingReadableStream();286 const ws = recordingWritableStream();287 const pipePromise = promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the same error');288 t.step_timeout(() => ws.controller.error(error1), 10);289 return pipePromise.then(() => {290 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);291 assert_array_equals(ws.events, []);292 });293}, 'Errors must be propagated backward: becomes errored after piping; preventCancel omitted; fulfilled cancel promise');294promise_test(t => {295 const rs = recordingReadableStream({296 cancel() {297 throw error2;298 }299 });300 const ws = recordingWritableStream();301 const pipePromise = promise_rejects(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the cancel error');302 t.step_timeout(() => ws.controller.error(error1), 10);303 return pipePromise.then(() => {304 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);305 assert_array_equals(ws.events, []);306 });307}, 'Errors must be propagated backward: becomes errored after piping; preventCancel omitted; rejected cancel promise');308promise_test(t => {309 const rs = recordingReadableStream();310 const ws = recordingWritableStream();311 const pipePromise = promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true }),312 'pipeTo must reject with the same error');313 t.step_timeout(() => ws.controller.error(error1), 10);314 return pipePromise.then(() => {315 assert_array_equals(rs.eventsWithoutPulls, []);316 assert_array_equals(ws.events, []);317 });318}, 'Errors must be propagated backward: becomes errored after piping; preventCancel = true');319promise_test(t => {320 const rs = recordingReadableStream({321 start(controller) {322 controller.enqueue('a');323 controller.enqueue('b');324 controller.enqueue('c');325 controller.close();326 }327 });328 const ws = recordingWritableStream({329 write(chunk) {330 if (chunk === 'c') {331 return Promise.reject(error1);332 }333 return undefined;334 }335 });336 return promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the same error').then(() => {337 assert_array_equals(rs.eventsWithoutPulls, []);338 assert_array_equals(ws.events, ['write', 'a', 'write', 'b', 'write', 'c']);339 });340}, 'Errors must be propagated backward: becomes errored after piping due to last write; source is closed; ' +341 'preventCancel omitted (but cancel is never called)');342promise_test(t => {343 const rs = recordingReadableStream({344 start(controller) {345 controller.enqueue('a');346 controller.enqueue('b');347 controller.enqueue('c');348 controller.close();349 }350 });351 const ws = recordingWritableStream({352 write(chunk) {353 if (chunk === 'c') {354 return Promise.reject(error1);355 }356 return undefined;357 }358 });359 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true }), 'pipeTo must reject with the same error')360 .then(() => {361 assert_array_equals(rs.eventsWithoutPulls, []);362 assert_array_equals(ws.events, ['write', 'a', 'write', 'b', 'write', 'c']);363 });364}, 'Errors must be propagated backward: becomes errored after piping due to last write; source is closed; ' +365 'preventCancel = true');366promise_test(t => {367 const rs = recordingReadableStream();368 const ws = recordingWritableStream(undefined, new CountQueuingStrategy({ highWaterMark: 0 }));369 const pipePromise = promise_rejects(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the same error');370 t.step_timeout(() => ws.controller.error(error1), 10);371 return pipePromise.then(() => {372 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);373 assert_array_equals(ws.events, []);374 });375}, 'Errors must be propagated backward: becomes errored after piping; dest never desires chunks; preventCancel = ' +376 'false; fulfilled cancel promise');377promise_test(t => {378 const rs = recordingReadableStream({379 cancel() {380 throw error2;381 }382 });383 const ws = recordingWritableStream(undefined, new CountQueuingStrategy({ highWaterMark: 0 }));384 const pipePromise = promise_rejects(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the cancel error');385 t.step_timeout(() => ws.controller.error(error1), 10);386 return pipePromise.then(() => {387 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);388 assert_array_equals(ws.events, []);389 });390}, 'Errors must be propagated backward: becomes errored after piping; dest never desires chunks; preventCancel = ' +391 'false; rejected cancel promise');392promise_test(t => {393 const rs = recordingReadableStream();394 const ws = recordingWritableStream(undefined, new CountQueuingStrategy({ highWaterMark: 0 }));395 const pipePromise = promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true }),396 'pipeTo must reject with the same error');397 t.step_timeout(() => ws.controller.error(error1), 10);398 return pipePromise.then(() => {399 assert_array_equals(rs.eventsWithoutPulls, []);400 assert_array_equals(ws.events, []);401 });402}, 'Errors must be propagated backward: becomes errored after piping; dest never desires chunks; preventCancel = ' +403 'true');404promise_test(() => {405 const rs = recordingReadableStream();406 const ws = recordingWritableStream();407 ws.abort(error1);408 return rs.pipeTo(ws).then(409 () => assert_unreached('the promise must not fulfill'),410 err => {411 assert_equals(err, error1, 'the promise must reject with error1');412 assert_array_equals(rs.eventsWithoutPulls, ['cancel', err]);413 assert_array_equals(ws.events, ['abort', error1]);414 }415 );416}, 'Errors must be propagated backward: becomes errored before piping via abort; preventCancel omitted; fulfilled ' +417 'cancel promise');418promise_test(t => {419 const rs = recordingReadableStream({420 cancel() {421 throw error2;422 }423 });424 const ws = recordingWritableStream();425 ws.abort(error1);426 return promise_rejects(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the cancel error')427 .then(() => {428 return ws.getWriter().closed.then(429 () => assert_unreached('the promise must not fulfill'),430 err => {431 assert_equals(err, error1, 'the promise must reject with error1');432 assert_array_equals(rs.eventsWithoutPulls, ['cancel', err]);433 assert_array_equals(ws.events, ['abort', error1]);434 }435 );436 });437}, 'Errors must be propagated backward: becomes errored before piping via abort; preventCancel omitted; rejected ' +438 'cancel promise');439promise_test(t => {440 const rs = recordingReadableStream();441 const ws = recordingWritableStream();442 ws.abort(error1);443 return promise_rejects(t, error1, rs.pipeTo(ws, { preventCancel: true })).then(() => {444 assert_array_equals(rs.eventsWithoutPulls, []);445 assert_array_equals(ws.events, ['abort', error1]);446 });447}, 'Errors must be propagated backward: becomes errored before piping via abort; preventCancel = true');448promise_test(t => {449 const rs = recordingReadableStream();450 let resolveWriteCalled;451 const writeCalledPromise = new Promise(resolve => {452 resolveWriteCalled = resolve;453 });454 const ws = recordingWritableStream({455 write() {456 resolveWriteCalled();457 return flushAsyncEvents();458 }459 });460 const pipePromise = rs.pipeTo(ws);461 rs.controller.enqueue('a');462 return writeCalledPromise.then(() => {463 ws.controller.error(error1);464 return promise_rejects(t, error1, pipePromise);465 }).then(() => {466 assert_array_equals(rs.eventsWithoutPulls, ['cancel', error1]);467 assert_array_equals(ws.events, ['write', 'a']);468 });...

Full Screen

Full Screen

abort.any.js

Source:abort.any.js Github

copy

Full Screen

...19for (const invalidSignal of [null, 'AbortSignal', true, -1, Object.create(AbortSignal.prototype)]) {20 promise_test(t => {21 const rs = recordingReadableStream(errorOnPull, hwm0);22 const ws = recordingWritableStream();23 return promise_rejects(t, new TypeError(), rs.pipeTo(ws, { signal: invalidSignal }), 'pipeTo should reject')24 .then(() => {25 assert_equals(rs.events.length, 0, 'no ReadableStream methods should have been called');26 assert_equals(ws.events.length, 0, 'no WritableStream methods should have been called');27 });28 }, `a signal argument '${invalidSignal}' should cause pipeTo() to reject`);29}30promise_test(t => {31 const rs = recordingReadableStream(errorOnPull, hwm0);32 const ws = new WritableStream();33 const abortController = new AbortController();34 const signal = abortController.signal;35 abortController.abort();36 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject')37 .then(() => Promise.all([38 rs.getReader().closed,39 promise_rejects(t, 'AbortError', ws.getWriter().closed, 'writer.closed should reject')40 ]))41 .then(() => {42 assert_equals(rs.events.length, 2, 'cancel should have been called');43 assert_equals(rs.events[0], 'cancel', 'first event should be cancel');44 assert_equals(rs.events[1].name, 'AbortError', 'the argument to cancel should be an AbortError');45 assert_equals(rs.events[1].constructor.name, 'DOMException',46 'the argument to cancel should be a DOMException');47 });48}, 'an aborted signal should cause the writable stream to reject with an AbortError');49promise_test(() => {50 let error;51 const rs = recordingReadableStream(errorOnPull, hwm0);52 const ws = new WritableStream();53 const abortController = new AbortController();54 const signal = abortController.signal;55 abortController.abort();56 return rs.pipeTo(ws, { signal })57 .catch(e => {58 error = e;59 })60 .then(() => Promise.all([61 rs.getReader().closed,62 ws.getWriter().closed.catch(e => {63 assert_equals(e, error, 'the writable should be errored with the same object');64 })65 ]))66 .then(() => {67 assert_equals(rs.events.length, 2, 'cancel should have been called');68 assert_equals(rs.events[0], 'cancel', 'first event should be cancel');69 assert_equals(rs.events[1], error, 'the readable should be canceled with the same object');70 });71}, 'all the AbortError objects should be the same object');72promise_test(t => {73 const rs = recordingReadableStream(errorOnPull, hwm0);74 const ws = new WritableStream();75 const abortController = new AbortController();76 const signal = abortController.signal;77 abortController.abort();78 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal, preventCancel: true }), 'pipeTo should reject')79 .then(() => assert_equals(rs.events.length, 0, 'cancel should not be called'));80}, 'preventCancel should prevent canceling the readable');81promise_test(t => {82 const rs = new ReadableStream(errorOnPull, hwm0);83 const ws = recordingWritableStream();84 const abortController = new AbortController();85 const signal = abortController.signal;86 abortController.abort();87 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal, preventAbort: true }), 'pipeTo should reject')88 .then(() => {89 assert_equals(ws.events.length, 0, 'writable should not have been aborted');90 return ws.getWriter().ready;91 });92}, 'preventAbort should prevent aborting the readable');93promise_test(t => {94 const rs = recordingReadableStream(errorOnPull, hwm0);95 const ws = recordingWritableStream();96 const abortController = new AbortController();97 const signal = abortController.signal;98 abortController.abort();99 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal, preventCancel: true, preventAbort: true }),100 'pipeTo should reject')101 .then(() => {102 assert_equals(rs.events.length, 0, 'cancel should not be called');103 assert_equals(ws.events.length, 0, 'writable should not have been aborted');104 return ws.getWriter().ready;105 });106}, 'preventCancel and preventAbort should prevent canceling the readable and aborting the readable');107promise_test(t => {108 const rs = new ReadableStream({109 start(controller) {110 controller.enqueue('a');111 controller.enqueue('b');112 controller.close();113 }114 });115 const abortController = new AbortController();116 const signal = abortController.signal;117 const ws = recordingWritableStream({118 write() {119 abortController.abort();120 }121 });122 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject')123 .then(() => {124 assert_equals(ws.events.length, 4, 'only chunk "a" should have been written');125 assert_array_equals(ws.events.slice(0, 3), ['write', 'a', 'abort'], 'events should match');126 assert_equals(ws.events[3].name, 'AbortError', 'abort reason should be an AbortError');127 });128}, 'abort should prevent further reads');129promise_test(t => {130 let readController;131 const rs = new ReadableStream({132 start(c) {133 readController = c;134 c.enqueue('a');135 c.enqueue('b');136 }137 });138 const abortController = new AbortController();139 const signal = abortController.signal;140 let resolveWrite;141 const writePromise = new Promise(resolve => {142 resolveWrite = resolve;143 });144 const ws = recordingWritableStream({145 write() {146 return writePromise;147 }148 }, new CountQueuingStrategy({ highWaterMark: Infinity }));149 const pipeToPromise = rs.pipeTo(ws, { signal });150 return delay(0).then(() => {151 abortController.abort();152 readController.close(); // Make sure the test terminates when signal is not implemented.153 resolveWrite();154 return promise_rejects(t, 'AbortError', pipeToPromise, 'pipeTo should reject');155 }).then(() => {156 assert_equals(ws.events.length, 6, 'chunks "a" and "b" should have been written');157 assert_array_equals(ws.events.slice(0, 5), ['write', 'a', 'write', 'b', 'abort'], 'events should match');158 assert_equals(ws.events[5].name, 'AbortError', 'abort reason should be an AbortError');159 });160}, 'all pending writes should complete on abort');161promise_test(t => {162 const rs = new ReadableStream({163 pull(controller) {164 controller.error('failed to abort');165 },166 cancel() {167 return Promise.reject(error1);168 }169 }, hwm0);170 const ws = new WritableStream();171 const abortController = new AbortController();172 const signal = abortController.signal;173 abortController.abort();174 return promise_rejects(t, error1, rs.pipeTo(ws, { signal }), 'pipeTo should reject');175}, 'a rejection from underlyingSource.cancel() should be returned by pipeTo()');176promise_test(t => {177 const rs = new ReadableStream(errorOnPull, hwm0);178 const ws = new WritableStream({179 abort() {180 return Promise.reject(error1);181 }182 });183 const abortController = new AbortController();184 const signal = abortController.signal;185 abortController.abort();186 return promise_rejects(t, error1, rs.pipeTo(ws, { signal }), 'pipeTo should reject');187}, 'a rejection from underlyingSink.abort() should be returned by pipeTo()');188promise_test(t => {189 const events = [];190 const rs = new ReadableStream({191 pull(controller) {192 controller.error('failed to abort');193 },194 cancel() {195 events.push('cancel');196 return Promise.reject(error1);197 }198 }, hwm0);199 const ws = new WritableStream({200 abort() {201 events.push('abort');202 return Promise.reject(error2);203 }204 });205 const abortController = new AbortController();206 const signal = abortController.signal;207 abortController.abort();208 return promise_rejects(t, error2, rs.pipeTo(ws, { signal }), 'pipeTo should reject')209 .then(() => assert_array_equals(events, ['abort', 'cancel'], 'abort() should be called before cancel()'));210}, 'a rejection from underlyingSink.abort() should be preferred to one from underlyingSource.cancel()');211promise_test(t => {212 const rs = new ReadableStream({213 start(controller) {214 controller.close();215 }216 });217 const ws = new WritableStream();218 const abortController = new AbortController();219 const signal = abortController.signal;220 abortController.abort();221 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');222}, 'abort signal takes priority over closed readable');223promise_test(t => {224 const rs = new ReadableStream({225 start(controller) {226 controller.error(error1);227 }228 });229 const ws = new WritableStream();230 const abortController = new AbortController();231 const signal = abortController.signal;232 abortController.abort();233 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');234}, 'abort signal takes priority over errored readable');235promise_test(t => {236 const rs = new ReadableStream({237 pull(controller) {238 controller.error('failed to abort');239 }240 }, hwm0);241 const ws = new WritableStream();242 const abortController = new AbortController();243 const signal = abortController.signal;244 abortController.abort();245 const writer = ws.getWriter();246 return writer.close().then(() => {247 writer.releaseLock();248 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');249 });250}, 'abort signal takes priority over closed writable');251promise_test(t => {252 const rs = new ReadableStream({253 pull(controller) {254 controller.error('failed to abort');255 }256 }, hwm0);257 const ws = new WritableStream({258 start(controller) {259 controller.error(error1);260 }261 });262 const abortController = new AbortController();263 const signal = abortController.signal;264 abortController.abort();265 return promise_rejects(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');266}, 'abort signal takes priority over errored writable');267promise_test(() => {268 let readController;269 const rs = new ReadableStream({270 start(c) {271 readController = c;272 }273 });274 const ws = new WritableStream();275 const abortController = new AbortController();276 const signal = abortController.signal;277 const pipeToPromise = rs.pipeTo(ws, { signal, preventClose: true });278 readController.close();279 return Promise.resolve().then(() => {280 abortController.abort();281 return pipeToPromise;282 }).then(() => ws.getWriter().write('this should succeed'));283}, 'abort should do nothing after the readable is closed');284promise_test(t => {285 let readController;286 const rs = new ReadableStream({287 start(c) {288 readController = c;289 }290 });291 const ws = new WritableStream();292 const abortController = new AbortController();293 const signal = abortController.signal;294 const pipeToPromise = rs.pipeTo(ws, { signal, preventAbort: true });295 readController.error(error1);296 return Promise.resolve().then(() => {297 abortController.abort();298 return promise_rejects(t, error1, pipeToPromise, 'pipeTo should reject');299 }).then(() => ws.getWriter().write('this should succeed'));300}, 'abort should do nothing after the readable is errored');301promise_test(t => {302 let readController;303 const rs = new ReadableStream({304 start(c) {305 readController = c;306 }307 });308 let resolveWrite;309 const writePromise = new Promise(resolve => {310 resolveWrite = resolve;311 });312 const ws = new WritableStream({313 write() {314 readController.error(error1);315 return writePromise;316 }317 });318 const abortController = new AbortController();319 const signal = abortController.signal;320 const pipeToPromise = rs.pipeTo(ws, { signal, preventAbort: true });321 readController.enqueue('a');322 return delay(0).then(() => {323 abortController.abort();324 resolveWrite();325 return promise_rejects(t, error1, pipeToPromise, 'pipeTo should reject');326 }).then(() => ws.getWriter().write('this should succeed'));327}, 'abort should do nothing after the readable is errored, even with pending writes');328promise_test(t => {329 const rs = recordingReadableStream({330 pull(controller) {331 return delay(0).then(() => controller.close());332 }333 });334 let writeController;335 const ws = new WritableStream({336 start(c) {337 writeController = c;338 }339 });340 const abortController = new AbortController();341 const signal = abortController.signal;342 const pipeToPromise = rs.pipeTo(ws, { signal, preventCancel: true });343 return Promise.resolve().then(() => {344 writeController.error(error1);345 return Promise.resolve();346 }).then(() => {347 abortController.abort();348 return promise_rejects(t, error1, pipeToPromise, 'pipeTo should reject');349 }).then(() => {350 assert_array_equals(rs.events, ['pull'], 'cancel should not have been called');351 });...

Full Screen

Full Screen

pipe-through.js

Source:pipe-through.js Github

copy

Full Screen

...5}6test(() => {7 let pipeToArguments;8 const thisValue = {9 pipeTo() {10 pipeToArguments = arguments;11 }12 };13 const input = { readable: {}, writable: {} };14 const options = {};15 const result = ReadableStream.prototype.pipeThrough.call(thisValue, input, options);16 assert_array_equals(pipeToArguments, [input.writable, options],17 'correct arguments should be passed to thisValue.pipeTo');18 assert_equals(result, input.readable, 'return value should be the passed readable property');19}, 'ReadableStream.prototype.pipeThrough should work generically on its this and its arguments');20test(() => {21 const thisValue = {22 pipeTo() {23 assert_unreached('pipeTo should not be called');24 }25 };26 methodThrows(ReadableStream.prototype, 'pipeThrough', thisValue, [undefined, {}]);27 methodThrows(ReadableStream.prototype, 'pipeThrough', thisValue, [null, {}]);28}, 'ReadableStream.prototype.pipeThrough should throw when its first argument is not convertible to an object');29test(() => {30 const args = [{ readable: {}, writable: {} }, {}];31 methodThrows(ReadableStream.prototype, 'pipeThrough', undefined, args);32 methodThrows(ReadableStream.prototype, 'pipeThrough', null, args);33 methodThrows(ReadableStream.prototype, 'pipeThrough', 1, args);34 methodThrows(ReadableStream.prototype, 'pipeThrough', { pipeTo: 'test' }, args);35}, 'ReadableStream.prototype.pipeThrough should throw when "this" has no pipeTo method');36test(() => {37 const error = new Error('potato');38 const throwingPipeTo = {39 get pipeTo() {40 throw error;41 }42 };43 assert_throws(error,44 () => ReadableStream.prototype.pipeThrough.call(throwingPipeTo, { readable: { }, writable: { } }, {}),45 'pipeThrough should rethrow the error thrown by pipeTo');46 const thisValue = {47 pipeTo() {48 assert_unreached('pipeTo should not be called');49 }50 };51 const throwingWritable = {52 readable: {},53 get writable() {54 throw error;55 }56 };57 assert_throws(error,58 () => ReadableStream.prototype.pipeThrough.call(thisValue, throwingWritable, {}),59 'pipeThrough should rethrow the error thrown by the writable getter');60 const throwingReadable = {61 get readable() {62 throw error;63 },64 writable: {}65 };66 assert_throws(error,67 () => ReadableStream.prototype.pipeThrough.call(thisValue, throwingReadable, {}),68 'pipeThrough should rethrow the error thrown by the readable getter');69}, 'ReadableStream.prototype.pipeThrough should rethrow errors from accessing pipeTo, readable, or writable');70test(() => {71 let count = 0;72 const thisValue = {73 pipeTo() {74 ++count;75 }76 };77 ReadableStream.prototype.pipeThrough.call(thisValue, { readable: {}, writable: {} });78 ReadableStream.prototype.pipeThrough.call(thisValue, { readable: {} }, {});79 ReadableStream.prototype.pipeThrough.call(thisValue, { writable: {} }, {});80 assert_equals(count, 3, 'pipeTo was called 3 times');81}, 'ReadableStream.prototype.pipeThrough should work with missing readable, writable, or options');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 var testId = data.data.testId;4 wpt.getTestResults(testId, function(err, data) {5 var jsonUrl = data.data.jsonUrl;6 var json = wpt.pipeTo(jsonUrl, 'json');7 console.log(json);8 });9});101. Fork it (

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.log(err);6 console.log(data);7 wpt.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.log(err);9 console.log(data);10 });11});12{ statusCode: 400,13 { statusCode: 400,

Full Screen

Using AI Code Generation

copy

Full Screen

1const { WritableStream } = require('stream/web');2const { ReadableStream } = require('stream/web');3const { TransformStream } = require('stream/web');4const { WritableStreamDefaultWriter } = require('stream/web');5const { ReadableStreamDefaultReader } = require('stream/web');6const { TransformStreamDefaultController } = require('stream/web');7const { TransformStreamDefaultControllerCallback, TransformStreamDefaultControllerEnqueueCallback, TransformStreamDefaultControllerErrorCallback, TransformStreamDefaultControllerTerminateCallback } = require('stream/web');8const { TransformStreamDefaultSourceCallback, TransformStreamDefaultSinkCallback, TransformStreamDefaultSourcePullCallback, TransformStreamDefaultSourceCancelCallback, TransformStreamDefaultSinkStartCallback, TransformStreamDefaultSinkWriteCallback, TransformStreamDefaultSinkCloseCallback, TransformStreamDefaultSinkAbortCallback } = require('stream/web');9const { ByteLengthQueuingStrategy } = require('stream/web');10const { CountQueuingStrategy } = require('stream/web');11const { AbortSignal } = require('abort-controller');12const { AbortController } = require('abort-controller');13const { WritableStreamDefaultController } = require('stream/web');14const { WritableStreamDefaultControllerCallback, WritableStreamDefaultControllerAbortCallback, WritableStreamDefaultControllerCloseCallback, WritableStreamDefaultControllerStartCallback, WritableStreamDefaultControllerWriteCallback } = require('stream/web');15const { WritableStreamDefaultWriterCallback, WritableStreamDefaultWriterCloseCallback, WritableStreamDefaultWriterReleaseCallback, WritableStreamDefaultWriterAbortCallback, WritableStreamDefaultWriterWriteCallback, WritableStreamDefaultWriterGetDesiredSizeCallback } = require('stream/web');16const { ReadableStreamDefaultController } = require('stream/web');17const { ReadableStreamDefaultControllerCallback, ReadableStreamDefaultControllerCancelCallback, ReadableStreamDefaultControllerPullCallback, ReadableStreamDefaultControllerStartCallback } = require('stream/web');18const { ReadableStreamDefaultReaderCallback, ReadableStreamDefaultReaderCancelCallback, ReadableStreamDefaultReaderReadCallback, ReadableStreamDefaultReaderReleaseCallback } = require('stream/web');19const { WritableStreamDefaultWriterCloseWithErrorPropagation, WritableStreamDefaultWriterRelease, WritableStreamDefaultWriterWriteWithErrorPropagation, WritableStreamDefaultWriterEnsureReadyPromiseRejected } = require('stream/web');20const { WritableStreamAbort, WritableStreamDefaultControllerError, WritableStreamDefaultControllerGetBack

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const fs = require('fs');3const page = wptools.page('Barack Obama');4page.pipeTo(fs.createWriteStream('barack_obama.json'));5const wptools = require('wptools');6const fs = require('fs');7const page = wptools.page('Barack Obama');8page.getCategories().then(function (data) {9 const categories = data.categories;10 console.log(categories);11});12const wptools = require('wptools');13const fs = require('fs');14const page = wptools.page('Barack Obama');15page.getLinks().then(function (data) {16 const links = data.links;17 console.log(links);18});19const wptools = require('wptools');20const fs = require('fs');21const page = wptools.page('Barack Obama');22page.getImages().then(function (data) {23 const images = data.images;24 console.log(images);25});26const wptools = require('wptools');27const fs = require('fs');28const page = wptools.page('Barack Obama');29page.getReferences().then(function (data) {30 const references = data.references;31 console.log(references);32});33const wptools = require('wptools');34const fs = require('fs');35const page = wptools.page('Barack Obama');36page.getInfobox().then(function (data) {37 const infobox = data.infobox;38 console.log(infobox);39});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful