UNPKG

klee

Version:

Record browser interactions for testing.

61 lines (53 loc) 1.41 kB
const {log, error: logError} = console function base64ToJson(base64) { const buffer = Buffer.from(base64, 'base64') const string = buffer.toString('utf8') return JSON.parse(string) } function jsonToBase64(json) { const jsonString = JSON.stringify(json) return Buffer.from(jsonString).toString('base64') } function findValuesByKey(object, targetKey) { if (!(object instanceof Object)) { throw new TypeError("The 'object' param must be an instance of an Object") } const cache = new Map() const stack = [object] const found = [] while (stack.length) { const current = stack.pop() Object.entries(current).forEach(([key, value]) => { if (value) { if (key.includes(targetKey)) { found.push(value) } else if (typeof value === 'object' && !cache.has(value)) { cache.set(value, 1) stack.push(value) } } }) } return Boolean(found.length) && found } const pretty = json => JSON.stringify(json, null, 2) const waitInSeconds = (seconds = 1) => new Promise(resolve => setTimeout(resolve, seconds * 1000)) module.exports = { log, pretty, logError, base64ToJson, jsonToBase64, waitInSeconds, findValuesByKey, } /** * Add cloud recordings saving API * - Create * - Read * - Delete * Add argv parser * - Index.js to handle routes of requests * Add dashboard to output runs, codes... */