<commit_before>/*global XMLHttpRequest,$,html2canvas,chai */
function httpGet(theUrl) {
  var xmlHttp = new XMLHttpRequest()
  xmlHttp.open('GET', theUrl, false) // false for synchronous request
  xmlHttp.send(null)
  return xmlHttp.responseText
}

function capture(imageName, height = null, width = null, misMatchPercentageMargin = 0.00, imageDirectory = 'visual-acceptance') {
  var browser = window.ui
  var istargetbrowser = JSON.parse(httpGet("/istargetbrowser?browser%5B" + encodeURIComponent(browser)))
  if (istargetbrowser === false) {
    return new Promise(function(resolve, reject) {
      resolve("Does not match target browser");
    })
  }
  $(document.getElementById('ember-testing')).css('zoom', 'normal')
  $(document.getElementById('ember-testing')).css('width', '100%')
  $(document.getElementById('ember-testing')).css('height', '100%')
  $(document.getElementById('ember-testing-container')).css('overflow', 'visible')
  $(document.getElementById('ember-testing-container')).css('position', 'initial')

  var browserDirectory = browser.os + '/' + browser.osversion + '/' + browser.browser + '/'
  if (height !== null && width !== null) {
    $(document.getElementById('ember-testing-container')).css('width', width + 'px')
    $(document.getElementById('ember-testing-container')).css('height', height + 'px')
    browserDirectory += width + 'x' + height + '/'
  } else {
    // default mocha window size
    browserDirectory += 640 + 'x' + 384 + '/'
  }
  resemble.outputSettings({
    largeImageThreshold: 0
  })
  return html2canvas(document.getElementById('ember-testing-container'), {
    height: null,
    width: null
  }).then(function(canvas) {
    // Get test dummy image
    var image = canvas.toDataURL('image/png')
    var visualAcceptanceContainer
    if (!document.getElementById('visual-acceptance')) {
      visualAcceptanceContainer = document.createElement('div')
      visualAcceptanceContainer.setAttribute('id', 'visual-acceptance')
      visualAcceptanceContainer.innerHTML = '<h3> Visual Acceptance tests: </h3> <ul id="visual-acceptance-report"> </ul>'
      document.body.appendChild(visualAcceptanceContainer)
    } else {
      visualAcceptanceContainer = document.getElementById('visual-acceptance')
    }
    var node = document.createElement('div')
      // Get passed image
    var res = JSON.parse(httpGet('/image?name=' + encodeURIComponent(browserDirectory + imageName) + '-passed.png'))
    if (res.error === 'File does not exist') {
      // Save image as passed if no existing passed image
      $.ajax({
        type: 'POST',
        async: false,
        url: '/passed',
        data: {
          image: image,
          name: browserDirectory + imageName + '.png'
        }
      })
      $(document.getElementById('ember-testing-container')).removeAttr('style')
      return 'No passed image. Saving current test as base'

    } else {
      // Passed image exists so compare to current
      res.image = 'data:image/png;base64,' + res.image
      return new Promise(function(resolve, reject) {
        resemble(res.image).compareTo(image).ignoreAntialiasing().onComplete(function(data) {
          var result = false

          if (parseFloat(data.misMatchPercentage) <= misMatchPercentageMargin) {
            // Passed
            $.ajax({
              type: 'POST',<commit_msg>Something super finicky about the output settings and not having scaleToSameSize that will cause resemble to be slightly mismatched sometimes (Same environment, everything)<commit_after>/*global XMLHttpRequest,$,html2canvas,chai */
function httpGet(theUrl) {
  var xmlHttp = new XMLHttpRequest()
  xmlHttp.open('GET', theUrl, false) // false for synchronous request
  xmlHttp.send(null)
  return xmlHttp.responseText
}

function capture(imageName, height = null, width = null, misMatchPercentageMargin = 0.00, imageDirectory = 'visual-acceptance') {
  var browser = window.ui
  var istargetbrowser = JSON.parse(httpGet("/istargetbrowser?browser%5B" + encodeURIComponent(browser)))
  if (istargetbrowser === false) {
    return new Promise(function(resolve, reject) {
      resolve("Does not match target browser");
    })
  }
  $(document.getElementById('ember-testing')).css('zoom', 'normal')
  $(document.getElementById('ember-testing')).css('width', '100%')
  $(document.getElementById('ember-testing')).css('height', '100%')
  $(document.getElementById('ember-testing-container')).css('overflow', 'visible')
  $(document.getElementById('ember-testing-container')).css('position', 'initial')

  var browserDirectory = browser.os + '/' + browser.osversion + '/' + browser.browser + '/'
  if (height !== null && width !== null) {
    $(document.getElementById('ember-testing-container')).css('width', width + 'px')
    $(document.getElementById('ember-testing-container')).css('height', height + 'px')
    browserDirectory += width + 'x' + height + '/'
  } else {
    // default mocha window size
    browserDirectory += 640 + 'x' + 384 + '/'
  }
  // resemble.outputSettings({
  //   largeImageThreshold: 0
  // })
  return html2canvas(document.getElementById('ember-testing-container'), {
    height: null,
    width: null
  }).then(function(canvas) {
    // Get test dummy image
    var image = canvas.toDataURL('image/png')
    var visualAcceptanceContainer
    if (!document.getElementById('visual-acceptance')) {
      visualAcceptanceContainer = document.createElement('div')
      visualAcceptanceContainer.setAttribute('id', 'visual-acceptance')
      visualAcceptanceContainer.innerHTML = '<h3> Visual Acceptance tests: </h3> <ul id="visual-acceptance-report"> </ul>'
      document.body.appendChild(visualAcceptanceContainer)
    } else {
      visualAcceptanceContainer = document.getElementById('visual-acceptance')
    }
    var node = document.createElement('div')
      // Get passed image
    var res = JSON.parse(httpGet('/image?name=' + encodeURIComponent(browserDirectory + imageName) + '-passed.png'))
    if (res.error === 'File does not exist') {
      // Save image as passed if no existing passed image
      $.ajax({
        type: 'POST',
        async: false,
        url: '/passed',
        data: {
          image: image,
          name: browserDirectory + imageName + '.png'
        }
      })
      $(document.getElementById('ember-testing-container')).removeAttr('style')
      return 'No passed image. Saving current test as base'

    } else {
      // Passed image exists so compare to current
      res.image = 'data:image/png;base64,' + res.image
      return new Promise(function(resolve, reject) {
        resemble(res.image).compareTo(image).scaleToSameSize().onComplete(function(data) {
          var result = false

          if (parseFloat(data.misMatchPercentage) <= misMatchPercentageMargin) {
            // Passed
            $.ajax({
              type: 'POST',
{'fraction_non_alphanumeric': 0.14514952589350838, 'fraction_numerical': 0.006710430342815463, 'mean_word_length': 3.613728129205922, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6347462', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1881, 'n_words': 423}