How to use error1 method in wpt

Best JavaScript code snippet using wpt

error-propagation-backward.any.js

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

copy

Full Screen

1// META: global=window,worker,jsshell2// META: script=../resources/test-utils.js3// META: script=../resources/recording-streams.js4'use strict';5const error1 = new Error('error1!');6error1.name = 'error1';7const error2 = new Error('error2!');8error2.name = 'error2';9promise_test(t => {10 const rs = recordingReadableStream();11 const ws = recordingWritableStream({12 start() {13 return Promise.reject(error1);14 }15 });16 return promise_rejects_exactly(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_exactly(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')31 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'writer.closed must reject with the write error'))32 .then(() => {33 writer.releaseLock();34 return promise_rejects_exactly(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_exactly(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')55 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'writer.closed must reject with the write error'))56 .then(() => {57 writer.releaseLock();58 return promise_rejects_exactly(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_exactly(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')77 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'writer.closed must reject with the write error'))78 .then(() => {79 writer.releaseLock();80 return promise_rejects_exactly(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_exactly(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')100 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'writer.closed must reject with the write error'))101 .then(() => {102 writer.releaseLock();103 return promise_rejects_exactly(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_exactly(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')122 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'writer.closed must reject with the write error'))123 .then(() => {124 writer.releaseLock();125 return promise_rejects_exactly(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_exactly(t, error1, writer.write('Hello'), 'writer.write() must reject with the write error')143 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'writer.closed must reject with the write error'))144 .then(() => {145 writer.releaseLock();146 return promise_rejects_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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_exactly(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

multiple-propagation.any.js

Source:multiple-propagation.any.js Github

copy

Full Screen

