Best JavaScript code snippet using wpt
default-reader.js
Source:default-reader.js
1'use strict';2if (self.importScripts) {3 self.importScripts('../resources/rs-utils.js');4 self.importScripts('/resources/testharness.js');5}6let ReadableStreamDefaultReader;7test(() => {8 // It's not exposed globally, but we test a few of its properties here.9 ReadableStreamDefaultReader = (new ReadableStream()).getReader().constructor;10}, 'Can get the ReadableStreamDefaultReader constructor indirectly');11test(() => {12 assert_throws(new TypeError(), () => new ReadableStreamDefaultReader('potato'));13 assert_throws(new TypeError(), () => new ReadableStreamDefaultReader({}));14 assert_throws(new TypeError(), () => new ReadableStreamDefaultReader());15}, 'ReadableStreamDefaultReader constructor should get a ReadableStream object as argument');16test(() => {17 const methods = ['cancel', 'constructor', 'read', 'releaseLock'];18 const properties = methods.concat(['closed']).sort();19 const rsReader = new ReadableStreamDefaultReader(new ReadableStream());20 const proto = Object.getPrototypeOf(rsReader);21 assert_array_equals(Object.getOwnPropertyNames(proto).sort(), properties);22 for (const m of methods) {23 const propDesc = Object.getOwnPropertyDescriptor(proto, m);24 assert_equals(propDesc.enumerable, false, 'method should be non-enumerable');25 assert_equals(propDesc.configurable, true, 'method should be configurable');26 assert_equals(propDesc.writable, true, 'method should be writable');27 assert_equals(typeof rsReader[m], 'function', 'should have be a method');28 }29 const closedPropDesc = Object.getOwnPropertyDescriptor(proto, 'closed');30 assert_equals(closedPropDesc.enumerable, false, 'closed should be non-enumerable');31 assert_equals(closedPropDesc.configurable, true, 'closed should be configurable');32 assert_not_equals(closedPropDesc.get, undefined, 'closed should have a getter');33 assert_equals(closedPropDesc.set, undefined, 'closed should not have a setter');34 assert_equals(rsReader.cancel.length, 1, 'cancel has 1 parameter');35 assert_not_equals(rsReader.closed, undefined, 'has a non-undefined closed property');36 assert_equals(typeof rsReader.closed.then, 'function', 'closed property is thenable');37 assert_equals(typeof rsReader.constructor, 'function', 'has a constructor method');38 assert_equals(rsReader.constructor.length, 1, 'constructor has 1 parameter');39 assert_equals(typeof rsReader.read, 'function', 'has a getReader method');40 assert_equals(rsReader.read.length, 0, 'read has no parameters');41 assert_equals(typeof rsReader.releaseLock, 'function', 'has a releaseLock method');42 assert_equals(rsReader.releaseLock.length, 0, 'releaseLock has no parameters');43}, 'ReadableStreamDefaultReader instances should have the correct list of properties');44test(() => {45 const rsReader = new ReadableStreamDefaultReader(new ReadableStream());46 assert_equals(rsReader.closed, rsReader.closed, 'closed should return the same promise');47}, 'ReadableStreamDefaultReader closed should always return the same promise object');48test(() => {49 const rs = new ReadableStream();50 new ReadableStreamDefaultReader(rs); // Constructing directly the first time should be fine.51 assert_throws(new TypeError(), () => new ReadableStreamDefaultReader(rs),52 'constructing directly the second time should fail');53}, 'Constructing a ReadableStreamDefaultReader directly should fail if the stream is already locked (via direct ' +54 'construction)');55test(() => {56 const rs = new ReadableStream();57 new ReadableStreamDefaultReader(rs); // Constructing directly should be fine.58 assert_throws(new TypeError(), () => rs.getReader(), 'getReader() should fail');59}, 'Getting a ReadableStreamDefaultReader via getReader should fail if the stream is already locked (via direct ' +60 'construction)');61test(() => {62 const rs = new ReadableStream();63 rs.getReader(); // getReader() should be fine.64 assert_throws(new TypeError(), () => new ReadableStreamDefaultReader(rs), 'constructing directly should fail');65}, 'Constructing a ReadableStreamDefaultReader directly should fail if the stream is already locked (via getReader)');66test(() => {67 const rs = new ReadableStream();68 rs.getReader(); // getReader() should be fine.69 assert_throws(new TypeError(), () => rs.getReader(), 'getReader() should fail');70}, 'Getting a ReadableStreamDefaultReader via getReader should fail if the stream is already locked (via getReader)');71test(() => {72 const rs = new ReadableStream({73 start(c) {74 c.close();75 }76 });77 new ReadableStreamDefaultReader(rs); // Constructing directly should not throw.78}, 'Constructing a ReadableStreamDefaultReader directly should be OK if the stream is closed');79test(() => {80 const theError = new Error('don\'t say i didn\'t warn ya');81 const rs = new ReadableStream({82 start(c) {83 c.error(theError);84 }85 });86 new ReadableStreamDefaultReader(rs); // Constructing directly should not throw.87}, 'Constructing a ReadableStreamDefaultReader directly should be OK if the stream is errored');88promise_test(() => {89 let controller;90 const rs = new ReadableStream({91 start(c) {92 controller = c;93 }94 });95 const reader = rs.getReader();96 const promise = reader.read().then(result => {97 assert_object_equals(result, { value: 'a', done: false }, 'read() should fulfill with the enqueued chunk');98 });99 controller.enqueue('a');100 return promise;101}, 'Reading from a reader for an empty stream will wait until a chunk is available');102promise_test(() => {103 let cancelCalled = false;104 const passedReason = new Error('it wasn\'t the right time, sorry');105 const rs = new ReadableStream({106 cancel(reason) {107 assert_true(rs.locked, 'the stream should still be locked');108 assert_throws(new TypeError(), () => rs.getReader(), 'should not be able to get another reader');109 assert_equals(reason, passedReason, 'the cancellation reason is passed through to the underlying source');110 cancelCalled = true;111 }112 });113 const reader = rs.getReader();114 return reader.cancel(passedReason).then(() => assert_true(cancelCalled));115}, 'cancel() on a reader does not release the reader');116promise_test(() => {117 let controller;118 const rs = new ReadableStream({119 start(c) {120 controller = c;121 }122 });123 const reader = rs.getReader();124 const promise = reader.closed;125 controller.close();126 return promise;127}, 'closed should be fulfilled after stream is closed (.closed access before acquiring)');128promise_test(t => {129 let controller;130 const rs = new ReadableStream({131 start(c) {132 controller = c;133 }134 });135 const reader1 = rs.getReader();136 reader1.releaseLock();137 const reader2 = rs.getReader();138 controller.close();139 return Promise.all([140 promise_rejects(t, new TypeError(), reader1.closed),141 reader2.closed142 ]);143}, 'closed should be rejected after reader releases its lock (multiple stream locks)');144promise_test(() => {145 const rs = new ReadableStream({146 start(c) {147 c.enqueue('a');148 c.enqueue('b');149 c.close();150 }151 });152 const reader1 = rs.getReader();153 const promise1 = reader1.read().then(r => {154 assert_object_equals(r, { value: 'a', done: false }, 'reading the first chunk from reader1 works');155 });156 reader1.releaseLock();157 const reader2 = rs.getReader();158 const promise2 = reader2.read().then(r => {159 assert_object_equals(r, { value: 'b', done: false }, 'reading the second chunk from reader2 works');160 });161 reader2.releaseLock();162 return Promise.all([promise1, promise2]);163}, 'Multiple readers can access the stream in sequence');164promise_test(() => {165 const rs = new ReadableStream({166 start(c) {167 c.enqueue('a');168 }169 });170 const reader1 = rs.getReader();171 reader1.releaseLock();172 const reader2 = rs.getReader();173 // Should be a no-op174 reader1.releaseLock();175 return reader2.read().then(result => {176 assert_object_equals(result, { value: 'a', done: false },177 'read() should still work on reader2 even after reader1 is released');178 });179}, 'Cannot use an already-released reader to unlock a stream again');180promise_test(t => {181 const rs = new ReadableStream({182 start(c) {183 c.enqueue('a');184 },185 cancel() {186 assert_unreached('underlying source cancel should not be called');187 }188 });189 const reader = rs.getReader();190 reader.releaseLock();191 const cancelPromise = reader.cancel();192 const reader2 = rs.getReader();193 const readPromise = reader2.read().then(r => {194 assert_object_equals(r, { value: 'a', done: false }, 'a new reader should be able to read a chunk');195 });196 return Promise.all([197 promise_rejects(t, new TypeError(), cancelPromise),198 readPromise199 ]);200}, 'cancel() on a released reader is a no-op and does not pass through');201promise_test(t => {202 const promiseAsserts = [];203 let controller;204 const theError = { name: 'unique error' };205 const rs = new ReadableStream({206 start(c) {207 controller = c;208 }209 });210 const reader1 = rs.getReader();211 promiseAsserts.push(212 promise_rejects(t, theError, reader1.closed),213 promise_rejects(t, theError, reader1.read())214 );215 assert_throws(new TypeError(), () => rs.getReader(), 'trying to get another reader before erroring should throw');216 controller.error(theError);217 reader1.releaseLock();218 const reader2 = rs.getReader();219 promiseAsserts.push(220 promise_rejects(t, theError, reader2.closed),221 promise_rejects(t, theError, reader2.read())222 );223 return Promise.all(promiseAsserts);224}, 'Getting a second reader after erroring the stream and releasing the reader should succeed');225promise_test(t => {226 let controller;227 const rs = new ReadableStream({228 start(c) {229 controller = c;230 }231 });232 const promise = rs.getReader().closed.then(233 t.unreached_func('closed promise should not be fulfilled when stream is errored'),234 err => {235 assert_equals(err, undefined, 'passed error should be undefined as it was');236 }237 );238 controller.error();239 return promise;240}, 'ReadableStreamDefaultReader closed promise should be rejected with undefined if that is the error');241promise_test(t => {242 const rs = new ReadableStream({243 start() {244 return Promise.reject();245 }246 });247 return rs.getReader().read().then(248 t.unreached_func('read promise should not be fulfilled when stream is errored'),249 err => {250 assert_equals(err, undefined, 'passed error should be undefined as it was');251 }252 );253}, 'ReadableStreamDefaultReader: if start rejects with no parameter, it should error the stream with an undefined ' +254 'error');255promise_test(t => {256 const theError = { name: 'unique string' };257 let controller;258 const rs = new ReadableStream({259 start(c) {260 controller = c;261 }262 });263 const promise = promise_rejects(t, theError, rs.getReader().closed);264 controller.error(theError);265 return promise;266}, 'Erroring a ReadableStream after checking closed should reject ReadableStreamDefaultReader closed promise');267promise_test(t => {268 const theError = { name: 'unique string' };269 let controller;270 const rs = new ReadableStream({271 start(c) {272 controller = c;273 }274 });275 controller.error(theError);276 // Let's call getReader twice for extra test coverage of this code path.277 rs.getReader().releaseLock();278 return promise_rejects(t, theError, rs.getReader().closed);279}, 'Erroring a ReadableStream before checking closed should reject ReadableStreamDefaultReader closed promise');280promise_test(() => {281 let controller;282 const rs = new ReadableStream({283 start(c) {284 controller = c;285 }286 });287 const reader = rs.getReader();288 const promise = Promise.all([289 reader.read().then(result => {290 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (1)');291 }),292 reader.read().then(result => {293 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (2)');294 }),295 reader.closed296 ]);297 controller.close();298 return promise;299}, 'Reading twice on a stream that gets closed');300promise_test(() => {301 let controller;302 const rs = new ReadableStream({303 start(c) {304 controller = c;305 }306 });307 controller.close();308 const reader = rs.getReader();309 return Promise.all([310 reader.read().then(result => {311 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (1)');312 }),313 reader.read().then(result => {314 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (2)');315 }),316 reader.closed317 ]);318}, 'Reading twice on a closed stream');319promise_test(t => {320 let controller;321 const rs = new ReadableStream({322 start(c) {323 controller = c;324 }325 });326 const myError = { name: 'mashed potatoes' };327 controller.error(myError);328 const reader = rs.getReader();329 return Promise.all([330 promise_rejects(t, myError, reader.read()),331 promise_rejects(t, myError, reader.read()),332 promise_rejects(t, myError, reader.closed)333 ]);334}, 'Reading twice on an errored stream');335promise_test(t => {336 let controller;337 const rs = new ReadableStream({338 start(c) {339 controller = c;340 }341 });342 const myError = { name: 'mashed potatoes' };343 const reader = rs.getReader();344 const promise = Promise.all([345 promise_rejects(t, myError, reader.read()),346 promise_rejects(t, myError, reader.read()),347 promise_rejects(t, myError, reader.closed)348 ]);349 controller.error(myError);350 return promise;351}, 'Reading twice on a stream that gets errored');...
readable-stream-reader.js
Source:readable-stream-reader.js
1'use strict';2if (self.importScripts) {3 self.importScripts('../resources/rs-utils.js');4 self.importScripts('/resources/testharness.js');5}6let ReadableStreamReader;7test(() => {8 // It's not exposed globally, but we test a few of its properties here.9 ReadableStreamReader = (new ReadableStream()).getReader().constructor;10}, 'Can get the ReadableStreamReader constructor indirectly');11test(() => {12 assert_throws(new TypeError(), () => new ReadableStreamReader('potato'));13 assert_throws(new TypeError(), () => new ReadableStreamReader({}));14 assert_throws(new TypeError(), () => new ReadableStreamReader());15}, 'ReadableStreamReader constructor should get a ReadableStream object as argument');16test(() => {17 const methods = ['cancel', 'constructor', 'read', 'releaseLock'];18 const properties = methods.concat(['closed']).sort();19 const rsReader = new ReadableStreamReader(new ReadableStream());20 const proto = Object.getPrototypeOf(rsReader);21 assert_array_equals(Object.getOwnPropertyNames(proto).sort(), properties);22 for (const m of methods) {23 const propDesc = Object.getOwnPropertyDescriptor(proto, m);24 assert_equals(propDesc.enumerable, false, 'method should be non-enumerable');25 assert_equals(propDesc.configurable, true, 'method should be configurable');26 assert_equals(propDesc.writable, true, 'method should be writable');27 assert_equals(typeof rsReader[m], 'function', 'should have be a method');28 }29 const closedPropDesc = Object.getOwnPropertyDescriptor(proto, 'closed');30 assert_equals(closedPropDesc.enumerable, false, 'closed should be non-enumerable');31 assert_equals(closedPropDesc.configurable, true, 'closed should be configurable');32 assert_not_equals(closedPropDesc.get, undefined, 'closed should have a getter');33 assert_equals(closedPropDesc.set, undefined, 'closed should not have a setter');34 assert_equals(rsReader.cancel.length, 1, 'cancel has 1 parameter');35 assert_not_equals(rsReader.closed, undefined, 'has a non-undefined closed property');36 assert_equals(typeof rsReader.closed.then, 'function', 'closed property is thenable');37 assert_equals(typeof rsReader.constructor, 'function', 'has a constructor method');38 assert_equals(rsReader.constructor.length, 1, 'constructor has 1 parameter');39 assert_equals(typeof rsReader.read, 'function', 'has a getReader method');40 assert_equals(rsReader.read.length, 0, 'read has no parameters');41 assert_equals(typeof rsReader.releaseLock, 'function', 'has a releaseLock method');42 assert_equals(rsReader.releaseLock.length, 0, 'releaseLock has no parameters');43}, 'ReadableStreamReader instances should have the correct list of properties');44test(() => {45 const rsReader = new ReadableStreamReader(new ReadableStream());46 assert_equals(rsReader.closed, rsReader.closed, 'closed should return the same promise');47}, 'ReadableStreamReader closed should always return the same promise object');48test(() => {49 const rs = new ReadableStream();50 new ReadableStreamReader(rs); // Constructing directly the first time should be fine.51 assert_throws(new TypeError(), () => new ReadableStreamReader(rs),52 'constructing directly the second time should fail');53}, 'Constructing a ReadableStreamReader directly should fail if the stream is already locked (via direct ' +54 'construction)');55test(() => {56 const rs = new ReadableStream();57 new ReadableStreamReader(rs); // Constructing directly should be fine.58 assert_throws(new TypeError(), () => rs.getReader(), 'getReader() should fail');59}, 'Getting a ReadableStreamReader via getReader should fail if the stream is already locked (via direct ' +60 'construction)');61test(() => {62 const rs = new ReadableStream();63 rs.getReader(); // getReader() should be fine.64 assert_throws(new TypeError(), () => new ReadableStreamReader(rs), 'constructing directly should fail');65}, 'Constructing a ReadableStreamReader directly should fail if the stream is already locked (via getReader)');66test(() => {67 const rs = new ReadableStream();68 rs.getReader(); // getReader() should be fine.69 assert_throws(new TypeError(), () => rs.getReader(), 'getReader() should fail');70}, 'Getting a ReadableStreamReader via getReader should fail if the stream is already locked (via getReader)');71test(() => {72 const rs = new ReadableStream({73 start(c) {74 c.close();75 }76 });77 new ReadableStreamReader(rs); // Constructing directly should not throw.78}, 'Constructing a ReadableStreamReader directly should be OK if the stream is closed');79test(() => {80 const theError = new Error('don\'t say i didn\'t warn ya');81 const rs = new ReadableStream({82 start(c) {83 c.error(theError);84 }85 });86 new ReadableStreamReader(rs); // Constructing directly should not throw.87}, 'Constructing a ReadableStreamReader directly should be OK if the stream is errored');88promise_test(() => {89 let controller;90 const rs = new ReadableStream({91 start(c) {92 controller = c;93 }94 });95 const reader = rs.getReader();96 const promise = reader.read().then(result => {97 assert_object_equals(result, { value: 'a', done: false }, 'read() should fulfill with the enqueued chunk');98 });99 controller.enqueue('a');100 return promise;101}, 'Reading from a reader for an empty stream will wait until a chunk is available');102promise_test(() => {103 let cancelCalled = false;104 const passedReason = new Error('it wasn\'t the right time, sorry');105 const rs = new ReadableStream({106 cancel(reason) {107 assert_true(rs.locked, 'the stream should still be locked');108 assert_throws(new TypeError(), () => rs.getReader(), 'should not be able to get another reader');109 assert_equals(reason, passedReason, 'the cancellation reason is passed through to the underlying source');110 cancelCalled = true;111 }112 });113 const reader = rs.getReader();114 return reader.cancel(passedReason).then(() => assert_true(cancelCalled));115}, 'cancel() on a reader does not release the reader');116promise_test(() => {117 let controller;118 const rs = new ReadableStream({119 start(c) {120 controller = c;121 }122 });123 const reader = rs.getReader();124 const promise = reader.closed;125 controller.close();126 return promise;127}, 'closed should be fulfilled after stream is closed (.closed access before acquiring)');128promise_test(t => {129 let controller;130 const rs = new ReadableStream({131 start(c) {132 controller = c;133 }134 });135 const reader1 = rs.getReader();136 reader1.releaseLock();137 const reader2 = rs.getReader();138 controller.close();139 return Promise.all([140 promise_rejects(t, new TypeError(), reader1.closed),141 reader2.closed142 ]);143}, 'closed should be rejected after reader releases its lock (multiple stream locks)');144promise_test(() => {145 const rs = new ReadableStream({146 start(c) {147 c.enqueue('a');148 c.enqueue('b');149 c.close();150 }151 });152 const reader1 = rs.getReader();153 const promise1 = reader1.read().then(r => {154 assert_object_equals(r, { value: 'a', done: false }, 'reading the first chunk from reader1 works');155 });156 reader1.releaseLock();157 const reader2 = rs.getReader();158 const promise2 = reader2.read().then(r => {159 assert_object_equals(r, { value: 'b', done: false }, 'reading the second chunk from reader2 works');160 });161 reader2.releaseLock();162 return Promise.all([promise1, promise2]);163}, 'Multiple readers can access the stream in sequence');164promise_test(() => {165 const rs = new ReadableStream({166 start(c) {167 c.enqueue('a');168 }169 });170 const reader1 = rs.getReader();171 reader1.releaseLock();172 const reader2 = rs.getReader();173 // Should be a no-op174 reader1.releaseLock();175 return reader2.read().then(result => {176 assert_object_equals(result, { value: 'a', done: false },177 'read() should still work on reader2 even after reader1 is released');178 });179}, 'Cannot use an already-released reader to unlock a stream again');180promise_test(t => {181 const rs = new ReadableStream({182 start(c) {183 c.enqueue('a');184 },185 cancel() {186 assert_unreached('underlying source cancel should not be called');187 }188 });189 const reader = rs.getReader();190 reader.releaseLock();191 const cancelPromise = reader.cancel();192 const reader2 = rs.getReader();193 const readPromise = reader2.read().then(r => {194 assert_object_equals(r, { value: 'a', done: false }, 'a new reader should be able to read a chunk');195 });196 return Promise.all([197 promise_rejects(t, new TypeError(), cancelPromise),198 readPromise199 ]);200}, 'cancel() on a released reader is a no-op and does not pass through');201promise_test(t => {202 const promiseAsserts = [];203 let controller;204 const theError = { name: 'unique error' };205 const rs = new ReadableStream({206 start(c) {207 controller = c;208 }209 });210 const reader1 = rs.getReader();211 promiseAsserts.push(212 promise_rejects(t, theError, reader1.closed),213 promise_rejects(t, theError, reader1.read())214 );215 assert_throws(new TypeError(), () => rs.getReader(), 'trying to get another reader before erroring should throw');216 controller.error(theError);217 reader1.releaseLock();218 const reader2 = rs.getReader();219 promiseAsserts.push(220 promise_rejects(t, theError, reader2.closed),221 promise_rejects(t, theError, reader2.read())222 );223 return Promise.all(promiseAsserts);224}, 'Getting a second reader after erroring the stream and releasing the reader should succeed');225promise_test(t => {226 let controller;227 const rs = new ReadableStream({228 start(c) {229 controller = c;230 }231 });232 const promise = rs.getReader().closed.then(233 t.unreached_func('closed promise should not be fulfilled when stream is errored'),234 err => {235 assert_equals(err, undefined, 'passed error should be undefined as it was');236 }237 );238 controller.error();239 return promise;240}, 'ReadableStreamReader closed promise should be rejected with undefined if that is the error');241promise_test(t => {242 const rs = new ReadableStream({243 start() {244 return Promise.reject();245 }246 });247 return rs.getReader().read().then(248 t.unreached_func('read promise should not be fulfilled when stream is errored'),249 err => {250 assert_equals(err, undefined, 'passed error should be undefined as it was');251 }252 );253}, 'ReadableStreamReader: if start rejects with no parameter, it should error the stream with an undefined error');254promise_test(t => {255 const theError = { name: 'unique string' };256 let controller;257 const rs = new ReadableStream({258 start(c) {259 controller = c;260 }261 });262 const promise = promise_rejects(t, theError, rs.getReader().closed);263 controller.error(theError);264 return promise;265}, 'Erroring a ReadableStream after checking closed should reject ReadableStreamReader closed promise');266promise_test(t => {267 const theError = { name: 'unique string' };268 let controller;269 const rs = new ReadableStream({270 start(c) {271 controller = c;272 }273 });274 controller.error(theError);275 // Let's call getReader twice for extra test coverage of this code path.276 rs.getReader().releaseLock();277 return promise_rejects(t, theError, rs.getReader().closed);278}, 'Erroring a ReadableStream before checking closed should reject ReadableStreamReader closed promise');279promise_test(() => {280 let controller;281 const rs = new ReadableStream({282 start(c) {283 controller = c;284 }285 });286 const reader = rs.getReader();287 const promise = Promise.all([288 reader.read().then(result => {289 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (1)');290 }),291 reader.read().then(result => {292 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (2)');293 }),294 reader.closed295 ]);296 controller.close();297 return promise;298}, 'Reading twice on a stream that gets closed');299promise_test(() => {300 let controller;301 const rs = new ReadableStream({302 start(c) {303 controller = c;304 }305 });306 controller.close();307 const reader = rs.getReader();308 return Promise.all([309 reader.read().then(result => {310 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (1)');311 }),312 reader.read().then(result => {313 assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close (2)');314 }),315 reader.closed316 ]);317}, 'Reading twice on a closed stream');318promise_test(t => {319 let controller;320 const rs = new ReadableStream({321 start(c) {322 controller = c;323 }324 });325 const myError = { name: 'mashed potatoes' };326 controller.error(myError);327 const reader = rs.getReader();328 return Promise.all([329 promise_rejects(t, myError, reader.read()),330 promise_rejects(t, myError, reader.read()),331 promise_rejects(t, myError, reader.closed)332 ]);333}, 'Reading twice on an errored stream');334promise_test(t => {335 let controller;336 const rs = new ReadableStream({337 start(c) {338 controller = c;339 }340 });341 const myError = { name: 'mashed potatoes' };342 const reader = rs.getReader();343 const promise = Promise.all([344 promise_rejects(t, myError, reader.read()),345 promise_rejects(t, myError, reader.read()),346 promise_rejects(t, myError, reader.closed)347 ]);348 controller.error(myError);349 return promise;350}, 'Reading twice on a stream that gets errored');...
Using AI Code Generation
1var wptools = require('wptools');2var rsReader = require('rs-reader');3var fs = require('fs');4var path = require('path');5var async = require('async');6var request = require('request');7var _ = require('underscore');8var util = require('util');9var jsonfile = require('jsonfile');10var file = 'data.json';11var data = [];12var data2 = [];13var data3 = [];14var data4 = [];15var data5 = [];16var data6 = [];17var data7 = [];18var data8 = [];19var data9 = [];20var data10 = [];21var data11 = [];22var data12 = [];23var data13 = [];24var data14 = [];25var data15 = [];26var data16 = [];27var data17 = [];28var data18 = [];29var data19 = [];30var data20 = [];31var data21 = [];32var data22 = [];33var data23 = [];34var data24 = [];35var data25 = [];36var data26 = [];37var data27 = [];38var data28 = [];39var data29 = [];40var data30 = [];41var data31 = [];42var data32 = [];43var data33 = [];44var data34 = [];45var data35 = [];46var data36 = [];47var data37 = [];48var data38 = [];49var data39 = [];50var data40 = [];51var data41 = [];52var data42 = [];53var data43 = [];54var data44 = [];55var data45 = [];56var data46 = [];57var data47 = [];58var data48 = [];59var data49 = [];60var data50 = [];61var data51 = [];62var data52 = [];63var data53 = [];64var data54 = [];65var data55 = [];66var data56 = [];67var data57 = [];68var data58 = [];69var data59 = [];70var data60 = [];71var data61 = [];72var data62 = [];73var data63 = [];74var data64 = [];75var data65 = [];76var data66 = [];77var data67 = [];78var data68 = [];79var data69 = [];80var data70 = [];81var data71 = [];82var data72 = [];83var data73 = [];84var data74 = [];85var data75 = [];86var data76 = [];87var data77 = [];88var data78 = [];89var data79 = [];90var data80 = [];91var data81 = [];92var data82 = [];93var data83 = [];94var data84 = [];
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama').get(function(err, resp) {3 console.log(resp);4});5var wptools = require('wptools');6var page = wptools.page('Barack Obama').get(function(err, resp) {7 console.log(resp);8});9var wptools = require('wptools');10var page = wptools.page('Barack Obama').get(function(err, resp) {11 console.log(resp);12});13var wptools = require('wptools');14var page = wptools.page('Barack Obama').get(function(err, resp) {15 console.log(resp);16});17var wptools = require('wptools');18var page = wptools.page('Barack Obama').get(function(err, resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama').get(function(err, resp) {23 console.log(resp);24});25var wptools = require('wptools');26var page = wptools.page('Barack Obama').get(function(err, resp) {27 console.log(resp);28});29var wptools = require('wptools');30var page = wptools.page('Barack Obama').get(function(err, resp) {31 console.log(resp);32});33var wptools = require('wptools');34var page = wptools.page('Barack Obama').get(function(err, resp) {35 console.log(resp);36});37var wptools = require('wptools');
Using AI Code Generation
1var wptools = require('wptools');2var rsReader = require('rs-reader');3var rs = new rsReader();4rs.on('data', function(data) {5 console.log(data);6});7wptools.page('Barack Obama').get(function(err, doc) {8 console.log(doc);9 rs.read(doc);10});11var Readable = require('stream').Readable;12var rsReader = module.exports = function(opts) {13 Readable.call(this, opts);14 this._data = [];15};16require('util').inherits(rsReader, Readable);17rsReader.prototype.read = function(data) {18 this._data.push(data);19 this.push(data);20};21rsReader.prototype._read = function() {22 var data = this._data.shift();23 if (data) {24 this.push(data);25 } else {26 this.push(null);27 }28};29{ title: 'Barack Obama',30 modified: { timestamp: '2015-12-30T15:56:10Z', 'new': '' },31 labels: { en: 'Barack Obama' },32 { P31: [ [Object] ],
Using AI Code Generation
1var wptoolkit = require("./wptoolkit.js");2var rsReader = wptoolkit.rsReader;3var args = process.argv.slice(2);4var rsfile = args[0];5var rs = rsReader(rsfile);6var rsjson = JSON.stringify(rs);7console.log(rsjson);
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var file = path.resolve(__dirname, 'list.json');5var data = require(file);6var rsReader = require('./rsReader.js');7var rsReader2 = require('./rsReader2.js');8var rsReader3 = require('./rsReader3.js');9var rsReader4 = require('./rsReader4.js');10var rsReader5 = require('./rsReader5.js');11var rsReader6 = require('./rsReader6.js');12var rsReader7 = require('./rsReader7.js');13var rsReader8 = require('./rsReader8.js');14var rsReader9 = require('./rsReader9.js');15var rsReader10 = require('./rsReader10.js');16var rsReader11 = require('./rsReader11.js');17var rsReader12 = require('./rsReader12.js');18var rsReader13 = require('./rsReader13.js');19var rsReader14 = require('./rsReader14.js');20var rsReader15 = require('./rsReader15.js');21var rsReader16 = require('./rsReader16.js');22var rsReader17 = require('./rsReader17.js');23var rsReader18 = require('./rsReader18.js');24var rsReader19 = require('./rsReader19.js');25var rsReader20 = require('./rsReader20.js');26var rsReader21 = require('./rsReader21.js');27var rsReader22 = require('./rsReader22.js');28var rsReader23 = require('./rsReader23.js');29var rsReader24 = require('./rsReader24.js');30var rsReader25 = require('./rsReader25.js');31var rsReader26 = require('./rsReader26.js');32var rsReader27 = require('./rsReader27.js');33var rsReader28 = require('./rsReader28.js');34var rsReader29 = require('./rsReader29.js');35var rsReader30 = require('./rsReader30.js');36var rsReader31 = require('./rsReader31.js');37var rsReader32 = require('./rsReader32.js');38var rsReader33 = require('./rsReader33.js');39var rsReader34 = require('./rsReader34.js');40var rsReader35 = require('./rsReader35.js');41var rsReader36 = require('./rsReader36.js');42var rsReader37 = require('./rsReader37.js');43var rsReader38 = require('./rsReader38.js');
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3rs.on('data', function(data) {4 console.log(data);5});6rs.on('end', function() {7 console.log('end');8});9var wptools = require('wptools');10var fs = require('fs');11rs.on('data', function(data) {12 console.log(data);13});14rs.on('end', function() {15 console.log('end');16});17var wptools = require('wptools');18var fs = require('fs');19rs.on('data', function(data) {20 console.log(data);21});22rs.on('end', function() {23 console.log('end');24});25var wptools = require('wptools');26var fs = require('fs');27rs.on('data', function(data) {28 console.log(data);29});30rs.on('end', function() {31 console.log('end');32});33 * @param {string} pageId - The pageId of
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!!