Best JavaScript code snippet using wpt
reentrant-strategy.js
Source:reentrant-strategy.js
1'use strict';2// These tests exercise the pathological case of calling WritableStream* methods from within the strategy.size()3// callback. This is not something any real code should ever do. Failures here indicate subtle deviations from the4// standard that may affect real, non-pathological code.5if (self.importScripts) {6 self.importScripts('/resources/testharness.js');7 self.importScripts('../resources/test-utils.js');8 self.importScripts('../resources/recording-streams.js');9}10const error1 = { name: 'error1' };11promise_test(() => {12 let writer;13 const strategy = {14 size(chunk) {15 if (chunk > 0) {16 writer.write(chunk - 1);17 }18 return chunk;19 }20 };21 const ws = recordingWritableStream({}, strategy);22 writer = ws.getWriter();23 return writer.write(2)24 .then(() => {25 assert_array_equals(ws.events, ['write', 0, 'write', 1, 'write', 2], 'writes should appear in order');26 });27}, 'writes should be written in the standard order');28promise_test(() => {29 let writer;30 const events = [];31 const strategy = {32 size(chunk) {33 events.push('size', chunk);34 if (chunk > 0) {35 writer.write(chunk - 1)36 .then(() => events.push('writer.write done', chunk - 1));37 }38 return chunk;39 }40 };41 const ws = new WritableStream({42 write(chunk) {43 events.push('sink.write', chunk);44 }45 }, strategy);46 writer = ws.getWriter();47 return writer.write(2)48 .then(() => events.push('writer.write done', 2))49 .then(() => flushAsyncEvents())50 .then(() => {51 assert_array_equals(events, ['size', 2, 'size', 1, 'size', 0,52 'sink.write', 0, 'sink.write', 1, 'writer.write done', 0,53 'sink.write', 2, 'writer.write done', 1,54 'writer.write done', 2],55 'events should happen in standard order');56 });57}, 'writer.write() promises should resolve in the standard order');58promise_test(t => {59 let controller;60 const strategy = {61 size() {62 controller.error(error1);63 return 1;64 }65 };66 const ws = recordingWritableStream({67 start(c) {68 controller = c;69 }70 }, strategy);71 const resolved = [];72 const writer = ws.getWriter();73 const readyPromise1 = writer.ready.then(() => resolved.push('ready1'));74 const writePromise = promise_rejects(t, error1, writer.write(),75 'write() should reject with the error')76 .then(() => resolved.push('write'));77 const readyPromise2 = promise_rejects(t, error1, writer.ready, 'ready should reject with error1')78 .then(() => resolved.push('ready2'));79 const closedPromise = promise_rejects(t, error1, writer.closed, 'closed should reject with error1')80 .then(() => resolved.push('closed'));81 return Promise.all([readyPromise1, writePromise, readyPromise2, closedPromise])82 .then(() => {83 assert_array_equals(resolved, ['ready1', 'write', 'ready2', 'closed'],84 'promises should resolve in standard order');85 assert_array_equals(ws.events, [], 'underlying sink write should not be called');86 });87}, 'controller.error() should work when called from within strategy.size()');88promise_test(t => {89 let writer;90 const strategy = {91 size() {92 writer.close();93 return 1;94 }95 };96 const ws = recordingWritableStream({}, strategy);97 writer = ws.getWriter();98 return promise_rejects(t, new TypeError(), writer.write('a'), 'write() promise should reject')99 .then(() => {100 assert_array_equals(ws.events, ['close'], 'sink.write() should not be called');101 });102}, 'close() should work when called from within strategy.size()');103promise_test(t => {104 let writer;105 const strategy = {106 size() {107 writer.abort('nice');108 return 1;109 }110 };111 const ws = recordingWritableStream({}, strategy);112 writer = ws.getWriter();113 return promise_rejects(t, new TypeError(), writer.write('a'), 'write() promise should reject')114 .then(() => {115 assert_array_equals(ws.events, ['abort', 'nice'], 'sink.write() should not be called');116 });117}, 'abort() should work when called from within strategy.size()');118promise_test(t => {119 let writer;120 const strategy = {121 size() {122 writer.releaseLock();123 return 1;124 }125 };126 const ws = recordingWritableStream({}, strategy);127 writer = ws.getWriter();128 const writePromise = promise_rejects(t, new TypeError(), writer.write('a'), 'write() promise should reject');129 const readyPromise = promise_rejects(t, new TypeError(), writer.ready, 'ready promise should reject');130 const closedPromise = promise_rejects(t, new TypeError(), writer.closed, 'closed promise should reject');131 return Promise.all([writePromise, readyPromise, closedPromise])132 .then(() => {133 assert_array_equals(ws.events, [], 'sink.write() should not be called');134 });135}, 'releaseLock() should abort the write() when called within strategy.size()');136promise_test(t => {137 let writer1;138 let ws;139 let writePromise2;140 let closePromise;141 let closedPromise2;142 const strategy = {143 size(chunk) {144 if (chunk > 0) {145 writer1.releaseLock();146 const writer2 = ws.getWriter();147 writePromise2 = writer2.write(0);148 closePromise = writer2.close();149 closedPromise2 = writer2.closed;150 }151 return 1;152 }153 };154 ws = recordingWritableStream({}, strategy);155 writer1 = ws.getWriter();156 const writePromise1 = promise_rejects(t, new TypeError(), writer1.write(1), 'write() promise should reject');157 const readyPromise = promise_rejects(t, new TypeError(), writer1.ready, 'ready promise should reject');158 const closedPromise1 = promise_rejects(t, new TypeError(), writer1.closed, 'closed promise should reject');159 return Promise.all([writePromise1, readyPromise, closedPromise1, writePromise2, closePromise, closedPromise2])160 .then(() => {161 assert_array_equals(ws.events, ['write', 0, 'close'], 'sink.write() should only be called once');162 });163}, 'original reader should error when new reader is created within strategy.size()');...
reentrant-strategy.any.js
Source:reentrant-strategy.any.js
1// META: global=window,worker,jsshell2// META: script=../resources/test-utils.js3// META: script=../resources/recording-streams.js4'use strict';5// These tests exercise the pathological case of calling WritableStream* methods from within the strategy.size()6// callback. This is not something any real code should ever do. Failures here indicate subtle deviations from the7// standard that may affect real, non-pathological code.8const error1 = { name: 'error1' };9promise_test(() => {10 let writer;11 const strategy = {12 size(chunk) {13 if (chunk > 0) {14 writer.write(chunk - 1);15 }16 return chunk;17 }18 };19 const ws = recordingWritableStream({}, strategy);20 writer = ws.getWriter();21 return writer.write(2)22 .then(() => {23 assert_array_equals(ws.events, ['write', 0, 'write', 1, 'write', 2], 'writes should appear in order');24 });25}, 'writes should be written in the standard order');26promise_test(() => {27 let writer;28 const events = [];29 const strategy = {30 size(chunk) {31 events.push('size', chunk);32 if (chunk > 0) {33 writer.write(chunk - 1)34 .then(() => events.push('writer.write done', chunk - 1));35 }36 return chunk;37 }38 };39 const ws = new WritableStream({40 write(chunk) {41 events.push('sink.write', chunk);42 }43 }, strategy);44 writer = ws.getWriter();45 return writer.write(2)46 .then(() => events.push('writer.write done', 2))47 .then(() => flushAsyncEvents())48 .then(() => {49 assert_array_equals(events, ['size', 2, 'size', 1, 'size', 0,50 'sink.write', 0, 'sink.write', 1, 'writer.write done', 0,51 'sink.write', 2, 'writer.write done', 1,52 'writer.write done', 2],53 'events should happen in standard order');54 });55}, 'writer.write() promises should resolve in the standard order');56promise_test(t => {57 let controller;58 const strategy = {59 size() {60 controller.error(error1);61 return 1;62 }63 };64 const ws = recordingWritableStream({65 start(c) {66 controller = c;67 }68 }, strategy);69 const resolved = [];70 const writer = ws.getWriter();71 const readyPromise1 = writer.ready.then(() => resolved.push('ready1'));72 const writePromise = promise_rejects_exactly(t, error1, writer.write(),73 'write() should reject with the error')74 .then(() => resolved.push('write'));75 const readyPromise2 = promise_rejects_exactly(t, error1, writer.ready, 'ready should reject with error1')76 .then(() => resolved.push('ready2'));77 const closedPromise = promise_rejects_exactly(t, error1, writer.closed, 'closed should reject with error1')78 .then(() => resolved.push('closed'));79 return Promise.all([readyPromise1, writePromise, readyPromise2, closedPromise])80 .then(() => {81 assert_array_equals(resolved, ['ready1', 'write', 'ready2', 'closed'],82 'promises should resolve in standard order');83 assert_array_equals(ws.events, [], 'underlying sink write should not be called');84 });85}, 'controller.error() should work when called from within strategy.size()');86promise_test(t => {87 let writer;88 const strategy = {89 size() {90 writer.close();91 return 1;92 }93 };94 const ws = recordingWritableStream({}, strategy);95 writer = ws.getWriter();96 return promise_rejects_js(t, TypeError, writer.write('a'), 'write() promise should reject')97 .then(() => {98 assert_array_equals(ws.events, ['close'], 'sink.write() should not be called');99 });100}, 'close() should work when called from within strategy.size()');101promise_test(t => {102 let writer;103 const strategy = {104 size() {105 writer.abort(error1);106 return 1;107 }108 };109 const ws = recordingWritableStream({}, strategy);110 writer = ws.getWriter();111 return promise_rejects_exactly(t, error1, writer.write('a'), 'write() promise should reject')112 .then(() => {113 assert_array_equals(ws.events, ['abort', error1], 'sink.write() should not be called');114 });115}, 'abort() should work when called from within strategy.size()');116promise_test(t => {117 let writer;118 const strategy = {119 size() {120 writer.releaseLock();121 return 1;122 }123 };124 const ws = recordingWritableStream({}, strategy);125 writer = ws.getWriter();126 const writePromise = promise_rejects_js(t, TypeError, writer.write('a'), 'write() promise should reject');127 const readyPromise = promise_rejects_js(t, TypeError, writer.ready, 'ready promise should reject');128 const closedPromise = promise_rejects_js(t, TypeError, writer.closed, 'closed promise should reject');129 return Promise.all([writePromise, readyPromise, closedPromise])130 .then(() => {131 assert_array_equals(ws.events, [], 'sink.write() should not be called');132 });133}, 'releaseLock() should abort the write() when called within strategy.size()');134promise_test(t => {135 let writer1;136 let ws;137 let writePromise2;138 let closePromise;139 let closedPromise2;140 const strategy = {141 size(chunk) {142 if (chunk > 0) {143 writer1.releaseLock();144 const writer2 = ws.getWriter();145 writePromise2 = writer2.write(0);146 closePromise = writer2.close();147 closedPromise2 = writer2.closed;148 }149 return 1;150 }151 };152 ws = recordingWritableStream({}, strategy);153 writer1 = ws.getWriter();154 const writePromise1 = promise_rejects_js(t, TypeError, writer1.write(1), 'write() promise should reject');155 const readyPromise = promise_rejects_js(t, TypeError, writer1.ready, 'ready promise should reject');156 const closedPromise1 = promise_rejects_js(t, TypeError, writer1.closed, 'closed promise should reject');157 return Promise.all([writePromise1, readyPromise, closedPromise1, writePromise2, closePromise, closedPromise2])158 .then(() => {159 assert_array_equals(ws.events, ['write', 0, 'close'], 'sink.write() should only be called once');160 });...
aflprep_reentrant-strategy.any.js
Source:aflprep_reentrant-strategy.any.js
1'use strict';2const error1 = { name: 'error1' };3promise_test(() => {4 let writer;5 const strategy = {6 size(chunk) {7 if (chunk > 0) {8 writer.write(chunk - 1);9 }10 return chunk;11 }12 };13 const ws = recordingWritableStream({}, strategy);14 writer = ws.getWriter();15 return writer.write(2)16 .then(() => {17 assert_array_equals(ws.events, ['write', 0, 'write', 1, 'write', 2], 'writes should appear in order');18 });19}, 'writes should be written in the standard order');20promise_test(() => {21 let writer;22 const events = [];23 const strategy = {24 size(chunk) {25 events.push('size', chunk);26 if (chunk > 0) {27 writer.write(chunk - 1)28 .then(() => events.push('writer.write done', chunk - 1));29 }30 return chunk;31 }32 };33 const ws = new WritableStream({34 write(chunk) {35 events.push('sink.write', chunk);36 }37 }, strategy);38 writer = ws.getWriter();39 return writer.write(2)40 .then(() => events.push('writer.write done', 2))41 .then(() => flushAsyncEvents())42 .then(() => {43 assert_array_equals(events, ['size', 2, 'size', 1, 'size', 0,44 'sink.write', 0, 'sink.write', 1, 'writer.write done', 0,45 'sink.write', 2, 'writer.write done', 1,46 'writer.write done', 2],47 'events should happen in standard order');48 });49}, 'writer.write() promises should resolve in the standard order');50promise_test(t => {51 let controller;52 const strategy = {53 size() {54 controller.error(error1);55 return 1;56 }57 };58 const ws = recordingWritableStream({59 start(c) {60 controller = c;61 }62 }, strategy);63 const resolved = [];64 const writer = ws.getWriter();65 const readyPromise1 = writer.ready.then(() => resolved.push('ready1'));66 const writePromise = promise_rejects_exactly(t, error1, writer.write(),67 'write() should reject with the error')68 .then(() => resolved.push('write'));69 const readyPromise2 = promise_rejects_exactly(t, error1, writer.ready, 'ready should reject with error1')70 .then(() => resolved.push('ready2'));71 const closedPromise = promise_rejects_exactly(t, error1, writer.closed, 'closed should reject with error1')72 .then(() => resolved.push('closed'));73 return Promise.all([readyPromise1, writePromise, readyPromise2, closedPromise])74 .then(() => {75 assert_array_equals(resolved, ['ready1', 'write', 'ready2', 'closed'],76 'promises should resolve in standard order');77 assert_array_equals(ws.events, [], 'underlying sink write should not be called');78 });79}, 'controller.error() should work when called from within strategy.size()');80promise_test(t => {81 let writer;82 const strategy = {83 size() {84 writer.close();85 return 1;86 }87 };88 const ws = recordingWritableStream({}, strategy);89 writer = ws.getWriter();90 return promise_rejects_js(t, TypeError, writer.write('a'), 'write() promise should reject')91 .then(() => {92 assert_array_equals(ws.events, ['close'], 'sink.write() should not be called');93 });94}, 'close() should work when called from within strategy.size()');95promise_test(t => {96 let writer;97 const strategy = {98 size() {99 writer.abort(error1);100 return 1;101 }102 };103 const ws = recordingWritableStream({}, strategy);104 writer = ws.getWriter();105 return promise_rejects_exactly(t, error1, writer.write('a'), 'write() promise should reject')106 .then(() => {107 assert_array_equals(ws.events, ['abort', error1], 'sink.write() should not be called');108 });109}, 'abort() should work when called from within strategy.size()');110promise_test(t => {111 let writer;112 const strategy = {113 size() {114 writer.releaseLock();115 return 1;116 }117 };118 const ws = recordingWritableStream({}, strategy);119 writer = ws.getWriter();120 const writePromise = promise_rejects_js(t, TypeError, writer.write('a'), 'write() promise should reject');121 const readyPromise = promise_rejects_js(t, TypeError, writer.ready, 'ready promise should reject');122 const closedPromise = promise_rejects_js(t, TypeError, writer.closed, 'closed promise should reject');123 return Promise.all([writePromise, readyPromise, closedPromise])124 .then(() => {125 assert_array_equals(ws.events, [], 'sink.write() should not be called');126 });127}, 'releaseLock() should abort the write() when called within strategy.size()');128promise_test(t => {129 let writer1;130 let ws;131 let writePromise2;132 let closePromise;133 let closedPromise2;134 const strategy = {135 size(chunk) {136 if (chunk > 0) {137 writer1.releaseLock();138 const writer2 = ws.getWriter();139 writePromise2 = writer2.write(0);140 closePromise = writer2.close();141 closedPromise2 = writer2.closed;142 }143 return 1;144 }145 };146 ws = recordingWritableStream({}, strategy);147 writer1 = ws.getWriter();148 const writePromise1 = promise_rejects_js(t, TypeError, writer1.write(1), 'write() promise should reject');149 const readyPromise = promise_rejects_js(t, TypeError, writer1.ready, 'ready promise should reject');150 const closedPromise1 = promise_rejects_js(t, TypeError, writer1.closed, 'closed promise should reject');151 return Promise.all([writePromise1, readyPromise, closedPromise1, writePromise2, closePromise, closedPromise2])152 .then(() => {153 assert_array_equals(ws.events, ['write', 0, 'close'], 'sink.write() should only be called once');154 });...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('wpt');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.getLocations(function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('wpt');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.getLocations(function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('wpt');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.getLocations(function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('wpt');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.getLocations(function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31var wpt = require('wpt');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.getLocations(function(err, data) {34 if (err) return console.error(err);35 console.log(data);36});37var wpt = require('wpt');38var wpt = new WebPageTest('www.webpagetest.org');39wpt.getLocations(function(err, data) {40 if (err) return console.error(err);41 console.log(data);42});43var wpt = require('wpt');
Using AI Code Generation
1var wptools = require('wptools');2wptools.page('Barack_Obama').then(function(page) {3 page.closedPromise1().then(function(result) {4 console.log(result);5 });6});7{8 "extract": "Barack Hussein Obama II (born August 4, 1961) is the 44th and current President of the United States. He is the first African American to hold the office. He previously served as a U.S. Senator from Illinois from 2005 to 2008 and as an Illinois State Senator from 1997 to 2004. He is a member of the Democratic Party. Obama was born in Honolulu, Hawaii. Two years after his parents' divorce, he moved with his mother and sister to live with his maternal grandparents in Jakarta, Indonesia. After returning to Hawaii, he attended Punahou School before enrolling in Occidental College in Los Angeles. He transferred to Columbia University in New York City, where he earned a Bachelor of Arts degree in political science in 1983. He worked as a community organizer in Chicago before earning his Juris Doctor from Harvard Law School in 1991. He was a civil rights attorney and taught constitutional law at the University of Chicago Law School from 1992 to 2004. He served three terms representing the 13th District in the Illinois Senate from 1997 until 2004, when he ran for the U.S. Senate. He won the Democratic primary in 2004, and the general election on November 2, 2004, defeating Republican incumbent Peter Fitzgerald. He was re-elected in 2006 and 2012. He was elected President in 2008, winning the electoral and popular vote. Obama was inaugurated on January 20, 2009. He was sworn in for a second term on January 20, 2013. He is married to Michelle Obama and has two daughters. He is the first president born outside the contiguous United States. He is also the first president to have been born in Hawaii and the first whose mother was a native of Hawaii. He is the first president to have been born in the 1960s and the first to have been a practicing Christian since Dwight D. Eisenhower. He is also the first president to have previously
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function (err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});
Using AI Code Generation
1const wpt = require('webpagetest');2const closedPromise1 = wpt('API_KEY').closedPromise1;3closedPromise1('testId')4 .then((data) => {5 console.log(data);6 })7 .catch((err) => {8 console.log(err);9 });10const wpt = require('webpagetest');11const closedPromise2 = wpt('API_KEY').closedPromise2;12closedPromise2('testId')13 .then((data) => {14 console.log(data);15 })16 .catch((err) => {17 console.log(err);18 });19const wpt = require('webpagetest');20const closedPromise3 = wpt('API_KEY').closedPromise3;21closedPromise3('testId')22 .then((data) => {23 console.log(data);24 })25 .catch((err) => {26 console.log(err);27 });28const wpt = require('webpagetest');29const closedPromise4 = wpt('API_KEY').closedPromise4;30closedPromise4('testId')31 .then((data) => {32 console.log(data);33 })34 .catch((err) => {35 console.log(err);36 });37const wpt = require('webpagetest');38const closedPromise5 = wpt('API_KEY').closedPromise5;39closedPromise5('testId')40 .then((data) => {41 console.log(data);42 })43 .catch((err) => {44 console.log(err);45 });46const wpt = require('webpagetest');47const closedPromise6 = wpt('API_KEY').closedPromise6;48closedPromise6('testId')49 .then((data) => {50 console.log(data);51 })52 .catch((err) => {53 console.log(err);54 });55const wpt = require('webpagetest');
Using AI Code Generation
1var wptools = require('wptools');2wptools.page('Barack_Obama').get(function(page) {3 console.log(page.data);4});5var wptools = require('wptools');6var page = wptools.page('Barack_Obama');7page.get(function(page) {8 console.log(page.data);9});10var wptools = require('wptools');11var page = wptools.page('Barack_Obama');12page.get().then(function(page) {13 console.log(page.data);14});15var wptools = require('wptools');16var page = wptools.page('Barack_Obama');17page.get().then(function(page) {18 console.log(page.data);19}).catch(function(err) {20 console.log(err);21});22var wptools = require('wptools');23var page = wptools.page('Barack_Obama');24page.get().then(function(page) {25 console.log(page.data);26}).catch(function(err) {27 console.log(err);28});29var wptools = require('wptools');30var page = wptools.page('Barack_Obama');31page.get().then(function(page) {32 console.log(page.data);33}).catch(function(err) {34 console.log(err);35});36var wptools = require('wptools');37var page = wptools.page('Barack_Obama');38page.get().then(function(page) {39 console.log(page.data);40}).catch(function(err) {41 console.log(err);42});43var wptools = require('wptools');44var page = wptools.page('Barack_Obama');45page.get().then(function(page) {46 console.log(page.data);47}).catch(function(err) {
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!!