Best JavaScript code snippet using wpt
index.ts
Source:index.ts
1import { EnvironmentConfig, WakaConfig } from '../../types'2import logger from '../logger'3import VersionManager from '../versionManager'4import TfNSWUpdater from './au-syd'5import BasicUpdater from './basic'6import Fargate from './fargate'7import Kubernetes from './kubernetes'8import ATUpdater from './nz-akl'9interface UpdateManagerProps {10 config: WakaConfig11 versionManager: VersionManager12}13interface Importer {14 startTask: (env: EnvironmentConfig) => void15}16class UpdateManager {17 config: WakaConfig18 versionManager: VersionManager19 updaters: { [prefix: string]: {} }20 interval: NodeJS.Timeout21 oldInterval: NodeJS.Timeout22 importer: Importer23 constructor(props: UpdateManagerProps) {24 const { config, versionManager } = props25 this.config = config26 this.versionManager = versionManager27 const { importer } = config28 this.importer = null29 if (importer) {30 if (importer.provider === 'fargate') {31 this.importer = new Fargate(importer)32 } else if (importer.provider === 'kubernetes') {33 this.importer = new Kubernetes(importer)34 }35 }36 this.updaters = {}37 }38 start = () => {39 const { callback, config, versionManager } = this40 const { updaters } = config41 const regions = Object.keys(updaters).filter(k => updaters[k] !== false)42 if (regions.length === 0) {43 logger.info(44 'No updaters are turned on. Waka will not update automatically.'45 )46 }47 regions.forEach(prefix => {48 const updaterConfig = updaters[prefix]49 if (updaterConfig !== false) {50 const { url, delay, interval, type, extended } = updaterConfig51 logger.info({ prefix, type }, 'Starting Updater')52 let updater53 if (type === 'nz-akl') {54 const apiKey = config.api['nz-akl']55 const params = { prefix, apiKey, delay, interval, callback, extended }56 updater = new ATUpdater(params)57 } else if (type === 'au-syd') {58 const apiKey = config.api['au-syd']59 const params = {60 prefix,61 apiKey,62 delay,63 interval,64 callback,65 versionManager,66 extended,67 config,68 }69 updater = new TfNSWUpdater(params)70 } else {71 const params = { prefix, url, delay, interval, callback, extended }72 if (updaterConfig.apiKeyHeader) {73 params.apiKey = config.api[prefix]74 params.apiKeyHeader = updaterConfig.apiKeyHeader75 }76 updater = new BasicUpdater(params)77 }78 updater.start()79 this.updaters[prefix] = updater80 }81 })82 // check the versions for remappings, this code is a bit gross i think83 logger.info('Checking versions in 30 seconds...')84 setTimeout(this.checkVersions, 1 * 30 * 1000) // initially after 30 seconds85 this.interval = setInterval(this.checkVersions, 10 * 60 * 1000) // then every 10 mins86 logger.info('Checking old versions in 5 minutes')87 this.oldInterval = setInterval(this.checkOldVersions, 5 * 60 * 1000) // every 5 minutes, this is a less expensive operation88 }89 stop = () => {90 setInterval(this.checkVersions)91 }92 callback = async (93 prefix: string,94 version: string,95 adjustMapping: boolean96 ) => {97 const { config, versionManager } = this98 // don't understand this99 const { shapesContainer, shapesRegion, dbconfig } = config.updaters[prefix]100 // the id should be the same as the one generated from addVersion101 const { id, exists } = await versionManager.checkVersionExists(102 prefix,103 version104 )105 if (exists) {106 logger.info({ prefix, version }, 'Version already exists in database.')107 } else {108 // Add the version with the default config for the importer if it doesn't already exist.109 await versionManager.addVersion({110 prefix,111 version,112 shapesContainer,113 shapesRegion,114 dbconfig,115 newRealtime: true,116 })117 logger.info({ prefix, version, status: 'empty' }, 'Created empty worker.')118 }119 const { status } = await versionManager.getVersionConfig(id)120 if (status === 'empty') {121 const newStatus = adjustMapping122 ? 'pendingimport-willmap'123 : 'pendingimport'124 await versionManager.updateVersionStatus(id, newStatus)125 logger.info(126 { prefix, version, status: newStatus },127 'Set status of worker.'128 )129 }130 const newStatus = (await versionManager.getVersionConfig(id)).status131 if (132 newStatus === 'pendingimport' ||133 newStatus === 'pendingimport-willmap'134 ) {135 if (adjustMapping === true && newStatus === 'pendingimport') {136 await versionManager.updateVersionStatus(id, 'pendingimport-willmap')137 logger.info(138 { prefix, version, status: 'pendingimport-willmap' },139 'Adjusted status from pendingimport to pendingimport-willmap.'140 )141 }142 // checkVersions() running on the interval will pick this up143 // we can't run it because if callback is run twice, it'll start all the tasks twice probably144 } else if (145 (adjustMapping === true && newStatus === 'imported') ||146 newStatus === 'imported-willmap'147 ) {148 logger.info({ prefix, version }, 'Import is complete - updating mapping.')149 versionManager.updateMapping(prefix, id)150 versionManager.updateVersionStatus(id, 'imported')151 }152 }153 checkVersions = async () => {154 const { versionManager, importer } = this155 const allVersions = await versionManager.allVersions()156 Object.keys(allVersions).forEach(async id => {157 const version = allVersions[id]158 const { prefix, status } = version159 if (status === 'pendingimport' || status === 'pendingimport-willmap') {160 if (this.importer === null) {161 logger.info(162 { prefix, version: version.version },163 'No Importer Configured - Please open /private and do a manual import.'164 )165 } else {166 logger.info({ prefix, version: version.version }, 'Starting Import')167 const config = await versionManager.getVersionConfig(id)168 const env = versionManager.envMapper.toEnvironmental(169 config,170 'importer'171 )172 await importer.startTask(env)173 }174 } else if (version.status === 'imported-willmap') {175 logger.info(176 { prefix, version: version.version },177 'Import is complete - updating mapping.'178 )179 versionManager.updateMapping(prefix, id)180 versionManager.updateVersionStatus(id, 'imported')181 }182 })183 }184 checkOldVersions = async () => {185 const { versionManager, config } = this186 if (!config.deleteOldVersions) {187 logger.info('Old versions deletion disabled, set deleteOldVersions to true to enable')188 return189 }190 logger.info('Checking old versions...')191 const allMappings = await versionManager.allMappings()192 const allVersions = await versionManager.allVersions()193 Object.keys(allVersions).forEach(async id => {194 const version = allVersions[id]195 const activeVersionId = (allMappings[version.prefix] || {}).value196 if (activeVersionId == null) {197 logger.info({ prefix: version.prefix, version: id }, 'No active version for region, skipping checks for version.')198 return199 }200 const activeVersion = allVersions[activeVersionId]201 // makes sure the versions are imported, aren't active202 if (version.status === 'imported' && activeVersionId !== id) {203 const activeDate = new Date(new Date(activeVersion.createdAt).getTime() - 1000 * 60 * 60 * 24 * 7)204 const testDate = new Date(version.createdAt)205 // and they're older than a new version206 if (testDate < activeDate) {207 logger.info({ prefix: version.prefix, version: id, activeVersion: activeVersionId }, 'Version is at least 1 week older than active version, deleting')208 try {209 await this.versionManager.deleteWorker(id)210 } catch(err) {211 logger.error(err, 'Error deleting worker.')212 }213 }214 }215 })216 }217}...
preprocess.jsx
Source:preprocess.jsx
...17 });18 return result;19};20export const preprocessData = (data) => ({21 IncomeStatement: adjustMapping(data.Name, data.StatementsOfIncome),22 BalanceSheet: adjustMapping(data.Name, data.BalanceSheets),23 CashFlow: adjustMapping(data.Name, data.StatementsOfCashFlows),24 Name: data.Name,25 Analytics: data.Analytics,26 Sentiment: data.Sentiment,27 Filings: data.Filings,28 'Q&A': data['Q&A'],29});30const combine = (...datas) => {31 const combinedData = {};32 datas.forEach((data) => {33 Object.keys(data).forEach((key) => {34 if (!(key in combinedData)) combinedData[key] = [];35 combinedData[key] = combinedData[key].concat(data[key]);36 });37 });...
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var mapping = {3};4var newMapping = wptoolkit.adjustMapping(mapping, "test2", "test4");5console.log(newMapping);6var wptoolkit = require('wptoolkit');7var mapping = {8};9var newMapping = wptoolkit.adjustMapping(mapping, "test2", "test4");10console.log(newMapping);11var wptoolkit = require('wptoolkit');12var mapping = {13};14var newMapping = wptoolkit.adjustMapping(mapping, "test2", "test4");15console.log(newMapping);16var wptoolkit = require('wptoolkit');17var mapping = {18};19var newMapping = wptoolkit.adjustMapping(mapping, "test2", "test4");20console.log(newMapping);21var wptoolkit = require('wptoolkit');22var mapping = {23};
Using AI Code Generation
1var wptdriver = require('wptdriver');2var wpt = new wptdriver();3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wptdriver = require('wptdriver');10var wpt = new wptdriver();11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wptdriver = require('wptdriver');18var wpt = new wptdriver();19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wptdriver = require('wptdriver');26var wpt = new wptdriver();27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wptdriver = require('wptdriver');34var wpt = new wptdriver();35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5var testId = '170824_6Y_2c5f5c5a5a5e5b5f5e5e5c5f5f5f5f5f';6var referenceId = '170824_6Y_2c5f5c5a5a5e5b5f5e5e5c5f5f5f5f5f';7wpt.adjustMapping(testId, referenceId, function(err, data) {8 if (err) {9 console.log(err);10 } else {11 console.log(data);12 }13});14var wpt = require('webpagetest');15var wpt = new WebPageTest('www.webpagetest.org');16wpt.getLocations(function(err, data) {17 if (err) {18 console.log(err);19 } else {20 console.log(data);21 }22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25wpt.getLocations(function(err, data) {26 if (err) {27 console.log(err);28 } else {29 console.log(data);30 }31});32var wpt = require('webpagetest');33var wpt = new WebPageTest('www.webpagetest.org');34wpt.getTesters(function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});
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!!