How to use checkProperty method in Puppeteer

Best JavaScript code snippet using puppeteer

aux-checkElements.js

Source:aux-checkElements.js Github

copy

Full Screen

2/* eslint-disable no-unused-vars */3/* eslint-disable no-restricted-syntax */4const config = require('../configurations');5const { logger } = config;6function checkProperty(obj, prop, nameParam) {7 const name = (nameParam !== null && nameParam !== undefined) ? nameParam : prop;8 const hasOwnProperty = Object.prototype.hasOwnProperty.call(obj, prop);9 if (hasOwnProperty === true) {10 logger.validationWarning(`'${name}' YES`);11 } else {12 logger.validationWarning(`'${name}' NO`);13 }14 return hasOwnProperty;15}16function listProperties(pricing) {17 // logger.validationWarning("-- BEGIN VERBOSE LIST OF PROPERTIES --");18 // context: Context19 // infrastructure: Infrastructure20 // pricing?: Pricing21 // metrics: Metrics22 // plans?: Plans23 // quotas?: Quotas24 // rates?: Rates25 // guarantees?: Guarantees26 // configuration?: Configuration27 // availability?: string28 if (checkProperty(pricing, 'context', 'root/context')) {29 // id: string30 // sla: string31 // api: string32 // type: "plans" | "instance"33 // provider?: string34 // consumer?: string35 // validity?: Validity36 checkProperty(pricing.context, 'id', 'root/context/id');37 checkProperty(pricing.context, 'sla', 'root/context/sla');38 checkProperty(pricing.context, 'api', 'root/context/api');39 checkProperty(pricing.context, 'type', 'root/context/type');40 checkProperty(pricing.context, 'provider', 'root/context/provider');41 checkProperty(pricing.context, 'consumer', 'root/context/consumer');42 if (checkProperty(pricing.context, 'validity', 'root/context/validity')) {43 // effectiveDate: string44 // expirationDate ?: string45 checkProperty(pricing.context.validity, 'effectiveDate', 'root/context/validity/effectiveDate');46 checkProperty(pricing.context.validity, 'expirationDate', 'root/context/validity/expirationDate');47 }48 }49 if (checkProperty(pricing, 'infrastructure', 'root/infrastructure')) {50 // supervisor: string51 // monitor: string52 // [x: string]: string53 checkProperty(pricing.infrastructure, 'supervisor', 'root/infrastructure/supervisor');54 checkProperty(pricing.infrastructure, 'monitor', 'root/infrastructure/monitor');55 }56 if (checkProperty(pricing, 'pricing', 'root/pricing')) {57 // cost?: number | Cost | "custom"58 // currency?: string59 // billing?: "onepay" | "daily" | "weekly" | "monthly" | "quarterly" | "yearly"60 // period?: Period61 if (checkProperty(pricing.pricing, 'cost', 'root/pricing/cost')) {62 // operation?: OperationCost63 // overage?: OverageCost64 // logger.validationWarning("-- HAS ${pricing.pricing.cost} COST");65 if (checkProperty(pricing.pricing.cost, 'operation', 'root/pricing/cost/operation')) {66 // volume: number67 // cost: number68 checkProperty(pricing.pricing.cost.operation, 'volume', 'root/pricing/cost/operation/volume');69 checkProperty(pricing.pricing.cost.operation, 'cost', 'root/pricing/cost/operation/cost');70 }71 if (checkProperty(pricing.pricing.cost, 'overage', 'root/pricing/cost/overage')) {72 // excess: number73 // cost: number74 checkProperty(pricing.pricing.cost.overage, 'excess', 'root/pricing/cost/overage/excess');75 checkProperty(pricing.pricing.cost.overage, 'cost', 'root/pricing/cost/overage/cost');76 }77 }78 checkProperty(pricing.pricing, 'currency', 'root/pricing/currency');79 checkProperty(pricing.pricing, 'billing', 'root/pricing/billing');80 if (checkProperty(pricing.pricing, 'period', 'root/pricing/period')) {81 // amount: number82 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"83 checkProperty(pricing.pricing.period, 'amount', 'root/pricing/period/amount');84 checkProperty(pricing.pricing.period, 'unit', 'root/pricing/period/unit');85 }86 }87 if (checkProperty(pricing, 'metrics', 'root/metrics')) {88 // logger.validationWarning("-- HAS ${Object.keys(pricing.metrics).length} METRICS");89 for (const [metricName, metric] of Object.entries(pricing.metrics)) {90 // type?: "integer" | "number" | "string" | "boolean"91 // format?: "int32" | "int64" | "float" | "double" | "string" | "byte" | "binary" | "date" | "date-time"92 // description?: string93 // unit?: string94 // resolution?: "check" | "consumption"95 // relatedMetrics?: Metric[]96 // logger.validationWarning("-- BEGIN metric");97 checkProperty(pricing.metrics[metricName], 'type', 'root/metrics/metric/type');98 checkProperty(pricing.metrics[metricName], 'format', 'root/metrics/metric/format');99 checkProperty(pricing.metrics[metricName], 'description', 'root/metrics/metric/description');100 checkProperty(pricing.metrics[metricName], 'unit', 'root/metrics/metric/unit');101 checkProperty(pricing.metrics[metricName], 'resolution', 'root/metrics/metric/resolution');102 checkProperty(pricing.metrics[metricName], 'relatedMetrics', 'root/metrics/metric/relatedMetrics');103 // logger.validationWarning("-- END metric");104 }105 }106 if (checkProperty(pricing, 'plans', 'root/plans')) {107 // [planName: string]: Plan108 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans).length} PLANS");109 for (const [planName, plan] of Object.entries(pricing.plans)) {110 // configuration?: Configuration111 // availability?: string112 // pricing?: Pricing113 // quotas?: Quotas114 // rates?: Rates115 // guarantees?: Guarantees116 // logger.validationWarning("-- BEGIN plan");117 if (checkProperty(pricing.plans[planName], 'configuration', 'root/plans/plan/configuration')) {118 // [name: string]: string119 // logger.validationWarning("-- HAS ${Object.keys(pricing.configuration).length} CONFIGURATIONS");120 }121 checkProperty(pricing.plans[planName], 'availability', 'root/plans/plan/availability');122 if (checkProperty(pricing.plans[planName], 'pricing', 'root/plans/plan/pricing')) {123 // cost?: number | Cost | "custom"124 // currency?: string125 // billing?: "onepay" | "daily" | "weekly" | "monthly" | "quarterly" | "yearly"126 // period?: Period127 if (checkProperty(pricing.plans[planName].pricing, 'cost', 'root/plans/plan/pricing/cost')) {128 // operation?: OperationCost129 // overage?: OverageCost130 // logger.validationWarning("-- HAS ${pricing.plans[planName].pricing} COST");131 if (checkProperty(pricing.plans[planName].pricing, 'operation', 'root/plans/plan/pricing/cost/operation')) {132 // volume: number133 // cost: number134 checkProperty(pricing.plans[planName].pricing.operation, 'volume', 'root/plans/plan/pricing/cost/operation/volume');135 checkProperty(pricing.plans[planName].pricing.operation, 'cost', 'root/plans/plan/pricing/cost/operation/cost');136 }137 if (checkProperty(pricing.plans[planName].pricing, 'overage', 'root/plans/plan/pricing/cost/overage')) {138 // excess: number139 // cost: number140 checkProperty(pricing.plans[planName].pricing.overage, 'excess', 'root/plans/plan/pricing/cost/overage/excess');141 checkProperty(pricing.plans[planName].pricing.overage, 'cost', 'root/plans/plan/pricing/cost/overage/cost');142 }143 }144 checkProperty(pricing.plans[planName].pricing, 'currency', 'root/plans/plan/pricing/currency');145 checkProperty(pricing.plans[planName].pricing, 'billing', 'root/plans/plan/pricing/billing');146 if (checkProperty(pricing.plans[planName].pricing, 'period', 'root/plans/plan/pricing/period')) {147 // amount: number148 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"149 checkProperty(pricing.plans[planName].pricing.period, 'amount', 'root/plans/plan/pricing/period/amount');150 checkProperty(pricing.plans[planName].pricing.period, 'unit', 'root/plans/plan/pricing/period/unit');151 }152 }153 if (checkProperty(pricing.plans[planName], 'quotas', 'root/plans/plan/quotas')) {154 // [pathName: string]: Path155 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans[planName].quotas).length} QUOTA PATHS");156 for (const [pathName, path] of Object.entries(pricing.plans[planName].quotas)) {157 // logger.validationWarning("-- BEGIN path");158 // [methodName: string]: Operation159 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans[planName].quotas[pathName]).length} QUOTA METHODS");160 for (const [methodName, method] of Object.entries(pricing.plans[planName].quotas[pathName])) {161 // logger.validationWarning("-- BEGIN method");162 // [metricName: string]: Limit[]163 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans[planName].quotas[pathName][methodName]).length} QUOTA METRICS");164 for (const [metricName, limits] of Object.entries(pricing.plans[planName].quotas[pathName][methodName])) {165 // logger.validationWarning("-- BEGIN metric");166 // [metricName: string]: Limit[]167 // logger.validationWarning("-- HAS ${pricing.plans[planName].quotas[pathName][methodName][metricName].length} QUOTA LIMITS");168 for (const i in pricing.plans[planName].quotas[pathName][methodName][metricName]) {169 // logger.validationWarning("-- BEGIN 0");170 // max: number | "unlimited"171 // period?: Period172 // scope?: string173 // cost?: number | Cost174 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i], 'max', 'root/plans/plan/quotas/path/method/metric/0/max');175 if (checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i], 'period', 'root/plans/plan/quotas/path/method/metric/0/period')) {176 // amount: number177 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"178 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].period, 'amount', 'root/plans/plan/quotas/path/method/metric/0/period/amount');179 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].period, 'unit', 'root/plans/plan/quotas/path/method/metric/0/period/unit');180 }181 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i], 'scope', 'root/plans/plan/quotas/path/method/metric/0/scope');182 if (checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i], 'cost', 'root/plans/plan/quotas/path/method/metric/0/cost')) {183 // operation ?: OperationCost184 // overage?: OverageCost185 // logger.validationWarning("-- HAS ${pricing.plans[planName].quotas[pathName][methodName][metricName][i].cost} COST");186 if (checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].cost, 'operation', 'root/plans/plan/quotas/path/method/metric/0/cost/operation')) {187 // volume: number188 // cost: number189 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].cost.operation, 'volume', 'root/plans/plan/quotas/path/method/metric/0/cost/operation/volume');190 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].cost.operation, 'cost', 'root/plans/plan/quotas/path/method/metric/0/cost/operation/cost');191 }192 if (checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].cost, 'overage', 'root/plans/plan/quotas/path/method/metric/0/cost/overage')) {193 // excess: number194 // cost: number195 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].cost.overage, 'excess', 'root/plans/plan/quotas/path/method/metric/0/cost/overage/excess');196 checkProperty(pricing.plans[planName].quotas[pathName][methodName][metricName][i].cost.overage, 'cost', 'root/plans/plan/quotas/path/method/metric/0/cost/overage/cost');197 }198 }199 // logger.validationWarning("-- END 0");200 }201 // logger.validationWarning("-- END metric");202 }203 // logger.validationWarning("-- END method");204 }205 // logger.validationWarning("-- END path");206 }207 }208 if (checkProperty(pricing.plans[planName], 'rates', 'root/plans/plan/rates')) {209 // [pathName: string]: Path210 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans[planName].rates).length} RATE PATHS");211 for (const [pathName, path] of Object.entries(pricing.plans[planName].rates)) {212 // logger.validationWarning("-- BEGIN path");213 // [methodName: string]: Operation214 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans[planName].rates[pathName]).length} RATE METHODS");215 for (const [methodName, method] of Object.entries(pricing.plans[planName].rates[pathName])) {216 // logger.validationWarning("-- BEGIN method");217 // [metricName: string]: Limit[]218 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans[planName].rates[pathName][methodName]).length} RATE METRICS");219 for (const [metricName, limits] of Object.entries(pricing.plans[planName].rates[pathName][methodName])) {220 // logger.validationWarning("-- BEGIN metric");221 // [metricName: string]: Limit[]222 // logger.validationWarning("-- HAS ${pricing.plans[planName].rates[pathName][methodName][metricName].length} RATE LIMITS");223 for (const i in pricing.plans[planName].rates[pathName][methodName][metricName]) {224 // logger.validationWarning("-- BEGIN 0");225 // max: number | "unlimited"226 // period?: Period227 // scope?: string228 // cost?: number | Cost229 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i], 'max', 'root/plans/plan/rates/path/method/metric/0/max');230 if (checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i], 'period', 'root/plans/plan/rates/path/method/metric/0/period')) {231 // amount: number232 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"233 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].period, 'amount', 'root/plans/plan/rates/path/method/metric/0/period/amount');234 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].period, 'unit', 'root/plans/plan/rates/path/method/metric/0/period/unit');235 }236 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i], 'scope', 'root/plans/plan/rates/path/method/metric/0/scope');237 if (checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i], 'cost', 'root/plans/plan/rates/path/method/metric/0/cost')) {238 // operation ?: OperationCost239 // overage?: OverageCost240 // logger.validationWarning("-- HAS ${pricing.plans[planName].rates[pathName][methodName][metricName][i].cost} COST");241 if (checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].cost, 'operation', 'root/plans/plan/rates/path/method/metric/0/cost/operation')) {242 // volume: number243 // cost: number244 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].cost.operation, 'volume', 'root/plans/plan/rates/path/method/metric/0/cost/operation/volume');245 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].cost.operation, 'cost', 'root/plans/plan/rates/path/method/metric/0/cost/operation/cost');246 }247 if (checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].cost, 'overage', 'root/plans/plan/rates/path/method/metric/0/cost/overage')) {248 // excess: number249 // cost: number250 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].cost.overage, 'excess', 'root/plans/plan/rates/path/method/metric/0/cost/overage/excess');251 checkProperty(pricing.plans[planName].rates[pathName][methodName][metricName][i].cost.overage, 'cost', 'root/plans/plan/rates/path/method/metric/0/cost/overage/cost');252 }253 }254 // logger.validationWarning("-- END 0");255 }256 // logger.validationWarning("-- END metric");257 }258 // logger.validationWarning("-- END method");259 }260 // logger.validationWarning("-- END path");261 }262 }263 if (checkProperty(pricing.plans[planName], 'guarantees', 'root/plans/plan/guarantees')) {264 // [pathName: string]: Guarantee265 // logger.validationWarning("-- HAS ${Object.keys(pricing.plans[planName].guarantees).length} GUARANTEES");266 for (const [guaranteeName, guarantee] of Object.entries(pricing.plans[planName].guarantees)) {267 // [methodName: string]: GuaranteeObjective[]268 // logger.validationWarning("-- BEGIN guarantee");269 for (const i in pricing.plans[planName].guarantees[guaranteeName]) {270 // objective: string271 // period ?: Period272 // window ?: "dynamic" | "static"273 // scope ?: string274 // logger.validationWarning("-- BEGIN 0");275 checkProperty(pricing.plans[planName].guarantees[guaranteeName], 'objective', 'root/plans/plan/guarantees/guarantee/0/objective');276 if (checkProperty(pricing.plans[planName].guarantees[guaranteeName], 'period', 'root/plans/plan/guarantees/guarantee/0/period')) {277 // amount: number278 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"279 checkProperty(pricing.plans[planName].guarantees[guaranteeName].period, 'amount', 'root/plans/plan/guarantees/guarantee/0/period/amount');280 checkProperty(pricing.plans[planName].guarantees[guaranteeName].period, 'unit', 'root/plans/plan/guarantees/guarantee/0/period/unit');281 }282 checkProperty(pricing.plans[planName].guarantees[guaranteeName], 'window', 'root/plans/plan/guarantees/guarantee/0/window');283 checkProperty(pricing.plans[planName].guarantees[guaranteeName], 'scope', 'root/plans/plan/guarantees/guarantee/0/scope');284 // logger.validationWarning("-- END 0");285 }286 // logger.validationWarning("-- END guarantee");287 }288 }289 // logger.validationWarning("-- END plan");290 }291 if (checkProperty(pricing, 'quotas', 'root/quotas')) {292 // [pathName: string]: Path293 // logger.validationWarning("-- HAS ${Object.keys(pricing.quotas).length} QUOTA PATHS");294 for (const [pathName, path] of Object.entries(pricing.quotas)) {295 // logger.validationWarning("-- BEGIN path");296 // [methodName: string]: Operation297 // logger.validationWarning("-- HAS ${Object.keys(pricing.quotas[pathName]).length} QUOTA METHODS");298 for (const [methodName, method] of Object.entries(pricing.quotas[pathName])) {299 // logger.validationWarning("-- BEGIN method");300 // [metricName: string]: Limit[]301 // logger.validationWarning("-- HAS ${Object.keys(pricing.quotas[pathName][methodName]).length} QUOTA METRICS");302 for (const [metricName, limits] of Object.entries(pricing.quotas[pathName][methodName])) {303 // logger.validationWarning("-- BEGIN metric");304 // [metricName: string]: Limit[]305 // logger.validationWarning("-- HAS ${pricing.quotas[pathName][methodName][metricName].length} QUOTA LIMITS");306 for (const i in pricing.quotas[pathName][methodName][metricName]) {307 // logger.validationWarning("-- BEGIN 0");308 // max: number | "unlimited"309 // period?: Period310 // scope?: string311 // cost?: number | Cost312 checkProperty(pricing.quotas[pathName][methodName][metricName][i], 'max', 'root/quotas/path/method/metric/0/max');313 if (checkProperty(pricing.quotas[pathName][methodName][metricName][i], 'period', 'root/quotas/path/method/metric/0/period')) {314 // amount: number315 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"316 checkProperty(pricing.quotas[pathName][methodName][metricName][i].period, 'amount', 'root/quotas/path/method/metric/0/period/amount');317 checkProperty(pricing.quotas[pathName][methodName][metricName][i].period, 'unit', 'root/quotas/path/method/metric/0/period/unit');318 }319 checkProperty(pricing.quotas[pathName][methodName][metricName][i], 'scope', 'root/quotas/path/method/metric/0/scope');320 if (checkProperty(pricing.quotas[pathName][methodName][metricName][i], 'cost', 'root/quotas/path/method/metric/0/cost')) {321 // operation ?: OperationCost322 // overage?: OverageCost323 // logger.validationWarning("-- HAS ${pricing.quotas[pathName][methodName][metricName][i].cost} COST");324 if (checkProperty(pricing.quotas[pathName][methodName][metricName][i].cost, 'operation', 'root/quotas/path/method/metric/0/cost/operation')) {325 // volume: number326 // cost: number327 checkProperty(pricing.quotas[pathName][methodName][metricName][i].cost.operation, 'volume', 'root/quotas/path/method/metric/0/cost/operation/volume');328 checkProperty(pricing.quotas[pathName][methodName][metricName][i].cost.operation, 'cost', 'root/quotas/path/method/metric/0/cost/operation/cost');329 }330 if (checkProperty(pricing.quotas[pathName][methodName][metricName][i].cost, 'overage', 'root/quotas/path/method/metric/0/cost/overage')) {331 // excess: number332 // cost: number333 checkProperty(pricing.quotas[pathName][methodName][metricName][i].cost.overage, 'excess', 'root/quotas/path/method/metric/0/cost/overage/excess');334 checkProperty(pricing.quotas[pathName][methodName][metricName][i].cost.overage, 'cost', 'root/quotas/path/method/metric/0/cost/overage/cost');335 }336 }337 // logger.validationWarning("-- END 0");338 }339 // logger.validationWarning("-- END metric");340 }341 // logger.validationWarning("-- END method");342 }343 // logger.validationWarning("-- END path");344 }345 }346 }347 if (checkProperty(pricing, 'rates', 'root/rates')) {348 // [pathName: string]: Path349 // logger.validationWarning("-- HAS ${Object.keys(pricing.rates).length} RATE PATHS");350 for (const [pathName, path] of Object.entries(pricing.rates)) {351 // logger.validationWarning("-- BEGIN path");352 // [methodName: string]: Operation353 // logger.validationWarning("-- HAS ${Object.keys(pricing.rates[pathName]).length} RATE METHODS");354 for (const [methodName, method] of Object.entries(pricing.rates[pathName])) {355 // logger.validationWarning("-- BEGIN method");356 // [metricName: string]: Limit[]357 // logger.validationWarning("-- HAS ${Object.keys(pricing.rates[pathName][methodName]).length} RATE METRICS");358 for (const [metricName, limits] of Object.entries(pricing.rates[pathName][methodName])) {359 // logger.validationWarning("-- BEGIN metric");360 // [metricName: string]: Limit[]361 // logger.validationWarning("-- HAS ${pricing.rates[pathName][methodName][metricName].length} RATE LIMITS");362 for (const i in pricing.rates[pathName][methodName][metricName]) {363 // logger.validationWarning("-- BEGIN 0");364 // max: number | "unlimited"365 // period?: Period366 // scope?: string367 // cost?: number | Cost368 checkProperty(pricing.rates[pathName][methodName][metricName][i], 'max', 'root/rates/path/method/metric/0/max');369 if (checkProperty(pricing.rates[pathName][methodName][metricName][i], 'period', 'root/rates/path/method/metric/0/period')) {370 // amount: number371 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"372 checkProperty(pricing.rates[pathName][methodName][metricName][i].period, 'amount', 'root/rates/path/method/metric/0/period/amount');373 checkProperty(pricing.rates[pathName][methodName][metricName][i].period, 'unit', 'root/rates/path/method/metric/0/period/unit');374 }375 checkProperty(pricing.rates[pathName][methodName][metricName][i], 'scope', 'root/rates/path/method/metric/0/scope');376 if (checkProperty(pricing.rates[pathName][methodName][metricName][i], 'cost', 'root/rates/path/method/metric/0/cost')) {377 // operation ?: OperationCost378 // overage?: OverageCost379 // logger.validationWarning("-- HAS ${pricing.rates[pathName][methodName][metricName][i].cost} COST");380 if (checkProperty(pricing.rates[pathName][methodName][metricName][i].cost, 'operation', 'root/rates/path/method/metric/0/cost/operation')) {381 // volume: number382 // cost: number383 checkProperty(pricing.rates[pathName][methodName][metricName][i].cost.operation, 'volume', 'root/rates/path/method/metric/0/cost/operation/volume');384 checkProperty(pricing.rates[pathName][methodName][metricName][i].cost.operation, 'cost', 'root/rates/path/method/metric/0/cost/operation/cost');385 }386 if (checkProperty(pricing.rates[pathName][methodName][metricName][i].cost, 'overage', 'root/rates/path/method/metric/0/cost/overage')) {387 // excess: number388 // cost: number389 checkProperty(pricing.rates[pathName][methodName][metricName][i].cost.overage, 'excess', 'root/rates/path/method/metric/0/cost/overage/excess');390 checkProperty(pricing.rates[pathName][methodName][metricName][i].cost.overage, 'cost', 'root/rates/path/method/metric/0/cost/overage/cost');391 }392 }393 // logger.validationWarning("-- END 0");394 }395 // logger.validationWarning("-- END metric");396 }397 // logger.validationWarning("-- END method");398 }399 // logger.validationWarning("-- END path");400 }401 }402 if (checkProperty(pricing, 'guarantees', 'root/guarantees')) {403 // [pathName: string]: Guarantee404 // logger.validationWarning("-- HAS ${Object.keys(pricing.guarantees).length} GUARANTEES");405 for (const [guaranteeName, guarantee] of Object.entries(pricing.guarantees)) {406 // [methodName: string]: GuaranteeObjective[]407 // logger.validationWarning("-- BEGIN guarantee");408 for (const i in pricing.guarantees[guaranteeName]) {409 // objective: string410 // period ?: Period411 // window ?: "dynamic" | "static"412 // scope ?: string413 // logger.validationWarning("-- BEGIN 0");414 checkProperty(pricing.guarantees[guaranteeName], 'objective', 'root/guarantees/guarantee/0/objective');415 if (checkProperty(pricing.guarantees[guaranteeName], 'period', 'root/guarantees/guarantee/0/period')) {416 // amount: number417 // unit: "millisecond" | "second" | "minute" | "hour" | "day" | "week" | "month" | "year" | "decade" | "century" | "forever"418 checkProperty(pricing.guarantees[guaranteeName].period, 'amount', 'root/guarantees/guarantee/0/period/amount');419 checkProperty(pricing.guarantees[guaranteeName].period, 'unit', 'root/guarantees/guarantee/0/period/unit');420 }421 checkProperty(pricing.guarantees[guaranteeName], 'window', 'root/guarantees/guarantee/0/window');422 checkProperty(pricing.guarantees[guaranteeName], 'scope', 'root/guarantees/guarantee/0/scope');423 // logger.validationWarning("-- END 0");424 }425 // logger.validationWarning("-- END guarantee");426 }427 }428 if (checkProperty(pricing, 'configuration', 'root/configuration')) {429 // [name: string]: string430 // logger.validationWarning("-- HAS ${Object.keys(pricing.configuration).length} CONFIGURATIONS");431 }432 checkProperty(pricing, 'availability', 'root/availability');433 // logger.validationWarning("-- END VERBOSE LIST OF PROPERTIES --");434}435module.exports = {436 listProperties,...

Full Screen

Full Screen

logic.js

Source:logic.js Github

copy

Full Screen

...3const checkProperty = (errors, keyword, property) => {4 if (errors === null) return false5 for (const error of errors) {6 if (error.keyword === 'errorMessage') {7 const nested = checkProperty(error.params.errors, keyword, property)8 if (nested) return nested9 }10 if (error.keyword !== keyword) continue11 if (12 ['required', 'dependencies'].includes(keyword) &&13 error.params.missingProperty === property14 ) {15 return true16 } else if (17 keyword === 'additionalProperties' &&18 error.params.additionalProperty === property19 ) {20 return true21 } else if (22 keyword === 'oneOf' &&23 error.params.passingSchemas.includes(property)24 ) {25 return true26 } else if (keyword === 'anyOf') return true27 else if (keyword === 'not' && error.instancePath.includes(property)) {28 return true29 } else if (keyword === 'enum' && error.instancePath.includes(property)) {30 return true31 } else if (keyword === 'minimum' && error.instancePath.includes(property)) {32 return true33 } else if (34 keyword === 'exclusiveMinimum' &&35 error.instancePath.includes(property)36 ) {37 return true38 } else if (keyword === 'maximum' && error.instancePath.includes(property)) {39 return true40 } else if (41 keyword === 'exclusiveMaximum' &&42 error.instancePath.includes(property)43 ) {44 return true45 } else if (46 keyword === 'false schema' &&47 error.instancePath.includes(property)48 ) {49 return true50 } else if (keyword === 'pattern') return true51 }52 return false53}54// allOf/155test('Should accept CharacteristicName AND NOT MethodSpeciation', async (t) => {56 const valid = validate({57 CharacteristicName: 'Calcium'58 })59 t.false(valid)60 t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)61 t.is(checkProperty(validate.errors, 'required', 'MethodSpeciation'), false)62})63test('Should reject CharacteristicName AND NOT MethodSpeciation', async (t) => {64 const valid = validate({65 CharacteristicName: 'Nitrate'66 })67 t.false(valid)68 t.is(checkProperty(validate.errors, 'required', 'MethodSpeciation'), true)69})70test('Should accept CharacteristicName AND MethodSpeciation', async (t) => {71 const valid = validate({72 CharacteristicName: 'Nitrate',73 MethodSpeciation: 'as N'74 })75 t.false(valid)76 t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)77 t.is(checkProperty(validate.errors, 'required', 'MethodSpeciation'), false)78})79// CharacteristicName-ResultSampleFraction80test('Should accept CharacteristicName AND NOT ResultSampleFraction', async (t) => {81 const valid = validate({82 CharacteristicName: 'Dissolved oxygen (DO)'83 })84 t.false(valid)85 t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)86 t.is(87 checkProperty(validate.errors, 'required', 'ResultSampleFraction'),88 false89 )90})91test('Should rejects CharacteristicName AND NOT ResultSampleFraction', async (t) => {92 const valid = validate({93 CharacteristicName: 'Silver'94 })95 t.false(valid)96 t.is(97 checkProperty(validate.errors, 'required', 'ResultSampleFraction'),98 true99 )100})101test('Should accept CharacteristicName AND ResultSampleFraction', async (t) => {102 const valid = validate({103 CharacteristicName: 'Silver',104 ResultSampleFraction: 'Dissolved'105 })106 t.false(valid)107 t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)108 t.is(109 checkProperty(validate.errors, 'required', 'ResultSampleFraction'),110 false111 )112})113// CharacteristicName-Nutrient-ResultSampleFraction114test('Should reject Nutrient CharacteristicName AND ResultSampleFraction', async (t) => {115 const valid = validate({116 ActivityMediaName: 'Surface Water',117 CharacteristicName: 'Ammonia',118 ActivityType: '',119 ResultSampleFraction: 'Total'120 })121 t.false(valid)122 t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)123 t.is(124 checkProperty(validate.errors, 'required', 'ResultSampleFraction'),125 false126 )127 t.is(checkProperty(validate.errors, 'enum', 'ResultSampleFraction'), true)128})129test('Should accept Nutrient CharacteristicName AND filter ResultSampleFraction', async (t) => {130 const valid = validate({131 ActivityMediaName: 'Surface Water',132 CharacteristicName: 'Ammonia',133 ActivityType: '',134 ResultSampleFraction: 'Filtered'135 })136 t.false(valid)137 t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)138 t.is(139 checkProperty(validate.errors, 'required', 'ResultSampleFraction'),140 false141 )142 t.is(checkProperty(validate.errors, 'enum', 'ResultSampleFraction'), false)143})144test('Should accept Nutrient Sediment', async (t) => {145 const valid = validate({146 ActivityMediaName: 'Surface Water Sediment',147 CharacteristicName: 'Ammonia',148 ActivityType: '',149 ResultSampleFraction: 'Total'150 })151 t.false(valid)152 t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)153 t.is(154 checkProperty(validate.errors, 'required', 'ResultSampleFraction'),155 false156 )157 t.is(checkProperty(validate.errors, 'enum', 'ResultSampleFraction'), false)158})159// test('Should accept Nutrient Sediment with no sample fraction', async (t) => {160// let valid = validate({161// 'ActivityMediaName':'Surface Water Sediment',162// 'CharacteristicName': 'Total Nitrogen, mixed forms',163// 'ActivityType': '',164// 'ResultSampleFraction': ''165// })166// console.log(validate.errors)167// t.is(checkProperty(validate.errors, 'required', 'CharacteristicName'), false)168// t.is(checkProperty(validate.errors, 'required', 'ResultSampleFraction'), false)169// t.is(checkProperty(validate.errors, 'enum', 'ResultSampleFraction'), false)170//171// })172// allOf/3173test('Should reject NOT ResultValue AND NOT ResultDetectionCondition', async (t) => {174 const valid = validate({})175 t.false(valid)176 t.is(checkProperty(validate.errors, 'required', 'ResultValue'), true)177 t.is(178 checkProperty(validate.errors, 'required', 'ResultDetectionCondition'),179 true180 )181})182test('Should reject ResultValue AND ResultDetectionCondition', async (t) => {183 const valid = validate({184 ResultValue: 1,185 ResultDetectionCondition: 'Not Reported'186 })187 t.false(valid)188 t.is(checkProperty(validate.errors, 'false schema', 'ResultValue'), true)189 t.is(190 checkProperty(validate.errors, 'false schema', 'ResultDetectionCondition'),191 true192 )193})194test('Should accept ResultValue OR ResultDetectionCondition', async (t) => {195 let valid = validate({196 ResultValue: 1197 })198 t.false(valid)199 t.is(checkProperty(validate.errors, 'required', 'ResultValue'), false)200 t.is(201 checkProperty(validate.errors, 'required', 'ResultDetectionCondition'),202 false203 )204 t.is(checkProperty(validate.errors, 'enum', 'ResultValue'), false)205 t.is(206 checkProperty(validate.errors, 'enum', 'ResultDetectionCondition'),207 false208 )209 valid = validate({210 ResultDetectionCondition: 'Not Reported'211 })212 t.false(valid)213 t.is(checkProperty(validate.errors, 'required', 'ResultValue'), false)214 t.is(215 checkProperty(validate.errors, 'required', 'ResultDetectionCondition'),216 false217 )218 t.is(checkProperty(validate.errors, 'enum', 'ResultValue'), false)219 t.is(220 checkProperty(validate.errors, 'enum', 'ResultDetectionCondition'),221 false222 )223})224// allOf/4225test('Should reject ResultDetectionCondition = Present Above Quantification Limit', async (t) => {226 const valid = validate({227 ResultDetectionCondition: 'Present Above Quantification Limit'228 })229 t.false(valid)230 t.is(231 checkProperty(232 validate.errors,233 'dependencies',234 'ResultDetectionQuantitationLimitType'235 ),236 true237 )238 t.is(239 checkProperty(240 validate.errors,241 'dependencies',242 'ResultDetectionQuantitationLimitMeasure'243 ),244 true245 )246 t.is(247 checkProperty(248 validate.errors,249 'dependencies',250 'ResultDetectionQuantitationLimitUnit'251 ),252 true253 )254})255test('Should reject ResultDetectionCondition = Present Below Quantification Limit', async (t) => {256 const valid = validate({257 ResultValue: 1,258 ResultDetectionCondition: 'Present Below Quantification Limit'259 })260 t.false(valid)261 t.is(262 checkProperty(263 validate.errors,264 'dependencies',265 'ResultDetectionQuantitationLimitType'266 ),267 true268 )269 t.is(270 checkProperty(271 validate.errors,272 'dependencies',273 'ResultDetectionQuantitationLimitMeasure'274 ),275 true276 )277 t.is(278 checkProperty(279 validate.errors,280 'dependencies',281 'ResultDetectionQuantitationLimitUnit'282 ),283 true284 )285})286test('Should accept ResultDetectionCondition', async (t) => {287 const valid = validate({288 ResultValue: 1,289 ResultDetectionCondition: 'Present Below Quantification Limit',290 ResultDetectionQuantitationLimitType: 'A',291 ResultDetectionQuantitationLimitMeasure: 1,292 ResultDetectionQuantitationLimitUnit: 'mg/L'293 })294 t.false(valid)295 t.is(296 checkProperty(297 validate.errors,298 'dependencies',299 'ResultDetectionQuantitationLimitType'300 ),301 false302 )303 t.is(304 checkProperty(305 validate.errors,306 'dependencies',307 'ResultDetectionQuantitationLimitMeasure'308 ),309 false310 )311 t.is(312 checkProperty(313 validate.errors,314 'dependencies',315 'ResultDetectionQuantitationLimitUnit'316 ),317 false318 )319})320// allOf/4321test('Should reject ResultDetectionCondition = Not Detected', async (t) => {322 const valid = validate({323 ResultDetectionCondition: 'Not Detected',324 ResultDetectionQuantitationLimitType: 'Sample Detection Limit',325 ResultDetectionQuantitationLimitMeasure: 0,326 ResultDetectionQuantitationLimitUnit: 'None'327 })328 t.false(valid)329 t.is(330 checkProperty(331 validate.errors,332 'false schema',333 'ResultDetectionQuantitationLimitType'334 ),335 true336 )337 t.is(338 checkProperty(339 validate.errors,340 'false schema',341 'ResultDetectionQuantitationLimitMeasure'342 ),343 true344 )345 t.is(346 checkProperty(347 validate.errors,348 'false schema',349 'ResultDetectionQuantitationLimitUnit'350 ),351 true352 )353})354test('Should accept ResultDetectionCondition = Not Detected', async (t) => {355 const valid = validate({356 ResultDetectionCondition: 'Not Detected'357 })358 t.false(valid)359 t.is(360 checkProperty(361 validate.errors,362 'enum',363 'ResultDetectionQuantitationLimitType'364 ),365 false366 )367 t.is(368 checkProperty(369 validate.errors,370 'enum',371 'ResultDetectionQuantitationLimitMeasure'372 ),373 false374 )375 t.is(376 checkProperty(377 validate.errors,378 'enum',379 'ResultDetectionQuantitationLimitUnit'380 ),381 false382 )383})384test('Should reject ResultDetectionCondition = Detected Not Quantified', async (t) => {385 const valid = validate({386 ResultDetectionCondition: 'Detected Not Quantified',387 ResultDetectionQuantitationLimitType: 'Sample Detection Limit',388 ResultDetectionQuantitationLimitMeasure: 0,389 ResultDetectionQuantitationLimitUnit: 'None'390 })391 t.false(valid)392 t.is(393 checkProperty(394 validate.errors,395 'false schema',396 'ResultDetectionQuantitationLimitType'397 ),398 true399 )400 t.is(401 checkProperty(402 validate.errors,403 'false schema',404 'ResultDetectionQuantitationLimitMeasure'405 ),406 true407 )408 t.is(409 checkProperty(410 validate.errors,411 'false schema',412 'ResultDetectionQuantitationLimitUnit'413 ),414 true415 )416})417test('Should accept ResultDetectionCondition = Detected Not Quantified', async (t) => {418 const valid = validate({419 ResultDetectionCondition: 'Detected Not Quantified'420 })421 t.false(valid)422 t.is(423 checkProperty(424 validate.errors,425 'enum',426 'ResultDetectionQuantitationLimitType'427 ),428 false429 )430 t.is(431 checkProperty(432 validate.errors,433 'enum',434 'ResultDetectionQuantitationLimitMeasure'435 ),436 false437 )438 t.is(439 checkProperty(440 validate.errors,441 'enum',442 'ResultDetectionQuantitationLimitUnit'443 ),444 false445 )446})447// allOf/5448test('Should reject ActivityType = Sample for ResultAnalyticalMethodID', async (t) => {449 const valid = validate({450 ActivityType: 'Sample-Other'451 })452 t.false(valid)453 t.is(454 checkProperty(validate.errors, 'dependencies', 'ResultAnalyticalMethodID'),455 true456 )457 t.is(458 checkProperty(459 validate.errors,460 'dependencies',461 'ResultAnalyticalMethodContext'462 ),463 true464 )465})466test('Should accept ActivityType = Sample for ResultAnalyticalMethodID', async (t) => {467 const valid = validate({468 ActivityType: 'Sample-Other',469 ResultAnalyticalMethodID: '0',470 ResultAnalyticalMethodContext: 'ENV'471 })472 t.false(valid)473 t.is(474 checkProperty(validate.errors, 'dependencies', 'ResultAnalyticalMethodID'),475 false476 )477 t.is(478 checkProperty(479 validate.errors,480 'dependencies',481 'ResultAnalyticalMethodContext'482 ),483 false484 )485})486test('Should reject ActivityType = Sample for ResultAnalyticalMethodName', async (t) => {487 const valid = validate({488 ActivityType: 'Sample-Other'489 })490 t.false(valid)491 t.is(492 checkProperty(493 validate.errors,494 'dependencies',495 'ResultAnalyticalMethodName'496 ),497 true498 )499})500test('Should accept ActivityType = Sample for ResultAnalyticalMethodName', async (t) => {501 const valid = validate({502 ActivityType: 'Sample-Other',503 ResultAnalyticalMethodName: 'Unspecified'504 })505 t.false(valid)506 t.is(507 checkProperty(508 validate.errors,509 'dependencies',510 'ResultAnalyticalMethodName'511 ),512 false513 )514})515// CSV Injection516test('Should reject columns with potential csv injection', async (t) => {517 const valid = validate({518 DatasetName: '=equals',519 MonitoringLocationID: '+positive',520 MonitoringLocationName: '-negative',521 ResultComment: '@at ',522 ResultAnalyticalMethodID: `523carriage return`,524 ResultAnalyticalMethodName: '\ncarriage return',525 LaboratoryName: '\rcarriage return',526 LaboratorySampleID: '\ttab'527 })528 t.false(valid)529 t.is(checkProperty(validate.errors, 'pattern', 'DatasetName'), true)530 t.is(checkProperty(validate.errors, 'pattern', 'MonitoringLocationID'), true)531 t.is(532 checkProperty(validate.errors, 'pattern', 'MonitoringLocationName'),533 true534 )535 t.is(checkProperty(validate.errors, 'pattern', 'ResultComment'), true)536 t.is(537 checkProperty(validate.errors, 'pattern', 'ResultAnalyticalMethodID'),538 true539 )540 t.is(541 checkProperty(validate.errors, 'pattern', 'ResultAnalyticalMethodName'),542 true543 )544 t.is(checkProperty(validate.errors, 'pattern', 'LaboratoryName'), true)545 t.is(checkProperty(validate.errors, 'pattern', 'LaboratorySampleID'), true)546})547test('Should accept columns without potential csv injection', async (t) => {548 const valid = validate({549 DatasetName: '~',550 MonitoringLocationID: '1',551 MonitoringLocationName: '&',552 ResultComment: '$',553 ResultAnalyticalMethodID: '#',554 ResultAnalyticalMethodName: '|',555 LaboratoryName: '_',556 LaboratorySampleID: '*'557 })558 t.false(valid)559 // console.log(valid, JSON.stringify(validate.errors, null, 2))560 t.is(checkProperty(validate.errors, 'pattern', 'DatasetName'), false)561 t.is(562 checkProperty(validate.errors, 'pattern', 'MonitoringLocationID'),563 false564 )565 t.is(566 checkProperty(validate.errors, 'pattern', 'MonitoringLocationName'),567 false568 )569 t.is(checkProperty(validate.errors, 'pattern', 'ResultComment'), false)570 t.is(571 checkProperty(validate.errors, 'pattern', 'ResultAnalyticalMethodID'),572 false573 )574 t.is(575 checkProperty(validate.errors, 'pattern', 'ResultAnalyticalMethodName'),576 false577 )578 t.is(checkProperty(validate.errors, 'pattern', 'LaboratoryName'), false)579 t.is(checkProperty(validate.errors, 'pattern', 'LaboratorySampleID'), false)...

Full Screen

Full Screen

object-assign-fast-path.js

Source:object-assign-fast-path.js Github

copy

Full Screen

...16 throw new Error('not thrown');17 if (String(error) !== errorMessage)18 throw new Error(`bad error: ${String(error)}`);19}20function checkProperty(object, name, value, attributes = { writable: true, enumerable: true, configurable: true })21{22 var desc = Object.getOwnPropertyDescriptor(object, name);23 shouldBe(!!desc, true);24 shouldBe(desc.writable, attributes.writable);25 shouldBe(desc.enumerable, attributes.enumerable);26 shouldBe(desc.configurable, attributes.configurable);27 shouldBe(desc.value, value);28}29{30 let result = Object.assign({}, RegExp);31 shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["$1","$2","$3","$4","$5","$6","$7","$8","$9","input","lastMatch","lastParen","leftContext","multiline","rightContext"]`);32}33{34 function Hello() { }35 let result = Object.assign(Hello, {36 ok: 4237 });38 shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["arguments","caller","length","name","ok","prototype"]`);39 checkProperty(result, "ok", 42);40}41{42 let result = Object.assign({ ok: 42 }, { 0: 0, 1: 1 });43 shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["0","1","ok"]`);44 checkProperty(result, "ok", 42);45 checkProperty(result, "0", 0);46 checkProperty(result, "1", 1);47}48{49 let object = { 0: 0, 1: 1 };50 ensureArrayStorage(object);51 let result = Object.assign({ ok: 42 }, object);52 shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["0","1","ok"]`);53 checkProperty(result, "ok", 42);54 checkProperty(result, "0", 0);55 checkProperty(result, "1", 1);56}57{58 let called = false;59 let result = Object.assign({}, {60 get hello() {61 called = true;62 return 42;63 }64 });65 shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["hello"]`);66 shouldBe(called, true);67 checkProperty(result, "hello", 42);68}69{70 let object = {};71 Object.defineProperty(object, "__proto__", {72 value: 42,73 enumerable: true,74 writable: true,75 configurable: true76 });77 checkProperty(object, "__proto__", 42);78 shouldBe(JSON.stringify(Object.getOwnPropertyNames(object).sort()), `["__proto__"]`);79 let result = Object.assign({}, object);80 shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `[]`);81 shouldBe(Object.getOwnPropertyDescriptor(result, "__proto__"), undefined);82 shouldBe(result.__proto__, Object.prototype);83}84{85 let object = {};86 Object.defineProperty(object, "hello", {87 value: 42,88 writable: false,89 enumerable: true,90 configurable: false91 });92 checkProperty(object, "hello", 42, { writable: false, enumerable: true, configurable: false });93 shouldBe(JSON.stringify(Object.getOwnPropertyNames(object).sort()), `["hello"]`);94 shouldThrow(() => {95 Object.assign(object, { hello: 50 });96 }, `TypeError: Attempted to assign to readonly property.`);97}98{99 let counter = 0;100 let helloCalled = null;101 let okCalled = null;102 let source = {};103 source.hello = 42;104 source.ok = 52;105 checkProperty(source, "hello", 42);106 checkProperty(source, "ok", 52);107 shouldBe(JSON.stringify(Object.getOwnPropertyNames(source)), `["hello","ok"]`);108 let result = Object.assign({109 set hello(value) {110 this.__hello = value;111 helloCalled = counter++;112 },113 set ok(value) {114 this.__ok = value;115 okCalled = counter++;116 }117 }, source);118 checkProperty(result, "__hello", 42);119 checkProperty(result, "__ok", 52);120 shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["__hello","__ok","hello","ok"]`);121 shouldBe(helloCalled, 0);122 shouldBe(okCalled, 1);123}124{125 let builtin = createBuiltin(`(function (obj) {126 return @getByIdDirectPrivate(obj, "generatorState");127 })`);128 function* hello() { }129 let generator = hello();130 shouldBe(typeof builtin(generator), "number");131 let result = Object.assign({}, generator);132 shouldBe(typeof builtin(result), "undefined");133}...

