<commit_before>const electron = require('electron')
const moment = require('moment')

// const Chart = require('chart.js')
// const Options = require('../cli/options')
// const options = new Options(electron.remote.process.argv)

const $ = window.jQuery = require('jquery')
require('bootstrap')

process.on('unhandledRejection', function (reason) {
  console.log(reason.message + '\\n' + reason.stack)
  electron.remote.process.exit(3)
})

const setProgress = (bar, states) => {
  Object.keys(states).forEach((status) => {
    bar.getElementsByClassName(status)[0].style.width = `${states[status]}%`
  })
}

class State {
  constructor() {
    this.testCases = []
    this.gherkinDocs = {}
  }

  getTestCase(location) {
    return this.testCases.find(
      testCase => (testCase.uri == location.uri && testCase.locations[0].line == location.line)
    )
  }
}
let state = new State()

const render = (state) => {
  $('.status-waiting').hide()
  $('.status-started').show()

  document.getElementsByClassName('pwd')[0].innerText = state.pwd
  document.getElementsByClassName('start-time')[0].innerText = moment(state.startTime).format('h:mm:ss a on MMMM Do YYYY')

  if (!state.currentTestCase) {
    $('.status-done').show()
    $('.status-running').hide()
  } else {
    $('.status-done').hide()
    $('.status-running').show()
  }
  document.getElementById('current-test-case').innerHTML =
    state.currentTestCase && `${state.currentTestCase.uri}:${state.currentTestCase.locations[0].line}`

  document.getElementById('current-test-step').innerHTML =
    state.currentTestStep && `${state.currentTestStep.locations[0].uri || state.currentTestCase.uri}:${state.currentTestStep.locations[0].line}`

  const completedTestCases = state.testCases.filter(testCase => testCase.result)
  $('.test-cases-finished-count').text(completedTestCases.length)
  const completedTestCasesWithResult = (status) => {
    return completedTestCases.filter(testCase => testCase.result.status == status)
  }

  setProgress(
    document.getElementById('progressOfTestRun'),
    {
      passed: completedTestCasesWithResult('passed').length / state.testCases.length * 100,
      failed: completedTestCasesWithResult('failed').length / state.testCases.length * 100,
      pending: completedTestCasesWithResult('pending').length / state.testCases.length * 100,
    }
  )

  const allTestSteps = state.testCases.reduce((result, testCase) => result.concat(testCase.steps), [])
  const completedTestSteps = allTestSteps.filter(step => step.result)
  $('.test-steps-finished-count').text(completedTestSteps.length)
}

const resetState = () => {
  document.getElementById('main').innerHTML = ''
  setProgress(
    document.getElementById('progressOfTestRun'),
    { passed: 0, failed: 0, skipped: 0, pending: 0 }
  )
}

const getTestCaseDiv = (location) => {
  return document.querySelector(`[x-test-case-location='${location}']`)
}

const events = electron.ipcRenderer

//   state.pwd = message.workingDirectory
events.on('start', () => {
  state = new State()
  state.startTime = new Date()
  render(state)

  resetState()
})

require('gherkin')
const Gherkin = window.Gherkin
const parser = new Gherkin.Parser(new Gherkin.AstBuilder())

events.on('source', (event, message) => {
  state.gherkinDocs[message.uri] = {
    body: message.data,
    ast: parser.parse(message.data),
  }
})

