Best JavaScript code snippet using wpt
bad-underlying-sources.js
Source:bad-underlying-sources.js
1'use strict';2if (self.importScripts) {3 self.importScripts('/resources/testharness.js');4}5test(() => {6 const theError = new Error('a unique string');7 assert_throws(theError, () => {8 new ReadableStream({9 get start() {10 throw theError;11 }12 });13 }, 'constructing the stream should re-throw the error');14}, 'Underlying source start: throwing getter');15test(() => {16 const theError = new Error('a unique string');17 assert_throws(theError, () => {18 new ReadableStream({19 start() {20 throw theError;21 }22 });23 }, 'constructing the stream should re-throw the error');24}, 'Underlying source start: throwing method');25test(() => {26 const theError = new Error('a unique string');27 assert_throws(theError, () => new ReadableStream({28 get pull() {29 throw theError;30 }31 }), 'constructor should throw');32}, 'Underlying source: throwing pull getter (initial pull)');33promise_test(t => {34 const theError = new Error('a unique string');35 const rs = new ReadableStream({36 pull() {37 throw theError;38 }39 });40 return promise_rejects(t, theError, rs.getReader().closed);41}, 'Underlying source: throwing pull method (initial pull)');42promise_test(t => {43 const theError = new Error('a unique string');44 let counter = 0;45 const rs = new ReadableStream({46 get pull() {47 ++counter;48 if (counter === 1) {49 return c => c.enqueue('a');50 }51 throw theError;52 }53 });54 const reader = rs.getReader();55 return Promise.all([56 reader.read().then(r => {57 assert_object_equals(r, { value: 'a', done: false }, 'the first chunk read should be correct');58 }),59 reader.read().then(r => {60 assert_object_equals(r, { value: 'a', done: false }, 'the second chunk read should be correct');61 assert_equals(counter, 1, 'counter should be 1');62 })63 ]);64}, 'Underlying source pull: throwing getter (second pull does not result in a second get)');65promise_test(t => {66 const theError = new Error('a unique string');67 let counter = 0;68 const rs = new ReadableStream({69 pull(c) {70 ++counter;71 if (counter === 1) {72 c.enqueue('a');73 return;74 }75 throw theError;76 }77 });78 const reader = rs.getReader();79 return Promise.all([80 reader.read().then(r => {81 assert_object_equals(r, { value: 'a', done: false }, 'the chunk read should be correct');82 }),83 promise_rejects(t, theError, reader.closed)84 ]);85}, 'Underlying source pull: throwing method (second pull)');86test(() => {87 const theError = new Error('a unique string');88 assert_throws(theError, () => new ReadableStream({89 get cancel() {90 throw theError;91 }92 }), 'constructor should throw');93}, 'Underlying source cancel: throwing getter');94promise_test(t => {95 const theError = new Error('a unique string');96 const rs = new ReadableStream({97 cancel() {98 throw theError;99 }100 });101 return promise_rejects(t, theError, rs.cancel());102}, 'Underlying source cancel: throwing method');103promise_test(() => {104 let controller;105 const rs = new ReadableStream({106 start(c) {107 controller = c;108 }109 });110 rs.cancel();111 assert_throws(new TypeError(), () => controller.enqueue('a'), 'Calling enqueue after canceling should throw');112 return rs.getReader().closed;113}, 'Underlying source: calling enqueue on an empty canceled stream should throw');114promise_test(() => {115 let controller;116 const rs = new ReadableStream({117 start(c) {118 c.enqueue('a');119 c.enqueue('b');120 controller = c;121 }122 });123 rs.cancel();124 assert_throws(new TypeError(), () => controller.enqueue('c'), 'Calling enqueue after canceling should throw');125 return rs.getReader().closed;126}, 'Underlying source: calling enqueue on a non-empty canceled stream should throw');127promise_test(() => {128 return new ReadableStream({129 start(c) {130 c.close();131 assert_throws(new TypeError(), () => c.enqueue('a'), 'call to enqueue should throw a TypeError');132 }133 }).getReader().closed;134}, 'Underlying source: calling enqueue on a closed stream should throw');135promise_test(t => {136 const theError = new Error('boo');137 const closed = new ReadableStream({138 start(c) {139 c.error(theError);140 assert_throws(new TypeError(), () => c.enqueue('a'), 'call to enqueue should throw the error');141 }142 }).getReader().closed;143 return promise_rejects(t, theError, closed);144}, 'Underlying source: calling enqueue on an errored stream should throw');145promise_test(() => {146 return new ReadableStream({147 start(c) {148 c.close();149 assert_throws(new TypeError(), () => c.close(), 'second call to close should throw a TypeError');150 }151 }).getReader().closed;152}, 'Underlying source: calling close twice on an empty stream should throw the second time');153promise_test(() => {154 let startCalled = false;155 let readCalled = false;156 const reader = new ReadableStream({157 start(c) {158 c.enqueue('a');159 c.close();160 assert_throws(new TypeError(), () => c.close(), 'second call to close should throw a TypeError');161 startCalled = true;162 }163 }).getReader();164 return Promise.all([165 reader.read().then(r => {166 assert_object_equals(r, { value: 'a', done: false }, 'read() should read the enqueued chunk');167 readCalled = true;168 }),169 reader.closed.then(() => {170 assert_true(startCalled);171 assert_true(readCalled);172 })173 ]);174}, 'Underlying source: calling close twice on a non-empty stream should throw the second time');175promise_test(() => {176 let controller;177 let startCalled = false;178 const rs = new ReadableStream({179 start(c) {180 controller = c;181 startCalled = true;182 }183 });184 rs.cancel();185 assert_throws(new TypeError(), () => controller.close(), 'Calling close after canceling should throw');186 return rs.getReader().closed.then(() => {187 assert_true(startCalled);188 });189}, 'Underlying source: calling close on an empty canceled stream should throw');190promise_test(() => {191 let controller;192 let startCalled = false;193 const rs = new ReadableStream({194 start(c) {195 controller = c;196 c.enqueue('a');197 startCalled = true;198 }199 });200 rs.cancel();201 assert_throws(new TypeError(), () => controller.close(), 'Calling close after canceling should throw');202 return rs.getReader().closed.then(() => {203 assert_true(startCalled);204 });205}, 'Underlying source: calling close on a non-empty canceled stream should throw');206promise_test(() => {207 const theError = new Error('boo');208 let startCalled = false;209 const closed = new ReadableStream({210 start(c) {211 c.error(theError);212 assert_throws(new TypeError(), () => c.close(), 'call to close should throw a TypeError');213 startCalled = true;214 }215 }).getReader().closed;216 return closed.catch(e => {217 assert_true(startCalled);218 assert_equals(e, theError, 'closed should reject with the error');219 });220}, 'Underlying source: calling close after error should throw');221promise_test(() => {222 const theError = new Error('boo');223 let startCalled = false;224 const closed = new ReadableStream({225 start(c) {226 c.error(theError);227 assert_throws(new TypeError(), () => c.error(), 'second call to error should throw a TypeError');228 startCalled = true;229 }230 }).getReader().closed;231 return closed.catch(e => {232 assert_true(startCalled);233 assert_equals(e, theError, 'closed should reject with the error');234 });235}, 'Underlying source: calling error twice should throw the second time');236promise_test(() => {237 let startCalled = false;238 const closed = new ReadableStream({239 start(c) {240 c.close();241 assert_throws(new TypeError(), () => c.error(), 'second call to error should throw a TypeError');242 startCalled = true;243 }244 }).getReader().closed;245 return closed.then(() => assert_true(startCalled));246}, 'Underlying source: calling error after close should throw');247promise_test(() => {248 let startCalled = false;249 const firstError = new Error('1');250 const secondError = new Error('2');251 const closed = new ReadableStream({252 start(c) {253 c.error(firstError);254 startCalled = true;255 return Promise.reject(secondError);256 }257 }).getReader().closed;258 return closed.catch(e => {259 assert_true(startCalled);260 assert_equals(e, firstError, 'closed should reject with the first error');261 });262}, 'Underlying source: calling error and returning a rejected promise from start should cause the stream to error ' +263 'with the first error');264promise_test(() => {265 let startCalled = false;266 const firstError = new Error('1');267 const secondError = new Error('2');268 const closed = new ReadableStream({269 pull(c) {270 c.error(firstError);271 startCalled = true;272 return Promise.reject(secondError);273 }274 }).getReader().closed;275 return closed.catch(e => {276 assert_true(startCalled);277 assert_equals(e, firstError, 'closed should reject with the first error');278 });279}, 'Underlying source: calling error and returning a rejected promise from pull should cause the stream to error ' +280 'with the first error');281const error1 = { name: 'error1' };282promise_test(t => {283 let pullShouldThrow = false;284 const rs = new ReadableStream({285 pull(controller) {286 if (pullShouldThrow) {287 throw error1;288 }289 controller.enqueue(0);290 }291 }, new CountQueuingStrategy({highWaterMark: 1}));292 const reader = rs.getReader();293 return Promise.resolve().then(() => {294 pullShouldThrow = true;295 return Promise.all([296 reader.read(),297 promise_rejects(t, error1, reader.closed, '.closed promise should reject')298 ]);299 });300}, 'read should not error if it dequeues and pull() throws');...
bad-underlying-sources.any.js
Source:bad-underlying-sources.any.js
1// META: global=worker,jsshell2'use strict';3test(() => {4 const theError = new Error('a unique string');5 assert_throws(theError, () => {6 new ReadableStream({7 get start() {8 throw theError;9 }10 });11 }, 'constructing the stream should re-throw the error');12}, 'Underlying source start: throwing getter');13test(() => {14 const theError = new Error('a unique string');15 assert_throws(theError, () => {16 new ReadableStream({17 start() {18 throw theError;19 }20 });21 }, 'constructing the stream should re-throw the error');22}, 'Underlying source start: throwing method');23test(() => {24 const theError = new Error('a unique string');25 assert_throws(theError, () => new ReadableStream({26 get pull() {27 throw theError;28 }29 }), 'constructor should throw');30}, 'Underlying source: throwing pull getter (initial pull)');31promise_test(t => {32 const theError = new Error('a unique string');33 const rs = new ReadableStream({34 pull() {35 throw theError;36 }37 });38 return promise_rejects(t, theError, rs.getReader().closed);39}, 'Underlying source: throwing pull method (initial pull)');40promise_test(t => {41 const theError = new Error('a unique string');42 let counter = 0;43 const rs = new ReadableStream({44 get pull() {45 ++counter;46 if (counter === 1) {47 return c => c.enqueue('a');48 }49 throw theError;50 }51 });52 const reader = rs.getReader();53 return Promise.all([54 reader.read().then(r => {55 assert_object_equals(r, { value: 'a', done: false }, 'the first chunk read should be correct');56 }),57 reader.read().then(r => {58 assert_object_equals(r, { value: 'a', done: false }, 'the second chunk read should be correct');59 assert_equals(counter, 1, 'counter should be 1');60 })61 ]);62}, 'Underlying source pull: throwing getter (second pull does not result in a second get)');63promise_test(t => {64 const theError = new Error('a unique string');65 let counter = 0;66 const rs = new ReadableStream({67 pull(c) {68 ++counter;69 if (counter === 1) {70 c.enqueue('a');71 return;72 }73 throw theError;74 }75 });76 const reader = rs.getReader();77 return Promise.all([78 reader.read().then(r => {79 assert_object_equals(r, { value: 'a', done: false }, 'the chunk read should be correct');80 }),81 promise_rejects(t, theError, reader.closed)82 ]);83}, 'Underlying source pull: throwing method (second pull)');84test(() => {85 const theError = new Error('a unique string');86 assert_throws(theError, () => new ReadableStream({87 get cancel() {88 throw theError;89 }90 }), 'constructor should throw');91}, 'Underlying source cancel: throwing getter');92promise_test(t => {93 const theError = new Error('a unique string');94 const rs = new ReadableStream({95 cancel() {96 throw theError;97 }98 });99 return promise_rejects(t, theError, rs.cancel());100}, 'Underlying source cancel: throwing method');101promise_test(() => {102 let controller;103 const rs = new ReadableStream({104 start(c) {105 controller = c;106 }107 });108 rs.cancel();109 assert_throws(new TypeError(), () => controller.enqueue('a'), 'Calling enqueue after canceling should throw');110 return rs.getReader().closed;111}, 'Underlying source: calling enqueue on an empty canceled stream should throw');112promise_test(() => {113 let controller;114 const rs = new ReadableStream({115 start(c) {116 c.enqueue('a');117 c.enqueue('b');118 controller = c;119 }120 });121 rs.cancel();122 assert_throws(new TypeError(), () => controller.enqueue('c'), 'Calling enqueue after canceling should throw');123 return rs.getReader().closed;124}, 'Underlying source: calling enqueue on a non-empty canceled stream should throw');125promise_test(() => {126 return new ReadableStream({127 start(c) {128 c.close();129 assert_throws(new TypeError(), () => c.enqueue('a'), 'call to enqueue should throw a TypeError');130 }131 }).getReader().closed;132}, 'Underlying source: calling enqueue on a closed stream should throw');133promise_test(t => {134 const theError = new Error('boo');135 const closed = new ReadableStream({136 start(c) {137 c.error(theError);138 assert_throws(new TypeError(), () => c.enqueue('a'), 'call to enqueue should throw the error');139 }140 }).getReader().closed;141 return promise_rejects(t, theError, closed);142}, 'Underlying source: calling enqueue on an errored stream should throw');143promise_test(() => {144 return new ReadableStream({145 start(c) {146 c.close();147 assert_throws(new TypeError(), () => c.close(), 'second call to close should throw a TypeError');148 }149 }).getReader().closed;150}, 'Underlying source: calling close twice on an empty stream should throw the second time');151promise_test(() => {152 let startCalled = false;153 let readCalled = false;154 const reader = new ReadableStream({155 start(c) {156 c.enqueue('a');157 c.close();158 assert_throws(new TypeError(), () => c.close(), 'second call to close should throw a TypeError');159 startCalled = true;160 }161 }).getReader();162 return Promise.all([163 reader.read().then(r => {164 assert_object_equals(r, { value: 'a', done: false }, 'read() should read the enqueued chunk');165 readCalled = true;166 }),167 reader.closed.then(() => {168 assert_true(startCalled);169 assert_true(readCalled);170 })171 ]);172}, 'Underlying source: calling close twice on a non-empty stream should throw the second time');173promise_test(() => {174 let controller;175 let startCalled = false;176 const rs = new ReadableStream({177 start(c) {178 controller = c;179 startCalled = true;180 }181 });182 rs.cancel();183 assert_throws(new TypeError(), () => controller.close(), 'Calling close after canceling should throw');184 return rs.getReader().closed.then(() => {185 assert_true(startCalled);186 });187}, 'Underlying source: calling close on an empty canceled stream should throw');188promise_test(() => {189 let controller;190 let startCalled = false;191 const rs = new ReadableStream({192 start(c) {193 controller = c;194 c.enqueue('a');195 startCalled = true;196 }197 });198 rs.cancel();199 assert_throws(new TypeError(), () => controller.close(), 'Calling close after canceling should throw');200 return rs.getReader().closed.then(() => {201 assert_true(startCalled);202 });203}, 'Underlying source: calling close on a non-empty canceled stream should throw');204promise_test(() => {205 const theError = new Error('boo');206 let startCalled = false;207 const closed = new ReadableStream({208 start(c) {209 c.error(theError);210 assert_throws(new TypeError(), () => c.close(), 'call to close should throw a TypeError');211 startCalled = true;212 }213 }).getReader().closed;214 return closed.catch(e => {215 assert_true(startCalled);216 assert_equals(e, theError, 'closed should reject with the error');217 });218}, 'Underlying source: calling close after error should throw');219promise_test(() => {220 const theError = new Error('boo');221 let startCalled = false;222 const closed = new ReadableStream({223 start(c) {224 c.error(theError);225 c.error();226 startCalled = true;227 }228 }).getReader().closed;229 return closed.catch(e => {230 assert_true(startCalled);231 assert_equals(e, theError, 'closed should reject with the error');232 });233}, 'Underlying source: calling error twice should not throw');234promise_test(() => {235 let startCalled = false;236 const closed = new ReadableStream({237 start(c) {238 c.close();239 c.error();240 startCalled = true;241 }242 }).getReader().closed;243 return closed.then(() => assert_true(startCalled));244}, 'Underlying source: calling error after close should not throw');245promise_test(() => {246 let startCalled = false;247 const firstError = new Error('1');248 const secondError = new Error('2');249 const closed = new ReadableStream({250 start(c) {251 c.error(firstError);252 startCalled = true;253 return Promise.reject(secondError);254 }255 }).getReader().closed;256 return closed.catch(e => {257 assert_true(startCalled);258 assert_equals(e, firstError, 'closed should reject with the first error');259 });260}, 'Underlying source: calling error and returning a rejected promise from start should cause the stream to error ' +261 'with the first error');262promise_test(() => {263 let startCalled = false;264 const firstError = new Error('1');265 const secondError = new Error('2');266 const closed = new ReadableStream({267 pull(c) {268 c.error(firstError);269 startCalled = true;270 return Promise.reject(secondError);271 }272 }).getReader().closed;273 return closed.catch(e => {274 assert_true(startCalled);275 assert_equals(e, firstError, 'closed should reject with the first error');276 });277}, 'Underlying source: calling error and returning a rejected promise from pull should cause the stream to error ' +278 'with the first error');279const error1 = { name: 'error1' };280promise_test(t => {281 let pullShouldThrow = false;282 const rs = new ReadableStream({283 pull(controller) {284 if (pullShouldThrow) {285 throw error1;286 }287 controller.enqueue(0);288 }289 }, new CountQueuingStrategy({highWaterMark: 1}));290 const reader = rs.getReader();291 return Promise.resolve().then(() => {292 pullShouldThrow = true;293 return Promise.all([294 reader.read(),295 promise_rejects(t, error1, reader.closed, '.closed promise should reject')296 ]);297 });...
Using AI Code Generation
1var wpt = require('wpt');2wpt.theError('error message');3var wpt = require('wpt');4wpt.theError('error message', 'error');5var wpt = require('wpt');6wpt.theError('error message', 'error', 'error');7var wpt = require('wpt');8wpt.theError('error message', 'error', 'error', 'error');9var wpt = require('wpt');10wpt.theError('error message', 'error', 'error', 'error', 'error');11var wpt = require('wpt');12wpt.theError('error message', 'error', 'error', 'error', 'error', 'error');13var wpt = require('wpt');14wpt.theError('error message', 'error', 'error', 'error', 'error', 'error', 'error');15var wpt = require('wpt');16wpt.theError('error message', 'error', 'error', 'error', 'error', 'error', 'error', 'error');17var wpt = require('wpt');18wpt.theError('error message', 'error', 'error', 'error', 'error', 'error', 'error', 'error', 'error');19var wpt = require('wpt');20wpt.theError('error message', 'error', 'error', 'error', 'error', 'error', 'error', 'error', 'error', 'error');21var wpt = require('wpt');
Using AI Code Generation
1var wpt = require('wpt');2 if (err) {3 console.log(err);4 } else {5 console.log(data);6 }7});8var wpt = require('wpt');9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});15var wpt = require('wpt');16 if (err) {17 console.log(err);18 } else {19 console.log(data);20 }21});22var wpt = require('wpt');23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28});29var wpt = require('wpt');30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36var wpt = require('wpt');37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43var wpt = require('wpt');44 if (err) {45 console.log(err);46 } else {47 console.log(data);48 }49});50var wpt = require('wpt');51 if (err) {52 console.log(err);53 } else {
Using AI Code Generation
1const wpt = require('webpagetest');2const wpt = new WebPageTest('www.webpagetest.org');3}, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10const wpt = require('webpagetest');11const wpt = new WebPageTest('www.webpagetest.org');12}, function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19const wpt = require('webpagetest');20const wpt = new WebPageTest('www.webpagetest.org');21}, function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28const wpt = require('webpagetest');29const wpt = new WebPageTest('www.webpagetest.org');30}, function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37const wpt = require('webpagetest');38const wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');3 if(err) throw err;4 console.log(data);5});6var wpt = require('wpt');7var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');8 if(err) throw err;9 console.log(data);10});11var wpt = require('wpt');12var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');13 if(err) throw err;14 console.log(data);15});16var wpt = require('wpt');17var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');18 if(err) throw err;19 console.log(data);20});21var wpt = require('wpt');22var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');23 if(err) throw err;24 console.log(data);25});26var wpt = require('wpt');27var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');28 if(err) throw err;29 console.log(data);30});
Using AI Code Generation
1var wp = require('wptools');2var error = wp.theError;3var page = wp.page('some page that doesnt exist');4page.get(function(err, data) {5 if (err) {6 console.log(error('bad page'));7 }8});9var wp = require('wptools');10var error = wp.theError;11var page = wp.page('some page that doesnt exist');12page.get(function(err, data) {13 if (err) {14 console.log(error('bad page'));15 }16});
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!!