Best JavaScript code snippet using wpt
abort.any.js
Source:abort.any.js
...32 const ws = new WritableStream();33 const abortController = new AbortController();34 const signal = abortController.signal;35 abortController.abort();36 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject')37 .then(() => Promise.all([38 rs.getReader().closed,39 promise_rejects_dom(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_dom(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_dom(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_dom(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_dom(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_dom(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_exactly(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_exactly(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_exactly(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_dom(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_dom(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_dom(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_dom(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(() => {...
aflprep_abort.any.js
Source:aflprep_abort.any.js
...25 const ws = new WritableStream();26 const abortController = new AbortController();27 const signal = abortController.signal;28 abortController.abort();29 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject')30 .then(() => Promise.all([31 rs.getReader().closed,32 promise_rejects_dom(t, 'AbortError', ws.getWriter().closed, 'writer.closed should reject')33 ]))34 .then(() => {35 assert_equals(rs.events.length, 2, 'cancel should have been called');36 assert_equals(rs.events[0], 'cancel', 'first event should be cancel');37 assert_equals(rs.events[1].name, 'AbortError', 'the argument to cancel should be an AbortError');38 assert_equals(rs.events[1].constructor.name, 'DOMException',39 'the argument to cancel should be a DOMException');40 });41}, 'an aborted signal should cause the writable stream to reject with an AbortError');42promise_test(() => {43 let error;44 const rs = recordingReadableStream(errorOnPull, hwm0);45 const ws = new WritableStream();46 const abortController = new AbortController();47 const signal = abortController.signal;48 abortController.abort();49 return rs.pipeTo(ws, { signal })50 .catch(e => {51 error = e;52 })53 .then(() => Promise.all([54 rs.getReader().closed,55 ws.getWriter().closed.catch(e => {56 assert_equals(e, error, 'the writable should be errored with the same object');57 })58 ]))59 .then(() => {60 assert_equals(rs.events.length, 2, 'cancel should have been called');61 assert_equals(rs.events[0], 'cancel', 'first event should be cancel');62 assert_equals(rs.events[1], error, 'the readable should be canceled with the same object');63 });64}, 'all the AbortError objects should be the same object');65promise_test(t => {66 const rs = recordingReadableStream(errorOnPull, hwm0);67 const ws = new WritableStream();68 const abortController = new AbortController();69 const signal = abortController.signal;70 abortController.abort();71 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal, preventCancel: true }), 'pipeTo should reject')72 .then(() => assert_equals(rs.events.length, 0, 'cancel should not be called'));73}, 'preventCancel should prevent canceling the readable');74promise_test(t => {75 const rs = new ReadableStream(errorOnPull, hwm0);76 const ws = recordingWritableStream();77 const abortController = new AbortController();78 const signal = abortController.signal;79 abortController.abort();80 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal, preventAbort: true }), 'pipeTo should reject')81 .then(() => {82 assert_equals(ws.events.length, 0, 'writable should not have been aborted');83 return ws.getWriter().ready;84 });85}, 'preventAbort should prevent aborting the readable');86promise_test(t => {87 const rs = recordingReadableStream(errorOnPull, hwm0);88 const ws = recordingWritableStream();89 const abortController = new AbortController();90 const signal = abortController.signal;91 abortController.abort();92 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal, preventCancel: true, preventAbort: true }),93 'pipeTo should reject')94 .then(() => {95 assert_equals(rs.events.length, 0, 'cancel should not be called');96 assert_equals(ws.events.length, 0, 'writable should not have been aborted');97 return ws.getWriter().ready;98 });99}, 'preventCancel and preventAbort should prevent canceling the readable and aborting the readable');100promise_test(t => {101 const rs = new ReadableStream({102 start(controller) {103 controller.enqueue('a');104 controller.enqueue('b');105 controller.close();106 }107 });108 const abortController = new AbortController();109 const signal = abortController.signal;110 const ws = recordingWritableStream({111 write() {112 abortController.abort();113 }114 });115 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject')116 .then(() => {117 assert_equals(ws.events.length, 4, 'only chunk "a" should have been written');118 assert_array_equals(ws.events.slice(0, 3), ['write', 'a', 'abort'], 'events should match');119 assert_equals(ws.events[3].name, 'AbortError', 'abort reason should be an AbortError');120 });121}, 'abort should prevent further reads');122promise_test(t => {123 let readController;124 const rs = new ReadableStream({125 start(c) {126 readController = c;127 c.enqueue('a');128 c.enqueue('b');129 }130 });131 const abortController = new AbortController();132 const signal = abortController.signal;133 let resolveWrite;134 const writePromise = new Promise(resolve => {135 resolveWrite = resolve;136 });137 const ws = recordingWritableStream({138 write() {139 return writePromise;140 }141 }, new CountQueuingStrategy({ highWaterMark: Infinity }));142 const pipeToPromise = rs.pipeTo(ws, { signal });143 return delay(0).then(() => {144 abortController.abort();145 resolveWrite();146 return promise_rejects_dom(t, 'AbortError', pipeToPromise, 'pipeTo should reject');147 }).then(() => {148 assert_equals(ws.events.length, 6, 'chunks "a" and "b" should have been written');149 assert_array_equals(ws.events.slice(0, 5), ['write', 'a', 'write', 'b', 'abort'], 'events should match');150 assert_equals(ws.events[5].name, 'AbortError', 'abort reason should be an AbortError');151 });152}, 'all pending writes should complete on abort');153promise_test(t => {154 const rs = new ReadableStream({155 pull(controller) {156 controller.error('failed to abort');157 },158 cancel() {159 return Promise.reject(error1);160 }161 }, hwm0);162 const ws = new WritableStream();163 const abortController = new AbortController();164 const signal = abortController.signal;165 abortController.abort();166 return promise_rejects_exactly(t, error1, rs.pipeTo(ws, { signal }), 'pipeTo should reject');167}, 'a rejection from underlyingSource.cancel() should be returned by pipeTo()');168promise_test(t => {169 const rs = new ReadableStream(errorOnPull, hwm0);170 const ws = new WritableStream({171 abort() {172 return Promise.reject(error1);173 }174 });175 const abortController = new AbortController();176 const signal = abortController.signal;177 abortController.abort();178 return promise_rejects_exactly(t, error1, rs.pipeTo(ws, { signal }), 'pipeTo should reject');179}, 'a rejection from underlyingSink.abort() should be returned by pipeTo()');180promise_test(t => {181 const events = [];182 const rs = new ReadableStream({183 pull(controller) {184 controller.error('failed to abort');185 },186 cancel() {187 events.push('cancel');188 return Promise.reject(error1);189 }190 }, hwm0);191 const ws = new WritableStream({192 abort() {193 events.push('abort');194 return Promise.reject(error2);195 }196 });197 const abortController = new AbortController();198 const signal = abortController.signal;199 abortController.abort();200 return promise_rejects_exactly(t, error2, rs.pipeTo(ws, { signal }), 'pipeTo should reject')201 .then(() => assert_array_equals(events, ['abort', 'cancel'], 'abort() should be called before cancel()'));202}, 'a rejection from underlyingSink.abort() should be preferred to one from underlyingSource.cancel()');203promise_test(t => {204 const rs = new ReadableStream({205 start(controller) {206 controller.close();207 }208 });209 const ws = new WritableStream();210 const abortController = new AbortController();211 const signal = abortController.signal;212 abortController.abort();213 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');214}, 'abort signal takes priority over closed readable');215promise_test(t => {216 const rs = new ReadableStream({217 start(controller) {218 controller.error(error1);219 }220 });221 const ws = new WritableStream();222 const abortController = new AbortController();223 const signal = abortController.signal;224 abortController.abort();225 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');226}, 'abort signal takes priority over errored readable');227promise_test(t => {228 const rs = new ReadableStream({229 pull(controller) {230 controller.error('failed to abort');231 }232 }, hwm0);233 const ws = new WritableStream();234 const abortController = new AbortController();235 const signal = abortController.signal;236 abortController.abort();237 const writer = ws.getWriter();238 return writer.close().then(() => {239 writer.releaseLock();240 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');241 });242}, 'abort signal takes priority over closed writable');243promise_test(t => {244 const rs = new ReadableStream({245 pull(controller) {246 controller.error('failed to abort');247 }248 }, hwm0);249 const ws = new WritableStream({250 start(controller) {251 controller.error(error1);252 }253 });254 const abortController = new AbortController();255 const signal = abortController.signal;256 abortController.abort();257 return promise_rejects_dom(t, 'AbortError', rs.pipeTo(ws, { signal }), 'pipeTo should reject');258}, 'abort signal takes priority over errored writable');259promise_test(() => {260 let readController;261 const rs = new ReadableStream({262 start(c) {263 readController = c;264 }265 });266 const ws = new WritableStream();267 const abortController = new AbortController();268 const signal = abortController.signal;269 const pipeToPromise = rs.pipeTo(ws, { signal, preventClose: true });270 readController.close();271 return Promise.resolve().then(() => {...
Using AI Code Generation
1promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));2promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));3promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));4promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));5promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));6promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));7promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));8promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));9promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));10promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));11promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));12promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audioData));13promise_rejects_dom(t, 'InvalidStateError', audioCtx.decodeAudioData(audio
Using AI Code Generation
1promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');2promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');3promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');4promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');5promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');6promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');7promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');8promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');9promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');10promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');11promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should reject with InvalidStateError');12promise_rejects_dom(t, 'InvalidStateError', navigator.mediaDevices.getUserMedia({video: true, audio: true}), 'getUserMedia() should
Using AI Code Generation
1promise_rejects_dom(t, "InvalidStateError", new Promise(function(resolve, reject) {2 var request = new XMLHttpRequest();3 request.send();4 request.abort();5 request.send();6}), "Aborted send() should throw InvalidStateError");7function promise_rejects_dom(t, name, promise, desc) {8 return promise_rejects(t, function(e) {9 if (e instanceof DOMException) {10 return e.name === name;11 }12 return false;13 }, promise, desc);14}15function promise_rejects(t, constructor, promise, desc) {16 return promise.then(function() {17 assert_unreached(desc + " - promise unexpectedly fulfilled.");18 }, function(e) {19 if (typeof constructor === "function") {20 assert_true(e instanceof constructor, desc + " - Promise rejected with " + e + " - expected rejection with " + constructor.name);21 } else {22 assert_equals(e.name, constructor, desc + " - Promise rejected with " + e + " - expected rejection with " + constructor);23 }24 });25}
Using AI Code Generation
1promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');2promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');3promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');4promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');5promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');6promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');7promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');8promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');9promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');10promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');11promise_rejects_dom(t, 'InvalidStateError', videoElement.play(), 'play() should reject with InvalidStateError');
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!!