Full Screen

Full Screen

10b7a7cfb27c80eb26eb4056f77e7853.js

Source:10b7a7cfb27c80eb26eb4056f77e7853.js Github

copy

Full Screen

...4}5function normalArgs() {6 return (function (a, b, c) { return arguments; })(1, 2);7}8function checkProperty(options, prop, shouldThrow) {9 var desc, orig;10 var obj = options.strict ? strictArgs() : normalArgs();11 var objType = options.strict ? "strict arguments." : "normal arguments.";12 function check() {13 orig = Object.getOwnPropertyDescriptor(obj, prop);14 var threw = false;15 try {16 obj[prop] = obj[prop];17 }18 catch (e) {19 threw = true;20 }21 assertEq(threw, shouldThrow, objType + prop + " threw");22 if (orig === undefined) {23 // The property wasn't defined, so we can skip it.24 return;25 }26 desc = Object.getOwnPropertyDescriptor(obj, prop);27 if ("value" in orig) {28 assertEq(desc.value, orig.value, objType + prop + " value");29 } else {30 assertEq(desc.get, orig.get, objType + prop + " get");31 assertEq(desc.set, orig.set, objType + prop + " set");32 }33 assertEq(desc.writable, orig.writable, objType + prop + " writable");34 assertEq(desc.enumerable, orig.enumerable, objType + prop + " enumerable");35 assertEq(desc.configurable, orig.configurable, objType + prop + " configurable");36 }37 check();38 if (orig && orig.configurable) {39 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }40 Object.defineProperty(obj, prop, {writable: false, enumerable: true});41 check();42 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }43 Object.defineProperty(obj, prop, {writable: true, enumerable: false});44 check();45 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }46 Object.defineProperty(obj, prop, {writable: false, configurable: false});47 check();48 }49}50checkProperty({strict: true, refresh: true}, 'callee', true);51checkProperty({strict: true, refresh: false}, 'callee', true);52checkProperty({strict: false, refresh: true}, 'callee', false);53checkProperty({strict: false, refresh: false}, 'callee', false);54checkProperty({strict: true, refresh: true}, 'length', false);55checkProperty({strict: true, refresh: false}, 'length', false);56checkProperty({strict: false, refresh: true}, 'length', false);57checkProperty({strict: false, refresh: false}, 'length', false);58for (var i = 0; i <= 5; i++) {59 checkProperty({strict: true, refresh: true}, "" + i, false);60 checkProperty({strict: true, refresh: false}, "" + i, false);61 checkProperty({strict: false, refresh: true}, "" + i, false);62 checkProperty({strict: false, refresh: false}, "" + i, false);...

Full Screen

Full Screen

args-attributes.js

Source:args-attributes.js Github

copy

Full Screen

...3}4function normalArgs() {5 return (function (a, b, c) { return arguments; })(1, 2);6}7function checkProperty(options, prop, shouldThrow) {8 var desc, orig;9 var obj = options.strict ? strictArgs() : normalArgs();10 var objType = options.strict ? "strict arguments." : "normal arguments.";11 function check() {12 orig = Object.getOwnPropertyDescriptor(obj, prop);13 var threw = false;14 try {15 obj[prop] = obj[prop];16 }17 catch (e) {18 threw = true;19 }20 assertEq(threw, shouldThrow, objType + prop + " threw");21 if (orig === undefined) {22 // The property wasn't defined, so we can skip it.23 return;24 }25 desc = Object.getOwnPropertyDescriptor(obj, prop);26 if ("value" in orig) {27 assertEq(desc.value, orig.value, objType + prop + " value");28 } else {29 assertEq(desc.get, orig.get, objType + prop + " get");30 assertEq(desc.set, orig.set, objType + prop + " set");31 }32 assertEq(desc.writable, orig.writable, objType + prop + " writable");33 assertEq(desc.enumerable, orig.enumerable, objType + prop + " enumerable");34 assertEq(desc.configurable, orig.configurable, objType + prop + " configurable");35 }36 check();37 if (orig && orig.configurable) {38 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }39 Object.defineProperty(obj, prop, {writable: false, enumerable: true});40 check();41 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }42 Object.defineProperty(obj, prop, {writable: true, enumerable: false});43 check();44 if(options.refresh) { obj = options.strict ? strictArgs() : normalArgs(); }45 Object.defineProperty(obj, prop, {writable: false, configurable: false});46 check();47 }48}49checkProperty({strict: true, refresh: true}, 'callee', true);50checkProperty({strict: true, refresh: false}, 'callee', true);51checkProperty({strict: false, refresh: true}, 'callee', false);52checkProperty({strict: false, refresh: false}, 'callee', false);53checkProperty({strict: true, refresh: true}, 'length', false);54checkProperty({strict: true, refresh: false}, 'length', false);55checkProperty({strict: false, refresh: true}, 'length', false);56checkProperty({strict: false, refresh: false}, 'length', false);57for (var i = 0; i <= 5; i++) {58 checkProperty({strict: true, refresh: true}, "" + i, false);59 checkProperty({strict: true, refresh: false}, "" + i, false);60 checkProperty({strict: false, refresh: true}, "" + i, false);61 checkProperty({strict: false, refresh: false}, "" + i, false);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch({headless: false});4 const page = await browser.newPage();5 const title = await page.title();6 await page.waitFor(2000);7 await page.screenshot({path: 'screenshot.png'});8 await browser.close();9})();10How to use Puppeteer to automate web browser? (Part 2)11How to use Puppeteer to automate web browser? (Part 3)12How to use Puppeteer to automate web browser? (Part 4)13How to use Puppeteer to automate web browser? (Part 5)14How to use Puppeteer to automate web browser? (Part 6)15How to use Puppeteer to automate web browser? (Part 7)16How to use Puppeteer to automate web browser? (Part 8)17How to use Puppeteer to automate web browser? (Part 9)18How to use Puppeteer to automate web browser? (Part 10)19How to use Puppeteer to automate web browser? (Part 11)20How to use Puppeteer to automate web browser? (Part 12)21How to use Puppeteer to automate web browser? (Part 13)22How to use Puppeteer to automate web browser? (Part 14)23How to use Puppeteer to automate web browser? (Part 15)24How to use Puppeteer to automate web browser? (Part 16)25How to use Puppeteer to automate web browser? (Part 17)26How to use Puppeteer to automate web browser? (Part 18)27How to use Puppeteer to automate web browser? (Part 19)28How to use Puppeteer to automate web browser? (Part 20)

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 const elementHandle = await page.$('input[type="text"]');8 const property = await elementHandle.getProperty('value');9 const propertyValue = await property.jsonValue();10 console.log(propertyValue);11 const elementHandle = await page.$('input[type="text"]');12 const property = await elementHandle.getProperty('value');13 const propertyValue = await property.jsonValue();14 console.log(propertyValue);15 const elementHandle = await page.$('input[type="text"]');16 const property = await elementHandle.getProperty('value');17 const propertyValue = await property.jsonValue();18 console.log(propertyValue);19 const elementHandle = await page.$('input[type="text"]');20 const property = await elementHandle.getProperty('value');21 const propertyValue = await property.jsonValue();22 console.log(propertyValue);23 await browser.close();24})();25const puppeteer = require('puppeteer');26const fs = require('fs');27const path = require('path');28(async () => {29 const browser = await puppeteer.launch();30 const page = await browser.newPage();31 const elementHandle = await page.$('input[type="text"]');32 const property = await elementHandle.getProperty('value');33 const propertyValue = await property.jsonValue();34 console.log(propertyValue);35 const elementHandle = await page.$('input[type="text"]');36 const property = await elementHandle.getProperty('value');37 const propertyValue = await property.jsonValue();38 console.log(propertyValue);39 const elementHandle = await page.$('input[type="text"]');40 const property = await elementHandle.getProperty('value');41 const propertyValue = await property.jsonValue();42 console.log(propertyValue);

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 const checked = await page.checkProperty('input[type="checkbox"]', 'checked');6 console.log(checked);7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 const checked = await page.checkProperty('input[type="checkbox"]', 'checked');15 console.log(checked);16 await browser.close();17})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.goto(url);6 await page.waitFor(1000);7 await page.checkProperty('input[name="q"]', 'checked', false);8 await page.type('input[name="q"]', 'Hello World');9 await page.waitFor(1000);10 await browser.close();11})();12const puppeteer = require('puppeteer');13(async () => {14 const browser = await puppeteer.launch();15 const page = await browser.newPage();16 await page.goto(url);17 await page.waitFor(1000);18 await page.checkProperty('input[name="q"]', 'checked', false);19 await page.type('input[name="q"]', 'Hello World');20 await page.waitFor(1000);21 await browser.close();22})();23const puppeteer = require('puppeteer');24(async () => {25 const browser = await puppeteer.launch();26 const page = await browser.newPage();27 await page.goto(url);28 await page.waitFor(1000);29 await page.checkProperty('input[name="q"]', 'checked', false);30 await page.type('input[name="q"]', 'Hello World');31 await page.waitFor(1000);32 await browser.close();33})();34const puppeteer = require('puppeteer');35(async () => {36 const browser = await puppeteer.launch();37 const page = await browser.newPage();38 await page.goto(url);39 await page.waitFor(1000);40 await page.checkProperty('input[name="q"]', 'checked', false);41 await page.type('input[name="q"]', 'Hello World');42 await page.waitFor(1000);43 await browser.close();44})();45const puppeteer = require('puppeteer');

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful