lukejpreston / junit_viewer

Start a mini service to view junit reports
39 stars 17 forks source link

Add console renderer #33

Closed vjpr closed 7 years ago

vjpr commented 8 years ago

It would be nice to be able to view the output in a similar format to when mocha console spec reporter.

vjpr commented 8 years ago

Here is one I whipped up:

import _ from 'lodash'
import c from 'chalk'
import indentString from 'indent-string'
import ms from 'milliseconds'

class JUnitReporter {

  report(parsedData) {
    //console.log(parsedData)

    function colorize(status, msg) {
      return c[statusToColor[status]](msg)
    }

    // TODO(vjpr): Add timings.
    const {title, suites, junit_info} = parsedData
    suites.forEach((s) => {
      const statusSymbol = statusToSymbol[s.type]
      let str = `${statusSymbol} Suite: ${s.name} - ${ms.seconds(s.time)}ms`
      str = colorize(s.type, str)
      console.log(str)
      s.testCases.forEach(tc => {
        const statusSymbol = statusToSymbol[tc.type]
        let str = `${statusSymbol} ${tc.name} - ${ms.seconds(tc.time)}ms`
        str = indentString(str, 2)
        str = colorize(tc.type, str)
        console.log(str)
        if (tc.type === 'failure') {
          console.log()
          tc.messages.values.forEach(m => {
            let str = m.value.replace(/\{newline\}/g, '\n')
            str = c.grey(str)
            str = indentString(str, 4)
            console.log(str)
          })
          console.log()
        }
      })
      console.log()
    })

    // Summary
    const {suites: summarySuites, tests} = junit_info
    const suiteStats = `Suites: ${summarySuites.passed}/${summarySuites.count}`
    const testStats = `Tests: ${tests.passed}/${tests.count}`
    console.log(c.bold('Summary: ') + suiteStats + ' ' + testStats)

  }

}
lukejpreston commented 8 years ago

brain dump:

There are loads of scenarios which the junit viewer takes into account. If you want to make a PR I think that would be a good idea. It would be good to extend junit viewer to be able to do console output and have a command line are, something like --console also extend the api because right now it only knows about creating HTML files. It would also be important to include the filtering functionality something like --filter='string filter' and --filter-suite='string filter' for example. Filtering and searching was important in this version of junit viewer. You should be able to re-use the filtering code (under tested and needs re-thinking) for this output as well.

junit viewer was built prior to es6 and was built when node 4 wasn't active LTS or in migratory phase so the code looks pretty old compared to this. I am not using lodash (and neither are you in this example), most things lodash is used for can be replaced with much more optimised code and equally readable imo; so avoid lodash if you decide to do a PR.

A lot of the scenarios are covered in the data and the tests. Ideally you should be able to get all the information from those. Things like properties and nested suites were complex to view in the html output.

The code is really due to be reactified and babelified anyway so when I do that I could look into doing this as well.

thoughts?

lukejpreston commented 7 years ago

this project is now deprecated, please see https://github.com/lukejpreston/xunit-viewer which supports the same features

the new one has a console rederer