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WAAW,KAAK,KACzB","file":"/npm/gore@1.0.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/gore@1.0.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\n'use strict'\n\nvar util = require('util')\n\nvar {Launcher} = require('lighthouse/chrome-launcher')\nvar chrome = require('chrome-remote-interface')\n\nvar remote_debug = util.promisify(function(x, cb) {\n  chrome(cb.bind(cb, null)).on('error', cb)\n})\n\nasync function next_test_or_quit(test_index, suite, failed, passed) {\n  // if there are no more tests to run\n  if (test_index >= suite.length) {\n    // report failures\n    failed.forEach(function(failure) {\n      console.log('[gore]', 'failure:', failure)\n    })\n    // report successes\n    passed.forEach(function(pass) {\n      console.log('[gore]', 'passed:', pass)\n    })\n    // shut down chrome, remote debug interface and node\n    var exit = process.exit.bind(process, failed.length ? 1 : 0)\n    return Promise.all([\n      this.rd.close(),\n      this.launcher.kill()\n    ]).catch(function(err) {\n      console.log(err)\n      exit()\n    }).then(exit)\n  }\n  // otherwise, navigate to the next test starting point\n  console.log('[gore]', 'starting:', suite[test_index].description)\n  try {\n    await this.rd.Page.navigate({url: suite[test_index].start_at})\n  } catch (e) {\n    failed.push(`test ${test_index + 1} step 1 failed with navigation error ${e}`)\n    return (await next_test_or_quit.call(this, ++test_index, suite, failed, passed))\n  }\n  return 0\n}\n\nfunction validate_suite(suite) {\n  console.log('[gore]', 'starting:', 'test suite type check')\n  if (!(Array.isArray(suite) && suite.length)) {\n    throw new Error('expected lengthy array `suite`')\n  }\n  for (var test in suite) {\n    if (!(typeof suite[test].start_at === 'string' &&\n          suite[test].start_at.length)) {\n      throw new Error('expected lengthy string `start_at`')\n    }\n    suite[test].description = suite[test].description || `test ${+test + 1}`\n    if (!(Array.isArray(suite[test].steps) && suite[test].steps.length)) {\n      throw new Error('expected lengthy array `steps`')\n    }\n    for (var func in suite[test].steps) {\n      if (!(typeof suite[test].steps[func] === 'function')) {\n        throw new Error('expected function in `steps` array')\n      }\n    }\n  }\n  console.log('[gore]', 'passed:', 'test suite type check')\n}\n\nfunction get_export() {\n  return {\n    input: this.rd.Input,\n    page: this.rd.Page,\n    dom: this.rd.DOM,\n    network: this.rd.Network,\n    sleep: function(duration) {\n      return new Promise(function(resolve) {\n        setTimeout(resolve, duration)\n      })\n    },\n    suite: async suite => {\n      // first ensure the test suite is usable\n\n      validate_suite(suite)\n      // accumulate user output\n      var failed = []\n      var passed = []\n\n      // set up control variables\n      var test_index = -1\n      var step_index = 0\n\n      // bind the page load event\n      this.rd.Page.loadEventFired(async _ => {\n        var threw = false\n        try {\n          // attempt to run the step\n          var result = await suite[test_index].steps[step_index]()\n        } catch (e) {\n          failed.push(`test ${test_index + 1} step ${step_index + 1} failed with an error: \\n  ${e.stack}`)\n          threw = true\n        }\n\n        var result_type = typeof result\n        if (threw) {\n          // the test threw, wait for the next test case to begin...\n        } else if (result_type === 'undefined' || result === null) {\n          if (step_index === suite[test_index].steps.length - 1) {\n            // the test case is faulty\n            failed.push(`test ${test_index + 1} step ${step_index + 1} failed to yield a boolean result`)\n            step_index = await next_test_or_quit.call(this, ++test_index, suite, failed, passed)\n            return\n          }\n          step_index += 1\n          return // return to wait for the next page load event\n                 // because the test case is not finished yet\n        } else if (result_type === 'string') {\n          try {\n            step_index += 1\n            await this.rd.Page.navigate({url: result})\n            return // return to wait for the next page load event\n                   // because the test case is not finished yet\n          } catch (e) {\n            failed.push(`test ${test_index + 1} step ${step_index + 1} failed with navigation error: \\n  ${e} \"${result}\"`)\n            step_index = await next_test_or_quit.call(this, ++test_index, suite, failed, passed)\n            return\n          }\n        } else if (result_type === 'boolean' && !result) {\n          failed.push(`test ${test_index + 1} step ${step_index + 1} failed with boolean false`)\n        } else if (result_type === 'boolean' && result) {\n          // the test passed, do nothing...\n          passed.push(suite[test_index].description)\n        } else {\n          failed.push(`test ${test_index + 1} step ${step_index + 1} failed with unexpected type: ${result_type}`)\n        }\n        step_index = await next_test_or_quit.call(this, ++test_index, suite, failed, passed)\n      })\n\n      // navigate to the first test case\n      await next_test_or_quit.call(this, ++test_index, suite, failed, passed)\n    },\n    runtime: Object.assign(this.rd.Runtime, {\n      eval: async expression => {\n        var res = await this.rd.Runtime.evaluate({\n          expression: `(function() {return new Promise(function(resolve, reject) {try {resolve((${expression.toString()})())} catch (e) {reject(e)}})})()`,\n          awaitPromise: true\n        })\n        if (res.exceptionDetails) {\n          // the input expression threw\n          var err = new (global[res.exceptionDetails.exception.className] || Error)()\n          err.stack = res.exceptionDetails.exception.description\n          throw err\n        }\n        return res.result.value\n      }\n    }),\n    kill: _ => {\n      return Promise.all([\n        this.rd.close(),\n        this.launcher.kill()\n      ]).catch(console.log)\n    }\n  }\n}\n\nvar gore = {}\n\nmodule.exports = async function(options = {}) {\n  \n  if (gore.launcher && gore.rd) return get_export.call(gore)\n  \n  gore.launcher = new Launcher({\n    port: 9222,\n    chromeFlags: [\n      `--window-size=${options.width || 1024},${options.height || 768}`,\n      '--disable-gpu',\n      '--headless'\n    ]\n  })\n\n  try {\n    gore.rd = (await (\n      gore.launcher.launch()\n    ).then(\n      remote_debug\n    ).then(function(rd) {\n      return Promise.all([\n        rd,\n        rd.Page.enable(),\n        rd.DOM.enable(),\n        rd.Network.enable(),\n        rd.Runtime.enable(),\n        rd.Log.enable()\n      ])\n    })).shift()\n  } catch (e) {\n    gore.launcher.kill().catch(console.log)\n    console.log(e)\n    throw new Error('unable to initialise remote debug context')\n  }\n\n  if (options.system) {\n    try {\n      // this throws for some reason\n      await gore.rd.SystemInfo.getInfo().then(console.log)\n    } catch (e) {\n      console.log(e)\n    }\n  }\n\n  if (options.console) gore.rd.Log.entryAdded(console.log)\n\n  return get_export.call(gore)\n}"]}