Best JavaScript code snippet using wpt
streams_writable_test.ts
Source:streams_writable_test.ts
1// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.2import { unitTest, assert, assertEquals, assertThrows } from "./test_util.ts";3unitTest(function writableStreamDesiredSizeOnReleasedWriter() {4 const ws = new WritableStream();5 const writer = ws.getWriter();6 writer.releaseLock();7 assertThrows(() => {8 writer.desiredSize;9 }, TypeError);10});11unitTest(function writableStreamDesiredSizeInitialValue() {12 const ws = new WritableStream();13 const writer = ws.getWriter();14 assertEquals(writer.desiredSize, 1);15});16unitTest(async function writableStreamDesiredSizeClosed() {17 const ws = new WritableStream();18 const writer = ws.getWriter();19 await writer.close();20 assertEquals(writer.desiredSize, 0);21});22unitTest(function writableStreamStartThrowsDesiredSizeNull() {23 const ws = new WritableStream({24 start(c): void {25 c.error();26 },27 });28 const writer = ws.getWriter();29 assertEquals(writer.desiredSize, null, "desiredSize should be null");30});31unitTest(function getWriterOnClosingStream() {32 const ws = new WritableStream({});33 const writer = ws.getWriter();34 writer.close();35 writer.releaseLock();36 ws.getWriter();37});38unitTest(async function getWriterOnClosedStream() {39 const ws = new WritableStream({});40 const writer = ws.getWriter();41 await writer.close();42 writer.releaseLock();43 ws.getWriter();44});45unitTest(function getWriterOnAbortedStream() {46 const ws = new WritableStream({});47 const writer = ws.getWriter();48 writer.abort();49 writer.releaseLock();50 ws.getWriter();51});52unitTest(function getWriterOnErroredStream() {53 const ws = new WritableStream({54 start(c): void {55 c.error();56 },57 });58 const writer = ws.getWriter();59 return writer.closed.then(60 (v) => {61 throw new Error(`writer.closed fulfilled unexpectedly with: ${v}`);62 },63 () => {64 writer.releaseLock();65 ws.getWriter();66 }67 );68});69unitTest(function closedAndReadyOnReleasedWriter() {70 const ws = new WritableStream({});71 const writer = ws.getWriter();72 writer.releaseLock();73 return writer.closed.then(74 (v) => {75 throw new Error("writer.closed fulfilled unexpectedly with: " + v);76 },77 (closedRejection) => {78 assertEquals(79 closedRejection.name,80 "TypeError",81 "closed promise should reject with a TypeError"82 );83 return writer.ready.then(84 (v) => {85 throw new Error("writer.ready fulfilled unexpectedly with: " + v);86 },87 (readyRejection) =>88 assertEquals(89 readyRejection,90 closedRejection,91 "ready promise should reject with the same error"92 )93 );94 }95 );96});97unitTest(function sinkMethodsCalledAsMethods() {98 let thisObject: Sink | null = null;99 // Calls to Sink methods after the first are implicitly ignored. Only the100 // first value that is passed to the resolver is used.101 class Sink {102 start(): void {103 assertEquals(this, thisObject, "start should be called as a method");104 }105 write(): void {106 assertEquals(this, thisObject, "write should be called as a method");107 }108 close(): void {109 assertEquals(this, thisObject, "close should be called as a method");110 }111 abort(): void {112 assertEquals(this, thisObject, "abort should be called as a method");113 }114 }115 const theSink = new Sink();116 thisObject = theSink;117 const ws = new WritableStream(theSink);118 const writer = ws.getWriter();119 writer.write("a");120 const closePromise = writer.close();121 const ws2 = new WritableStream(theSink);122 const writer2 = ws2.getWriter();123 const abortPromise = writer2.abort();124 return Promise.all([closePromise, abortPromise]).then(undefined);125});126unitTest(function sizeShouldNotBeCalledAsMethod() {127 const strategy = {128 size(): number {129 if (this !== undefined) {130 throw new Error("size called as a method");131 }132 return 1;133 },134 };135 const ws = new WritableStream({}, strategy);136 const writer = ws.getWriter();137 return writer.write("a");138});139unitTest(function redundantReleaseLockIsNoOp() {140 const ws = new WritableStream();141 const writer1 = ws.getWriter();142 assertEquals(143 undefined,144 writer1.releaseLock(),145 "releaseLock() should return undefined"146 );147 const writer2 = ws.getWriter();148 assertEquals(149 undefined,150 writer1.releaseLock(),151 "no-op releaseLock() should return undefined"152 );153 // Calling releaseLock() on writer1 should not interfere with writer2. If it did, then the ready promise would be154 // rejected.155 return writer2.ready;156});157unitTest(function readyPromiseShouldFireBeforeReleaseLock() {158 const events: string[] = [];159 const ws = new WritableStream();160 const writer = ws.getWriter();161 return writer.ready.then(() => {162 // Force the ready promise back to a pending state.163 const writerPromise = writer.write("dummy");164 const readyPromise = writer.ready.catch(() => events.push("ready"));165 const closedPromise = writer.closed.catch(() => events.push("closed"));166 writer.releaseLock();167 return Promise.all([readyPromise, closedPromise]).then(() => {168 assertEquals(169 events,170 ["ready", "closed"],171 "ready promise should fire before closed promise"172 );173 // Stop the writer promise hanging around after the test has finished.174 return Promise.all([writerPromise, ws.abort()]).then(undefined);175 });176 });177});178unitTest(function subclassingWritableStream() {179 class Subclass extends WritableStream {180 extraFunction(): boolean {181 return true;182 }183 }184 assert(185 Object.getPrototypeOf(Subclass.prototype) === WritableStream.prototype,186 "Subclass.prototype's prototype should be WritableStream.prototype"187 );188 assert(189 Object.getPrototypeOf(Subclass) === WritableStream,190 "Subclass's prototype should be WritableStream"191 );192 const sub = new Subclass();193 assert(194 sub instanceof WritableStream,195 "Subclass object should be an instance of WritableStream"196 );197 assert(198 sub instanceof Subclass,199 "Subclass object should be an instance of Subclass"200 );201 const lockedGetter = Object.getOwnPropertyDescriptor(202 WritableStream.prototype,203 "locked"204 )!.get!;205 assert(206 lockedGetter.call(sub) === sub.locked,207 "Subclass object should pass brand check"208 );209 assert(210 sub.extraFunction(),211 "extraFunction() should be present on Subclass object"212 );213});214unitTest(function lockedGetterShouldReturnTrue() {215 const ws = new WritableStream();216 assert(!ws.locked, "stream should not be locked");217 ws.getWriter();218 assert(ws.locked, "stream should be locked");...
streams_writable_test.mjs
Source:streams_writable_test.mjs
1import {assert, assertEquals, assertThrows, unitTest} from "./test_util.mjs";2unitTest(function writableStreamDesiredSizeOnReleasedWriter() {3 const ws = new WritableStream();4 const writer = ws.getWriter();5 writer.releaseLock();6 assertThrows(() => {7 writer.desiredSize;8 }, TypeError);9});10unitTest(function writableStreamDesiredSizeInitialValue() {11 const ws = new WritableStream();12 const writer = ws.getWriter();13 assertEquals(writer.desiredSize, 1);14});15unitTest(async function writableStreamDesiredSizeClosed() {16 const ws = new WritableStream();17 const writer = ws.getWriter();18 await writer.close();19 assertEquals(writer.desiredSize, 0);20});21unitTest(function writableStreamStartThrowsDesiredSizeNull() {22 const ws = new WritableStream({23 start(c) {24 c.error();25 }26 });27 const writer = ws.getWriter();28 assertEquals(writer.desiredSize, null, "desiredSize should be null");29});30unitTest(function getWriterOnClosingStream() {31 const ws = new WritableStream({});32 const writer = ws.getWriter();33 writer.close();34 writer.releaseLock();35 ws.getWriter();36});37unitTest(async function getWriterOnClosedStream() {38 const ws = new WritableStream({});39 const writer = ws.getWriter();40 await writer.close();41 writer.releaseLock();42 ws.getWriter();43});44unitTest(function getWriterOnAbortedStream() {45 const ws = new WritableStream({});46 const writer = ws.getWriter();47 writer.abort();48 writer.releaseLock();49 ws.getWriter();50});51unitTest(function getWriterOnErroredStream() {52 const ws = new WritableStream({53 start(c) {54 c.error();55 }56 });57 const writer = ws.getWriter();58 return writer.closed.then((v) => {59 throw new Error(`writer.closed fulfilled unexpectedly with: ${v}`);60 }, () => {61 writer.releaseLock();62 ws.getWriter();63 });64});65unitTest(function closedAndReadyOnReleasedWriter() {66 const ws = new WritableStream({});67 const writer = ws.getWriter();68 writer.releaseLock();69 return writer.closed.then((v) => {70 throw new Error("writer.closed fulfilled unexpectedly with: " + v);71 }, (closedRejection) => {72 assertEquals(closedRejection.name, "TypeError", "closed promise should reject with a TypeError");73 return writer.ready.then((v) => {74 throw new Error("writer.ready fulfilled unexpectedly with: " + v);75 }, (readyRejection) => assertEquals(readyRejection, closedRejection, "ready promise should reject with the same error"));76 });77});78unitTest(function sinkMethodsCalledAsMethods() {79 let thisObject = null;80 class Sink {81 start() {82 assertEquals(this, thisObject, "start should be called as a method");83 }84 write() {85 assertEquals(this, thisObject, "write should be called as a method");86 }87 close() {88 assertEquals(this, thisObject, "close should be called as a method");89 }90 abort() {91 assertEquals(this, thisObject, "abort should be called as a method");92 }93 }94 const theSink = new Sink();95 thisObject = theSink;96 const ws = new WritableStream(theSink);97 const writer = ws.getWriter();98 writer.write("a");99 const closePromise = writer.close();100 const ws2 = new WritableStream(theSink);101 const writer2 = ws2.getWriter();102 const abortPromise = writer2.abort();103 return Promise.all([closePromise, abortPromise]).then(void 0);104});105unitTest(function sizeShouldNotBeCalledAsMethod() {106 const strategy = {107 size() {108 if (this !== void 0) {109 throw new Error("size called as a method");110 }111 return 1;112 }113 };114 const ws = new WritableStream({}, strategy);115 const writer = ws.getWriter();116 return writer.write("a");117});118unitTest(function redundantReleaseLockIsNoOp() {119 const ws = new WritableStream();120 const writer1 = ws.getWriter();121 assertEquals(void 0, writer1.releaseLock(), "releaseLock() should return undefined");122 const writer2 = ws.getWriter();123 assertEquals(void 0, writer1.releaseLock(), "no-op releaseLock() should return undefined");124 return writer2.ready;125});126unitTest(function readyPromiseShouldFireBeforeReleaseLock() {127 const events = [];128 const ws = new WritableStream();129 const writer = ws.getWriter();130 return writer.ready.then(() => {131 const writerPromise = writer.write("dummy");132 const readyPromise = writer.ready.catch(() => events.push("ready"));133 const closedPromise = writer.closed.catch(() => events.push("closed"));134 writer.releaseLock();135 return Promise.all([readyPromise, closedPromise]).then(() => {136 assertEquals(events, ["ready", "closed"], "ready promise should fire before closed promise");137 return Promise.all([writerPromise, ws.abort()]).then(void 0);138 });139 });140});141unitTest(function subclassingWritableStream() {142 class Subclass extends WritableStream {143 extraFunction() {144 return true;145 }146 }147 assert(Object.getPrototypeOf(Subclass.prototype) === WritableStream.prototype, "Subclass.prototype's prototype should be WritableStream.prototype");148 assert(Object.getPrototypeOf(Subclass) === WritableStream, "Subclass's prototype should be WritableStream");149 const sub = new Subclass();150 assert(sub instanceof WritableStream, "Subclass object should be an instance of WritableStream");151 assert(sub instanceof Subclass, "Subclass object should be an instance of Subclass");152 const lockedGetter = Object.getOwnPropertyDescriptor(WritableStream.prototype, "locked").get;153 assert(lockedGetter.call(sub) === sub.locked, "Subclass object should pass brand check");154 assert(sub.extraFunction(), "extraFunction() should be present on Subclass object");155});156unitTest(function lockedGetterShouldReturnTrue() {157 const ws = new WritableStream();158 assert(!ws.locked, "stream should not be locked");159 ws.getWriter();160 assert(ws.locked, "stream should be locked");...
getters.js
Source:getters.js
1import { toCKB } from '../../services/ckb/utils'2export const lockedGetter = state => toCKB(state.locked)3export const apcGetter = state => state.apc4export const revenueGetter = state => toCKB(state.revenue)5export const loadingListGetter = state => state.loadingList...
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const path = require('path');4const _ = require('lodash');5const async = require('async');6const mkdirp = require('mkdirp');7const request = require('request');8const config = require('./config');9const { exec } = require('child_process');10const { spawn } = require('child_process');11const options = {12};13let searchResults = [];14let pageResults = [];15let pageId = '';16let pageExtract = '';17let pageImage = '';18let pageImageName = '';19let pageImageURL = '';20let pageImageExt = '';21let pageImageDir = '';22let pageImageFilePath = '';23let pageImageFilePath2 = '';24let pageImageFilePath3 = '';25let pageImageFilePath4 = '';26let pageImageFilePath5 = '';27let pageImageFilePath6 = '';28let pageImageFilePath7 = '';29let pageImageFilePath8 = '';30let pageImageFilePath9 = '';31let pageImageFilePath10 = '';32let pageImageFilePath11 = '';33let pageImageFilePath12 = '';34let pageImageFilePath13 = '';35let pageImageFilePath14 = '';36let pageImageFilePath15 = '';37let pageImageFilePath16 = '';38let pageImageFilePath17 = '';39let pageImageFilePath18 = '';40let pageImageFilePath19 = '';41let pageImageFilePath20 = '';42let pageImageFilePath21 = '';43let pageImageFilePath22 = '';44let pageImageFilePath23 = '';45let pageImageFilePath24 = '';46let pageImageFilePath25 = '';47let pageImageFilePath26 = '';48let pageImageFilePath27 = '';49let pageImageFilePath28 = '';50let pageImageFilePath29 = '';51let pageImageFilePath30 = '';52let pageImageFilePath31 = '';53let pageImageFilePath32 = '';54let pageImageFilePath33 = '';
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const options = {4};5const page = wptools.page('Jimi Hendrix', options);6page.get((err, info, raw) => {7 if (err) {8 console.error(err);9 }10 else {11 fs.writeFile('test.json', JSON.stringify(info, null, 2), (err) => {12 if (err) throw err;13 console.log('The file has been saved!');14 });15 }16});
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3var data = fs.readFileSync('test.json');4var json = JSON.parse(data);5var arr = json.query.pages;6var keys = Object.keys(arr);7var pageid = keys[0];8var title = arr[pageid].title;9var page = wptools.page(title);10page.get(function(err, info) {11 if (err) {12 console.log(err);13 } else {14 console.log(info);15 }16});17var page = wptools.page(title);18page.get(function(err, info) {19 if (err) {20 console.log(err);21 } else {22 console.log(info);23 }24});25var page = wptools.page(title);26page.get(function(err, info) {27 if (err) {28 console.log(err);29 } else {30 console.log(info);31 }32});33var page = wptools.page(title);34page.get(function(err, info) {35 if (err) {36 console.log(err);37 } else {38 console.log(info);39 }40});41var page = wptools.page(title);42page.get(function(err, info) {43 if (err) {44 console.log(err);45 } else {46 console.log(info);47 }48});49var page = wptools.page(title);50page.get(function(err, info) {51 if (err) {52 console.log(err);53 } else {54 console.log(info);55 }56});57var page = wptools.page(title);58page.get(function(err, info) {59 if (err) {60 console.log(err);61 } else {62 console.log(info);63 }64});65var page = wptools.page(title);66page.get(function(err, info) {67 if (err) {68 console.log(err);69 } else {70 console.log(info);71 }72});73var page = wptools.page(title);74page.get(function(err, info) {75 if (err) {
Using AI Code Generation
1const wptools = require('wptools');2const { lockedGetter } = require('locked-getter');3const getter = async (page) => {4 const data = await wptools.page(page).get();5 return data;6};7const lockedGetterFn = lockedGetter(getter, 1000);8const data = await lockedGetterFn('Albert_Einstein');9console.log(data);10const wptools = require('wptools');11const { lockedGetter } = require('locked-getter');12const getter = async (page) => {13 const data = await wptools.page(page).get();14 return data;15};16const lockedGetterFn = lockedGetter(getter, 1000);17const data = await lockedGetterFn('Albert_Einstein');18console.log(data);19const wptools = require('wptools');20const { lockedGetter } = require('locked-getter');21const getter = async (page) => {22 const data = await wptools.page(page).get();23 return data;24};25const lockedGetterFn = lockedGetter(getter, 1000);26const data = await lockedGetterFn('Albert_Einstein');27console.log(data);28const wptools = require('wptools');29const { lockedGetter } = require('locked-getter');30const getter = async (page) => {31 const data = await wptools.page(page).get();32 return data;33};34const lockedGetterFn = lockedGetter(getter, 1000);
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var pages = JSON.parse(fs.readFileSync('pages.json'));4var wikidata = fs.createWriteStream('wikidata.json');5wikidata.write('{\n');6var getWikidata = function(page) {7 wptools.page(page)8 .get(function(err, page) {9 if (!err) {10 wikidata.write('"' + page.data.page + '": "' + page.data.wikidata + '",\n');11 }12 });13};14pages.forEach(function(page) {15 getWikidata(page);16});17wikidata.write('}');18wikidata.end();
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org', 'A.1b8e7c8c0b0d2e2e1a8c1e0f3a3c0a3e');3 if (err) return console.error(err);4 test.getTestStatus(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 test.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9 });10 });11});12var wpt = require('webpagetest');13var test = wpt('www.webpagetest.org', 'A.1b8e7c8c0b0d2e2e1a8c1e0f3a3c0a3e');14 if (err) return console.error(err);15 test.getTestStatus(data.data.testId, function(err, data) {16 if (err) return console.error(err);17 test.getTestResults(data.data.testId, function(err, data) {18 if (err) return console.error(err);19 console.log(data);20 });21 });22});23var wpt = require('webpagetest');24var test = wpt('www.webpagetest.org', 'A.1b8e7c8c0b0d2e2e1a8c1e0f3a3c0a3e');25 if (err) return console.error(err);26 test.getTestStatus(data.data.testId, function(err, data) {27 if (err) return console.error(err);28 test.getTestResults(data.data.testId, function(err, data) {29 if (err) return console.error(err);30 console.log(data);31 });32 });33});34var wpt = require('webpagetest
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4var webpagetest = new wpt(options);5var testId = "170611_3A_1d0b6d5a6a6f5a6e5d6e5b5a5a6d5b6a";6var data = {7};8webpagetest.runTest(url, data, function(err, data) {9 if (err) {10 console.log(err);11 } else {12 console.log(data);13 }14});
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!!