1// META: global=window,worker,jsshell2// META: script=../resources/test-utils.js3// META: script=../resources/recording-streams.js4'use strict';5const error1 = new Error('error1!');6error1.name = 'error1';7const error2 = new Error('error2!');8error2.name = 'error2';9function createErroredWritableStream(t) {10 return Promise.resolve().then(() => {11 const ws = recordingWritableStream({12 start(c) {13 c.error(error2);14 }15 });16 const writer = ws.getWriter();17 return promise_rejects_exactly(t, error2, writer.closed, 'the writable stream must be errored with error2')18 .then(() => {19 writer.releaseLock();20 assert_array_equals(ws.events, []);21 return ws;22 });23 });24}25promise_test(t => {26 const rs = recordingReadableStream({27 start(c) {28 c.error(error1);29 }30 });31 const ws = recordingWritableStream({32 start(c) {33 c.error(error2);34 }35 });36 // Trying to abort a stream that is erroring will give the writable's error37 return promise_rejects_exactly(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the writable stream\'s error').then(() => {38 assert_array_equals(rs.events, []);39 assert_array_equals(ws.events, []);40 return Promise.all([41 promise_rejects_exactly(t, error1, rs.getReader().closed, 'the readable stream must be errored with error1'),42 promise_rejects_exactly(t, error2, ws.getWriter().closed, 'the writable stream must be errored with error2')43 ]);44 });45}, 'Piping from an errored readable stream to an erroring writable stream');46promise_test(t => {47 const rs = recordingReadableStream({48 start(c) {49 c.error(error1);50 }51 });52 return createErroredWritableStream(t)53 .then(ws => promise_rejects_exactly(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the readable stream\'s error'))54 .then(() => {55 assert_array_equals(rs.events, []);56 return promise_rejects_exactly(t, error1, rs.getReader().closed, 'the readable stream must be errored with error1');57 });58}, 'Piping from an errored readable stream to an errored writable stream');59promise_test(t => {60 const rs = recordingReadableStream({61 start(c) {62 c.error(error1);63 }64 });65 const ws = recordingWritableStream({66 start(c) {67 c.error(error2);68 }69 });70 return promise_rejects_exactly(t, error1, rs.pipeTo(ws, { preventAbort: true }),71 'pipeTo must reject with the readable stream\'s error')72 .then(() => {73 assert_array_equals(rs.events, []);74 assert_array_equals(ws.events, []);75 return Promise.all([76 promise_rejects_exactly(t, error1, rs.getReader().closed, 'the readable stream must be errored with error1'),77 promise_rejects_exactly(t, error2, ws.getWriter().closed, 'the writable stream must be errored with error2')78 ]);79 });80}, 'Piping from an errored readable stream to an erroring writable stream; preventAbort = true');81promise_test(t => {82 const rs = recordingReadableStream({83 start(c) {84 c.error(error1);85 }86 });87 return createErroredWritableStream(t)88 .then(ws => promise_rejects_exactly(t, error1, rs.pipeTo(ws, { preventAbort: true }),89 'pipeTo must reject with the readable stream\'s error'))90 .then(() => {91 assert_array_equals(rs.events, []);92 return promise_rejects_exactly(t, error1, rs.getReader().closed, 'the readable stream must be errored with error1');93 });94}, 'Piping from an errored readable stream to an errored writable stream; preventAbort = true');95promise_test(t => {96 const rs = recordingReadableStream({97 start(c) {98 c.error(error1);99 }100 });101 const ws = recordingWritableStream();102 const writer = ws.getWriter();103 const closePromise = writer.close();104 writer.releaseLock();105 return promise_rejects_exactly(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the readable stream\'s error').then(() => {106 assert_array_equals(rs.events, []);107 assert_array_equals(ws.events, ['abort', error1]);108 return Promise.all([109 promise_rejects_exactly(t, error1, rs.getReader().closed, 'the readable stream must be errored with error1'),110 promise_rejects_exactly(t, error1, ws.getWriter().closed,111 'closed must reject with error1'),112 promise_rejects_exactly(t, error1, closePromise,113 'close() must reject with error1')114 ]);115 });116}, 'Piping from an errored readable stream to a closing writable stream');117promise_test(t => {118 const rs = recordingReadableStream({119 start(c) {120 c.error(error1);121 }122 });123 const ws = recordingWritableStream();124 const writer = ws.getWriter();125 const closePromise = writer.close();126 writer.releaseLock();127 return flushAsyncEvents().then(() => {128 return promise_rejects_exactly(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the readable stream\'s error').then(() => {129 assert_array_equals(rs.events, []);130 assert_array_equals(ws.events, ['close']);131 return Promise.all([132 promise_rejects_exactly(t, error1, rs.getReader().closed, 'the readable stream must be errored with error1'),133 ws.getWriter().closed,134 closePromise135 ]);136 });137 });138}, 'Piping from an errored readable stream to a closed writable stream');139promise_test(t => {140 const rs = recordingReadableStream({141 start(c) {142 c.close();143 }144 });145 const ws = recordingWritableStream({146 start(c) {147 c.error(error1);148 }149 });150 return promise_rejects_exactly(t, error1, rs.pipeTo(ws), 'pipeTo must reject with the writable stream\'s error').then(() => {151 assert_array_equals(rs.events, []);152 assert_array_equals(ws.events, []);153 return Promise.all([154 rs.getReader().closed,155 promise_rejects_exactly(t, error1, ws.getWriter().closed, 'the writable stream must be errored with error1')156 ]);157 });158}, 'Piping from a closed readable stream to an erroring writable stream');159promise_test(t => {160 const rs = recordingReadableStream({161 start(c) {162 c.close();163 }164 });165 return createErroredWritableStream(t)166 .then(ws => promise_rejects_exactly(t, error2, rs.pipeTo(ws), 'pipeTo must reject with the writable stream\'s error'))167 .then(() => {168 assert_array_equals(rs.events, []);169 return rs.getReader().closed;170 });171}, 'Piping from a closed readable stream to an errored writable stream');172promise_test(() => {173 const rs = recordingReadableStream({174 start(c) {175 c.close();176 }177 });178 const ws = recordingWritableStream();179 const writer = ws.getWriter();180 writer.close();181 writer.releaseLock();182 return rs.pipeTo(ws).then(() => {183 assert_array_equals(rs.events, []);184 assert_array_equals(ws.events, ['close']);185 return Promise.all([186 rs.getReader().closed,187 ws.getWriter().closed188 ]);189 });...