events.on('pickle', (event, message) => {
  message.pickle.uri = message.uri
  state.testCases.push(message.pickle)
  const location = `${message.pickle.locations[0].uri || message.uri}:${message.pickle.locations[0].line}`

  const div = document.createElement('div')

  div.setAttribute('x-test-case-location', location)<commit_msg>Display project name / working directory and start time<commit_after>const electron = require('electron')
const moment = require('moment')
const path = require('path')

// const Chart = require('chart.js')
// const Options = require('../cli/options')
// const options = new Options(electron.remote.process.argv)

const $ = window.jQuery = require('jquery')
require('bootstrap')

process.on('unhandledRejection', function (reason) {
  console.log(reason.message + '\\n' + reason.stack)
  electron.remote.process.exit(3)
})

const setProgress = (bar, states) => {
  Object.keys(states).forEach((status) => {
    bar.getElementsByClassName(status)[0].style.width = `${states[status]}%`
  })
}

class State {
  constructor() {
    this.testCases = []
    this.gherkinDocs = {}
  }

  getTestCase(location) {
    return this.testCases.find(
      testCase => (testCase.uri == location.uri && testCase.locations[0].line == location.line)
    )
  }
}
let state = new State()

const render = (state) => {
  const projectName = path.basename(state.pwd)
  const startTime = moment(state.startTime).format('h:mm:ss a on MMMM Do YYYY')
  document.title = `Cucumber - ${projectName} (${startTime})`
  
  $('.status-waiting').hide()
  $('.status-started').show()

  document.getElementsByClassName('pwd')[0].innerText = state.pwd
  document.getElementsByClassName('start-time')[0].innerText = startTime

  if (!state.currentTestCase) {
    $('.status-done').show()
    $('.status-running').hide()
  } else {
    $('.status-done').hide()
    $('.status-running').show()
  }
  document.getElementById('current-test-case').innerHTML =
    state.currentTestCase && `${state.currentTestCase.uri}:${state.currentTestCase.locations[0].line}`

  document.getElementById('current-test-step').innerHTML =
    state.currentTestStep && `${state.currentTestStep.locations[0].uri || state.currentTestCase.uri}:${state.currentTestStep.locations[0].line}`

  const completedTestCases = state.testCases.filter(testCase => testCase.result)
  $('.test-cases-finished-count').text(completedTestCases.length)
  const completedTestCasesWithResult = (status) => {
    return completedTestCases.filter(testCase => testCase.result.status == status)
  }

  setProgress(
    document.getElementById('progressOfTestRun'),
    {
      passed: completedTestCasesWithResult('passed').length / state.testCases.length * 100,
      failed: completedTestCasesWithResult('failed').length / state.testCases.length * 100,
      pending: completedTestCasesWithResult('pending').length / state.testCases.length * 100,
    }
  )

  const allTestSteps = state.testCases.reduce((result, testCase) => result.concat(testCase.steps), [])
  const completedTestSteps = allTestSteps.filter(step => step.result)
  $('.test-steps-finished-count').text(completedTestSteps.length)
}

const resetState = () => {
  document.getElementById('main').innerHTML = ''
  setProgress(
    document.getElementById('progressOfTestRun'),
    { passed: 0, failed: 0, skipped: 0, pending: 0 }
  )
}

const getTestCaseDiv = (location) => {
  return document.querySelector(`[x-test-case-location='${location}']`)
}

const events = electron.ipcRenderer

events.on('start', (event, message) => {
  state = new State()
  state.startTime = message.timestamp * 1000 || new Date()
  state.pwd = message.workingDirectory || 'unknown'

  render(state)

  resetState()
})

require('gherkin')
const Gherkin = window.Gherkin
const parser = new Gherkin.Parser(new Gherkin.AstBuilder())

events.on('source', (event, message) => {
  state.gherkinDocs[message.uri] = {
    body: message.data,
    ast: parser.parse(message.data),
  }
})

events.on('pickle', (event, message) => {
  message.pickle.uri = message.uri
  state.testCases.push(message.pickle)
  const location = `${message.pickle.locations[0].uri || message.uri}:${message.pickle.locations[0].line}`

  const div = document.createElement('div')

  div.setAttribute('x-test-case-location', location)
{'fraction_non_alphanumeric': 0.16801672328194409, 'fraction_numerical': 0.006532532009406846, 'mean_word_length': 4.55918663761801, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2594327', 'n_tokens_mistral': 2454, 'n_tokens_neox': 2391, 'n_words': 382}