{"size": 2178, "ext": "js", "max_stars_repo_path": "test/e2e/utils.js", "max_stars_repo_name": "opbeat/opbeat-react", "max_stars_repo_stars_event_min_datetime": "2017-04-12T17:17:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-09T15:13:31.000Z", "max_issues_repo_path": "test/e2e/utils.js", "max_issues_repo_name": "opbeat/opbeat-react", "max_issues_repo_issues_event_min_datetime": "2017-04-05T13:17:33.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-28T11:26:57.000Z", "max_forks_repo_path": "test/e2e/utils.js", "max_forks_repo_name": "opbeat/opbeat-react", "max_forks_repo_forks_event_min_datetime": "2017-04-05T12:29:31.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-04T16:51:18.000Z"}
{"max_stars_count": 13, "max_issues_count": 15, "max_forks_count": 8, "avg_line_length": 28.2857142857, "max_line_length": 145, "alphanum_fraction": 0.6230486685}
var logLevels = {
  ALL: {value: Number.MIN_VALUE},
  DEBUG: {value: 700},
  INFO: {value: 800},
  WARNING: {value: 900},
  SEVERE: {value: 1000},
  OFF: {value: Number.MAX_VALUE}
}

var debugMode = false
var debugLevel = logLevels.INFO.value
function assertNoBrowserErrors (whitelist, done) {
  // TODO: Bug in ChromeDriver: Need to execute at least one command
  // so that the browser logs can be read out!
  browser.execute('1+1')
  browser.log('browser').then(function (response) {
    var failureEntries = []
    var debugLogs = []
    var browserLog = response.value

    for (var i = 0; i < browserLog.length; i++) {
      var logEntry = browserLog[i]
      if (isLogEntryATestFailure(logEntry, whitelist)) {
        failureEntries.push(logEntry)
      }
      if (logLevels[logEntry.level].value >= debugLevel) {
        debugLogs.push(logEntry)
      }
    }

    if (failureEntries.length > 0 || debugMode) {
      console.log('------------> FailuresLogs')
      console.log(failureEntries)
      console.log('------------> debugLogs')
      console.log(debugLogs)
    }

    expect(failureEntries.length).toEqual(0, 'Expected no errors in the browserLog but got ' + failureEntries.length + ' error(s)') // .because()
    if (typeof done === 'function') {
      done()
    } else if (debugMode) {
      console.log('done is not a function')
    }
  })
}

function isLogEntryATestFailure (entry, whitelist) {
  var result = false
  if (logLevels[entry.level].value > logLevels.WARNING.value) {
    result = true
    if (whitelist) {
      for (var i = 0, l = whitelist.length; i < l; i++) {
        if (entry.message.indexOf(whitelist[i]) !== -1) {
          result = false
          break
        }
      }
    }
  }
  return result
}
module.exports = {
  allowSomeBrowserErrors: assertNoBrowserErrors,
  verifyNoBrowserErrors: function verifyNoBrowserErrors (done) {
    return assertNoBrowserErrors([], done)
  },
  handleError: function handleError (done) {
    return function (error) {
      console.log(error, error.stack)
      if (error.message.indexOf('received Inspector.detached event') === -1) {
        done.fail(error)
      }
    // done()
    }
  }
}