Full Screen

Full Screen

bad-underlying-sinks.any.js

Source:bad-underlying-sinks.any.js Github

copy

Full Screen

1// META: global=window,worker,jsshell2// META: script=../resources/test-utils.js3// META: script=../resources/recording-streams.js4'use strict';5const error1 = new Error('error1');6error1.name = 'error1';7test(() => {8 assert_throws_exactly(error1, () => {9 new WritableStream({10 get start() {11 throw error1;12 }13 });14 }, 'constructor should throw same error as throwing start getter');15 assert_throws_exactly(error1, () => {16 new WritableStream({17 start() {18 throw error1;19 }20 });21 }, 'constructor should throw same error as throwing start method');22 assert_throws_js(TypeError, () => {23 new WritableStream({24 start: 'not a function or undefined'25 });26 }, 'constructor should throw TypeError when passed a non-function start property');27 assert_throws_js(TypeError, () => {28 new WritableStream({29 start: { apply() {} }30 });31 }, 'constructor should throw TypeError when passed a non-function start property with an .apply method');32}, 'start: errors in start cause WritableStream constructor to throw');33promise_test(t => {34 const ws = recordingWritableStream({35 close() {36 throw error1;37 }38 });39 const writer = ws.getWriter();40 return promise_rejects_exactly(t, error1, writer.close(), 'close() promise must reject with the thrown error')41 .then(() => promise_rejects_exactly(t, error1, writer.ready, 'ready promise must reject with the thrown error'))42 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'closed promise must reject with the thrown error'))43 .then(() => {44 assert_array_equals(ws.events, ['close']);45 });46}, 'close: throwing method should cause writer close() and ready to reject');47promise_test(t => {48 const ws = recordingWritableStream({49 close() {50 return Promise.reject(error1);51 }52 });53 const writer = ws.getWriter();54 return promise_rejects_exactly(t, error1, writer.close(), 'close() promise must reject with the same error')55 .then(() => promise_rejects_exactly(t, error1, writer.ready, 'ready promise must reject with the same error'))56 .then(() => assert_array_equals(ws.events, ['close']));57}, 'close: returning a rejected promise should cause writer close() and ready to reject');58test(() => {59 assert_throws_exactly(error1, () => new WritableStream({60 get close() {61 throw error1;62 }63 }), 'constructor should throw');64}, 'close: throwing getter should cause constructor to throw');65test(() => {66 assert_throws_exactly(error1, () => new WritableStream({67 get write() {68 throw error1;69 }70 }), 'constructor should throw');71}, 'write: throwing getter should cause write() and closed to reject');72promise_test(t => {73 const ws = new WritableStream({74 write() {75 throw error1;76 }77 });78 const writer = ws.getWriter();79 return promise_rejects_exactly(t, error1, writer.write('a'), 'write should reject with the thrown error')80 .then(() => promise_rejects_exactly(t, error1, writer.closed, 'closed should reject with the thrown error'));81}, 'write: throwing method should cause write() and closed to reject');82promise_test(t => {83 let rejectSinkWritePromise;84 const ws = recordingWritableStream({85 write() {86 return new Promise((r, reject) => {87 rejectSinkWritePromise = reject;88 });89 }90 });91 return flushAsyncEvents().then(() => {92 const writer = ws.getWriter();93 const writePromise = writer.write('a');94 rejectSinkWritePromise(error1);95 return Promise.all([96 promise_rejects_exactly(t, error1, writePromise, 'writer write must reject with the same error'),97 promise_rejects_exactly(t, error1, writer.ready, 'ready promise must reject with the same error')98 ]);99 })100 .then(() => {101 assert_array_equals(ws.events, ['write', 'a']);102 });103}, 'write: returning a promise that becomes rejected after the writer write() should cause writer write() and ready ' +104 'to reject');105promise_test(t => {106 const ws = recordingWritableStream({107 write() {108 if (ws.events.length === 2) {109 return delay(0);110 }111 return Promise.reject(error1);112 }113 });114 const writer = ws.getWriter();115 // Do not wait for this; we want to test the ready promise when the stream is "full" (desiredSize = 0), but if we wait116 // then the stream will transition back to "empty" (desiredSize = 1)117 writer.write('a');118 const readyPromise = writer.ready;119 return promise_rejects_exactly(t, error1, writer.write('b'), 'second write must reject with the same error').then(() => {120 assert_equals(writer.ready, readyPromise,121 'the ready promise must not change, since the queue was full after the first write, so the pending one simply ' +122 'transitioned');123 return promise_rejects_exactly(t, error1, writer.ready, 'ready promise must reject with the same error');124 })125 .then(() => assert_array_equals(ws.events, ['write', 'a', 'write', 'b']));126}, 'write: returning a rejected promise (second write) should cause writer write() and ready to reject');127test(() => {128 assert_throws_js(TypeError, () => new WritableStream({129 start: 'test'130 }), 'constructor should throw');131}, 'start: non-function start method');132test(() => {133 assert_throws_js(TypeError, () => new WritableStream({134 write: 'test'135 }), 'constructor should throw');136}, 'write: non-function write method');137test(() => {138 assert_throws_js(TypeError, () => new WritableStream({139 close: 'test'140 }), 'constructor should throw');141}, 'close: non-function close method');142test(() => {143 assert_throws_js(TypeError, () => new WritableStream({144 abort: { apply() {} }145 }), 'constructor should throw');146}, 'abort: non-function abort method with .apply');147test(() => {148 assert_throws_exactly(error1, () => new WritableStream({149 get abort() {150 throw error1;151 }152 }), 'constructor should throw');153}, 'abort: throwing getter should cause abort() and closed to reject');154promise_test(t => {155 const abortReason = new Error('different string');156 const ws = new WritableStream({157 abort() {158 throw error1;159 }160 });161 const writer = ws.getWriter();162 return promise_rejects_exactly(t, error1, writer.abort(abortReason), 'abort should reject with the thrown error')163 .then(() => promise_rejects_exactly(t, abortReason, writer.closed, 'closed should reject with abortReason'));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.error1();3var wpt = require('wpt');4wpt.error2();5var wpt = require('wpt');6wpt.error3();7var wpt = require('wpt');8wpt.error4();9var wpt = require('wpt');10wpt.error5();11var wpt = require('wpt');12wpt.error6();13var wpt = require('wpt');14wpt.error7();15var wpt = require('wpt');16wpt.error8();17var wpt = require('wpt');18wpt.error9();19var wpt = require('wpt');20wpt.error10();21var wpt = require('wpt');22wpt.error11();23var wpt = require('wpt');24wpt.error12();25var wpt = require('wpt');26wpt.error13();27var wpt = require('wpt');28wpt.error14();29var wpt = require('wpt');30wpt.error15();31var wpt = require('wpt');32wpt.error16();33var wpt = require('wpt');34wpt.error17();35var wpt = require('wpt');36wpt.error18();37var wpt = require('wpt');38wpt.error19();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.error1('test');3wpt.error2('test');4wpt.error3('test');5wpt.error4('test');6wpt.error5('test');7wpt.error6('test');8wpt.error7('test');9wpt.error8('test');10wpt.error9('test');11wpt.error10('test');12wpt.error11('test');13wpt.error12('test');14wpt.error13('test');15wpt.error14('test');16wpt.error15('test');17wpt.error16('test');18wpt.error17('test');19wpt.error18('test');20wpt.error19('test');21wpt.error20('test');22wpt.error21('test');23wpt.error22('test');24wpt.error23('test');25wpt.error24('test');26wpt.error25('test');27wpt.error26('test');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.error1(function(error1){3 console.log(error1);4});5var wpt = require('wpt');6wpt.error2(function(error2){7 console.log(error2);8});9var wpt = require('wpt');10wpt.error3(function(error3){11 console.log(error3);12});13var wpt = require('wpt');14wpt.error4(function(error4){15 console.log(error4);16});17var wpt = require('wpt');18wpt.error5(function(error5){19 console.log(error5);20});21var wpt = require('wpt');22wpt.error6(function(error6){23 console.log(error6);24});25var wpt = require('wpt');26wpt.error7(function(error7){27 console.log(error7);28});29var wpt = require('wpt');30wpt.error8(function(error8){31 console.log(error8);32});33var wpt = require('wpt');34wpt.error9(function(error9){35 console.log(error9);36});37var wpt = require('wpt');38wpt.error10(function(error10){39 console.log(error10);40});41var wpt = require('wpt');42wpt.error11(function(error11){43 console.log(error11);44});45var wpt = require('wpt');46wpt.error12(function(error12){47 console.log(error12);48});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.error1(function(err,data){3 if(err){4 console.log(err);5 }6 else{7 console.log(data);8 }9});10wpt.error2(function(err,data){11 if(err){12 console.log(err);13 }14 else{15 console.log(data);16 }17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.error1();3wpt.error2();4 throw err;5 at Function.Module._resolveFilename (module.js:336:15)6 at Function.Module._load (module.js:278:25)7 at Module.require (module.js:365:17)8 at require (module.js:384:17)9 at Object.<anonymous> (/home/rohit/Desktop/nodejs/exports/test.js:1:13)10 at Module._compile (module.js:460:26)11 at Object.Module._extensions..js (module.js:478:10)12 at Module.load (module.js:355:32)13 at Function.Module._load (module.js:310:12)14 at Function.Module.runMain (module.js:501:10)15 at startup (node.js:129:16)16exports.error3 = function(message){17 console.log(message);18};19var wpt = require('wpt');20wpt.error3('This is a custom error message');21We can also export an object from a module. For example, we can export an object called error4 from the wpt module. The object will have a method called printMessage()

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.error1();3module.exports = {4 error1: function() {5 throw new Error('Error 1');6 }7}8var wpt = require('wpt');9try {10 wpt.error1();11} catch (e) {12 console.log(e);13}14Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt1 = new wpt('your wpt api key');3wpt1.error1('test error', function(err, data) {4 console.log(data);5});6var wpt = require('wpt');7var wpt1 = new wpt('your wpt api key');8wpt1.error2('test error', function(err, data) {9 console.log(data);10});11var wpt = require('wpt');12var wpt1 = new wpt('your wpt api key');13wpt1.error3('test error', function(err, data) {14 console.log(data);15});16var wpt = require('wpt');17var wpt1 = new wpt('your wpt api key');18wpt1.error4('test error', function(err, data) {19 console.log(data);20});21var wpt = require('wpt');22var wpt1 = new wpt('your wpt api key');23wpt1.error5('test error', function(err, data) {24 console.log(data);25});26var wpt = require('wpt');27var wpt1 = new wpt('your wpt api key');28wpt1.error6('test error', function(err, data) {29 console.log(data);30});31var wpt = require('wpt');32var wpt1 = new wpt('your wpt api key');33wpt1.error7('test error', function(err, data) {34 console.log(data);35});36var wpt = require('wpt');37var wpt1 = new wpt('your wpt api key');38wpt1.error8('test error', function(err, data) {39 console.log(data);40});41var wpt = require('wpt');42var wpt1 = new wpt('your wpt api key');43wpt1.error9('test error', function(err, data) {

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