Best JavaScript code snippet using wpt
index.ts
Source:index.ts
...50 }51}52;(async () => {53 const twodEvents = {54 // en: await createPromise(path.join(root, '6-npcdata', 'en.txt')),55 // fr: await createPromise(path.join(root, '6-npcdata', 'fr.txt')),56 // de: await createPromise(path.join(root, '6-npcdata', 'de.txt')),57 // es: await createPromise(path.join(root, '6-npcdata', 'es.txt')),58 // it: await createPromise(path.join(root, '6-npcdata', 'it.txt')),59 // ru: await createPromise(path.join(root, '6-npcdata', 'ru.txt')),60 // cs: await createPromise(path.join(root, '6-npcdata', 'cs.txt')),61 // pl: await createPromise(path.join(root, '6-npcdata', 'pl.txt')),62 // zhHans: await createPromise(path.join(root, '6-npcdata', 'zh-Hans.txt')),63 // zhHant: await createPromise(path.join(root, '6-npcdata', 'zh-Hant.txt')),64 en: await createPromise(path.join(root, '7-2devents', 'en.txt')),65 fr: await createPromise(path.join(root, '7-2devents', 'fr.txt')),66 de: await createPromise(path.join(root, '7-2devents', 'de.txt')),67 es: await createPromise(path.join(root, '7-2devents', 'es.txt')),68 it: await createPromise(path.join(root, '7-2devents', 'it.txt')),69 ru: await createPromise(path.join(root, '7-2devents', 'ru.txt')),70 cs: await createPromise(path.join(root, '7-2devents', 'cs.txt')),71 pl: await createPromise(path.join(root, '7-2devents', 'pl.txt')),72 zhHans: await createPromise(path.join(root, '7-2devents', 'zh-Hans.txt')),73 zhHant: await createPromise(path.join(root, '7-2devents', 'zh-Hant.txt')),74 // en: await createPromise(path.join(root, '8-2devents', 'en.txt')),75 // fr: await createPromise(path.join(root, '8-2devents', 'fr.txt')),76 // de: await createPromise(path.join(root, '8-2devents', 'de.txt')),77 // es: await createPromise(path.join(root, '8-2devents', 'es.txt')),78 // it: await createPromise(path.join(root, '8-2devents', 'it.txt')),79 // ru: await createPromise(path.join(root, '8-2devents', 'ru.txt')),80 // cs: await createPromise(path.join(root, '8-2devents', 'cs.txt')),81 // pl: await createPromise(path.join(root, '8-2devents', 'pl.txt')),82 // zhHans: await createPromise(path.join(root, '8-2devents', 'zh-Hans.txt')),83 // zhHant: await createPromise(path.join(root, '8-2devents', 'zh-Hant.txt')),84 // en: await createPromise(path.join(root, 'merge-2devents', 'en.txt')),85 }86 const mapstats = {87 // en: await createPromise(path.join(root, '6-mapstats', 'en.txt')),88 // fr: await createPromise(path.join(root, '6-mapstats', 'fr.txt')),89 // de: await createPromise(path.join(root, '6-mapstats', 'de.txt')),90 // es: await createPromise(path.join(root, '6-mapstats', 'es.txt')),91 // it: await createPromise(path.join(root, '6-mapstats', 'it.txt')),92 // ru: await createPromise(path.join(root, '6-mapstats', 'ru.txt')),93 // cs: await createPromise(path.join(root, '6-mapstats', 'cs.txt')),94 // pl: await createPromise(path.join(root, '6-mapstats', 'pl.txt')),95 // zhHans: await createPromise(path.join(root, '6-mapstats', 'zh-Hans.txt')),96 // zhHant: await createPromise(path.join(root, '6-mapstats', 'zh-Hant.txt')),97 en: await createPromise(path.join(root, '7-mapstats', 'en.txt')),98 fr: await createPromise(path.join(root, '7-mapstats', 'fr.txt')),99 de: await createPromise(path.join(root, '7-mapstats', 'de.txt')),100 es: await createPromise(path.join(root, '7-mapstats', 'es.txt')),101 it: await createPromise(path.join(root, '7-mapstats', 'it.txt')),102 ru: await createPromise(path.join(root, '7-mapstats', 'ru.txt')),103 cs: await createPromise(path.join(root, '7-mapstats', 'cs.txt')),104 pl: await createPromise(path.join(root, '7-mapstats', 'pl.txt')),105 zhHans: await createPromise(path.join(root, '7-mapstats', 'zh-Hans.txt')),106 zhHant: await createPromise(path.join(root, '7-mapstats', 'zh-Hant.txt')),107 // en: await createPromise(path.join(root, '8-mapstats', 'en.txt')),108 // fr: await createPromise(path.join(root, '8-mapstats', 'fr.txt')),109 // de: await createPromise(path.join(root, '8-mapstats', 'de.txt')),110 // es: await createPromise(path.join(root, '8-mapstats', 'es.txt')),111 // it: await createPromise(path.join(root, '8-mapstats', 'it.txt')),112 // ru: await createPromise(path.join(root, '8-mapstats', 'ru.txt')),113 // cs: await createPromise(path.join(root, '8-mapstats', 'cs.txt')),114 // pl: await createPromise(path.join(root, '8-mapstats', 'pl.txt')),115 // zhHans: await createPromise(path.join(root, '8-mapstats', 'zh-Hans.txt')),116 // zhHant: await createPromise(path.join(root, '8-mapstats', 'zh-Hant.txt')),117 // en: await createPromise(path.join(root, 'merge-mapstats', 'en.txt')),118 }119 const getTavernNameInLang = (120 tavernName: string,121 lang: keyof typeof twodEvents,122 ) => {123 const rc = getRC(twodEvents.en, tavernName)124 if (rc !== null) {125 const [row, column] = rc126 return twodEvents[lang][row][column]127 } else {128 return null129 }130 }131 const getLocationNameInLang = (...
retryablePromiseAny.ts
Source:retryablePromiseAny.ts
1import retryablePromiseAny from '../retryablePromiseAny';2import { DEFAULT_RETRY_OPTIONS } from '../retryablePromiseAny';3const delayedResolve = (status: number, message: string, delay = 1000): Promise<unknown> => {4 if (status < 300) {5 return new Promise((resolve): void => {6 setTimeout(() => {7 resolve({ status, message });8 }, delay);9 });10 }11 return new Promise((_, reject): void => {12 setTimeout(() => {13 reject({ status, message });14 }, delay);15 });16};17jest.disableAutomock();18describe('retryablePromiseAny', () => {19 afterEach(() => {20 jest.useRealTimers();21 });22 describe('createPromise', () => {23 it('uses default options', async () => {24 const createPromise = jest.fn(() => Promise.resolve());25 await retryablePromiseAny(createPromise);26 expect(createPromise).toHaveBeenCalledWith({ ...DEFAULT_RETRY_OPTIONS, currentRetry: 0 });27 });28 it('increments currentRetry', async () => {29 const createPromise = jest30 .fn()31 .mockReturnValueOnce(delayedResolve(200, 'success', 3500))32 .mockReturnValueOnce(delayedResolve(408, 'dead', 1000))33 .mockReturnValueOnce(delayedResolve(200, 'last', 1000));34 await retryablePromiseAny(createPromise);35 expect(createPromise.mock.calls[0][0].currentRetry).toBe(0);36 expect(createPromise.mock.calls[1][0].currentRetry).toBe(1);37 expect(createPromise.mock.calls[2][0].currentRetry).toBe(2);38 });39 });40 it('first request resolves in time', async () => {41 const createPromise = jest.fn().mockReturnValue(delayedResolve(200, 'first success', 100));42 const data = await retryablePromiseAny(createPromise, {43 timeout: 20044 });45 expect(createPromise).toHaveBeenCalledTimes(1);46 expect(data).toEqual({ status: 200, message: 'first success' });47 });48 it('first request errors and is not retryable', async () => {49 const createPromise = jest.fn().mockReturnValueOnce(delayedResolve(401, 'Unauthorized', 100));50 const data = await retryablePromiseAny(createPromise, {51 timeout: 50052 }).catch(e => e);53 expect(data).toEqual([{ message: 'Unauthorized', status: 401 }]);54 expect(createPromise).toHaveBeenCalledTimes(1);55 });56 it('all requests reject and status is always retryable', async () => {57 const createPromise = jest.fn().mockReturnValue(delayedResolve(408, 'dead', 150));58 const data = await retryablePromiseAny(createPromise, {59 timeout: 20060 }).catch(errors => errors);61 expect(data).toEqual([62 { status: 408, message: 'dead' },63 { status: 408, message: 'dead' },64 { status: 408, message: 'dead' },65 { status: 408, message: 'dead' }66 ]);67 });68 it('requests rejects and status is not retryable', async () => {69 const createPromise = jest.fn().mockReturnValue(delayedResolve(402, 'dead', 150));70 const errors = await retryablePromiseAny(createPromise, {71 timeout: 20072 }).catch(e => e);73 expect(createPromise).toHaveBeenCalledTimes(1);74 expect(errors).toEqual([{ status: 402, message: 'dead' }]);75 });76 it('first request is slow, but faster than retried one', async () => {77 const createPromise = jest78 .fn()79 .mockReturnValueOnce(delayedResolve(200, 'first resolve', 220))80 .mockReturnValueOnce(delayedResolve(200, 'second resolve', 320));81 const data = await retryablePromiseAny(createPromise, {82 maxRetryCount: 2,83 timeout: 20084 });85 expect(createPromise).toHaveBeenCalledTimes(2);86 expect(data).toEqual({ status: 200, message: 'first resolve' });87 });88 it('first request is slow, retried one is faster', async () => {89 const createPromise = jest90 .fn()91 .mockReturnValueOnce(delayedResolve(200, 'first resolve', 800))92 .mockReturnValueOnce(delayedResolve(200, 'second resolve', 100));93 const data = await retryablePromiseAny(createPromise, { timeout: 200 });94 expect(createPromise).toHaveBeenCalledTimes(2);95 expect(data).toEqual({ status: 200, message: 'second resolve' });96 });97 it('first request is slow, retried one times out', async () => {98 const createPromise = jest99 .fn()100 .mockReturnValueOnce(delayedResolve(200, 'first resolve', 250))101 .mockReturnValueOnce(delayedResolve(408, 'last reject', 50));102 retryablePromiseAny(createPromise, { timeout: 200, maxRetryCount: 2 }).then(data => {103 expect(createPromise).toHaveBeenCalledTimes(2);104 expect(data).toEqual({ status: 200, message: 'first resolve' });105 });106 jest.advanceTimersByTime(350);107 });108 it('retries if first one times out', () => {109 const createPromise = jest110 .fn()111 .mockReturnValueOnce(delayedResolve(408, 'first reject', 100))112 .mockReturnValueOnce(delayedResolve(200, 'second resolve', 10));113 retryablePromiseAny(createPromise, { timeout: 200 }).then(data => {114 expect(data).toEqual({ status: 200, message: 'second resolve' });115 expect(createPromise).toHaveBeenCalledTimes(2);116 });117 });...
main.js
Source:main.js
...6 );78function getBreedImages() {9 const promises = [10 createPromise(),11 createPromise(),12 createPromise(),13 createPromise(),14 createPromise(),15 createPromise(),16 createPromise(),17 createPromise(),18 createPromise(),19 createPromise(),20 createPromise(),21 createPromise(),22 createPromise(),23 createPromise(),24 createPromise(),25 createPromise(),26 createPromise(),27 createPromise(),28 createPromise(),29 createPromise(),30 createPromise(),31 createPromise(),32 createPromise(),33 createPromise(),34 createPromise(),35 createPromise(),36 createPromise(),37 createPromise(),38 createPromise(),39 createPromise(),40 createPromise(),41 createPromise(),42 createPromise(),43 createPromise(),44 createPromise(),45 ];46 Promise.all(promises).then((responses) => {47 for (let i = 0; i < responses.length; i++) {48 const img = document.querySelector(".dog" + (i + 1));49 img.src = responses[i].message;50 }51 });52}53const btn = document.querySelector(".js-btn");
...
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var promise = wptoolkit.createPromise();3promise.then(function (result) {4 console.log(result);5}, function (err) {6 console.log(err);7});8We welcome contributions from the community. Please read the [contributing guide](
Using AI Code Generation
1const wpt = require('wpt');2const wptPromise = wpt.createPromise();3wptPromise.getLocations()4.then((response) => {5console.log(response.statusCode);6console.log(response.data);7})8.catch((error) => {9console.log(error);10});11const wpt = require('wpt');12wpt.getLocations((error, response) => {13if (error) {14console.log(error);15} else {16console.log(response.statusCode);17console.log(response.data);18}19});20const wpt = require('wpt');21wpt.getLocations()22.then((response) => {23console.log(response.statusCode);24console.log(response.data);25})26.catch((error) => {27console.log(error);28});29const wpt = require('wpt');30const wptPromise = wpt.createPromise();31wptPromise.getLocations()32.then((response) => {33console.log(response.statusCode);34console.log(response.data);35})36.catch((error) => {37console.log(error);38});39const wpt = require('wpt');40wpt.getLocations((error, response) => {41if (error) {42console.log(error);43} else {44console.log(response.statusCode);45console.log(response.data);46}47});48const wpt = require('wpt');49wpt.getLocations()50.then((response) => {51console.log(response.statusCode);52console.log(response.data);53})54.catch((error) => {55console.log(error);56});57const wpt = require('wpt');58const wptPromise = wpt.createPromise();59wptPromise.getLocations()60.then((response) => {61console.log(response.statusCode);62console.log(response.data);63})64.catch((error) => {65console.log(error);66});67const wpt = require('wpt');68wpt.getLocations((error, response) => {69if (error) {70console.log(error);71} else {72console.log(response.statusCode);73console.log(response
Using AI Code Generation
1const wpt = require('wpt-api');2const wptApi = new wpt(process.env.WPT_API_KEY);3wptApi.createPromise('runTest', { url: url, location: 'Dulles:Chrome' })4 .then((result) => {5 console.log(result);6 })7 .catch((err) => {8 console.log(err);9 });10const wpt = require('wpt-api');11const wptApi = new wpt(process.env.WPT_API_KEY);12wptApi.createPromise('runTest', { url: url, location: 'Dulles:Chrome' })13 .then((result) => {14 console.log(result);15 })16 .catch((err) => {17 console.log(err);18 });19const wpt = require('wpt-api');20const wptApi = new wpt(process.env.WPT_API_KEY);21wptApi.createPromise('runTest', { url: url, location: 'Dulles:Chrome' })22 .then((result) => {23 console.log(result);24 })25 .catch((err) => {26 console.log(err);27 });28const wpt = require('wpt-api');29const wptApi = new wpt(process.env.WPT_API_KEY);30wptApi.createPromise('runTest', { url: url, location: 'Dulles:Chrome' })31 .then((result) => {32 console.log(result);33 })34 .catch((err) => {35 console.log(err);36 });37const wpt = require('wpt-api');38const wptApi = new wpt(process.env.WPT_API_KEY);39wptApi.createPromise('runTest', { url: url, location: 'Dulles:Chrome' })40 .then((result) => {
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!!