nickbradley / autotest

CPSC 310 GitHub integration service.
1 stars 2 forks source link

Coverage can be "Unknown" which breaks view #14

Closed nickbradley closed 7 years ago

nickbradley commented 7 years ago

The view results/_design/grades/_view/byTeamDeliverableCommit is broken when coverage.lines.percentage is "Unknown".

The code for the view is

function(doc) {
        if (doc.team && doc.deliverable && doc.commit && doc.deliverable.deliverable !== 'd0') {
          if (doc.buildFailed || doc.containerExitCode > 0) {
            emit([doc.team, doc.deliverable, doc.commit],
              {
                'deliverable': doc.deliverable,
                'exitCode': doc.container.exitcode,
                'buildFailed': doc.buildFailed,
                'buildMsg': doc.buildMsg,
                'grade': 0,
                'testGrade': -1,
                'testSummary': 'Tests did not run.',
                'coverageGrade': -1,
                'coverStderr': '',
                'scriptVersion': doc.container.scriptVersion,
                'suiteVersion': doc.container.suiteVersion,
                'failedTests': []
              })
          } else {
            var tStats = doc.testStats;
            emit([doc.team, doc.deliverable, doc.commit], {
              'deliverable': doc.deliverable,
              'exitCode': doc.container.exitcode,
              'buildFailed': doc.buildFailed,
              'buildMsg': doc.buildMsg,
              'grade': +(0.8*tStats.passPercent + 0.2*Math.min(doc.coverStats.lines.percentage+5, 100)).toFixed(2),
              'testGrade': tStats.passPercent,
              'testSummary': tStats.passCount + ' passing, ' + tStats.failCount + ' failing, ' + tStats.skipCount + ' skipped',
              'coverageGrade': doc.coverStats.lines.percentage,
              'coverStderr': doc.coverStderr,
              'scriptVersion': doc.container.scriptVersion,
              'suiteVersion': doc.container.suiteVersion,
              'failedTests': doc.testReport.allFailures.map(function(test) {
                var name = test.title;
                var code = name.substring(name.indexOf('~')+1, name.lastIndexOf('~'));
                //return code + ': ' + name.substring(name.lastIndexOf('~')+1);
                return code + ': ' + name.substring(name.lastIndexOf('~')+1, name.indexOf('.')+1);
              })
            })
          }
        }
      }
nickbradley commented 7 years ago
function(doc) {
        if (doc.team && doc.deliverable && doc.commit && doc.deliverable.deliverable !== 'd0') {
          if (doc.buildFailed || doc.containerExitCode > 0) {
            emit([doc.team, doc.deliverable, doc.commit],
              {
                'deliverable': doc.deliverable,
                'exitCode': doc.container.exitcode,
                'buildFailed': doc.buildFailed,
                'buildMsg': doc.buildMsg,
                'grade': 0,
                'testGrade': -1,
                'testSummary': 'Tests did not run.',
                'coverageGrade': -1,
                'coverStderr': '',
                'scriptVersion': doc.container.scriptVersion,
                'suiteVersion': doc.container.suiteVersion,
                'failedTests': []
              })
          } else {
            var tStats = doc.testStats;
            var coverage = doc.coverStats.lines.percentage === "Unknown" ? 0 : doc.coverStats.lines.percentage
            emit([doc.team, doc.deliverable, doc.commit], {
              'deliverable': doc.deliverable,
              'exitCode': doc.container.exitcode,
              'buildFailed': doc.buildFailed,
              'buildMsg': doc.buildMsg,
              'grade': +(0.8*tStats.passPercent + 0.2*Math.min(coverage+5, 100)).toFixed(2),
              'testGrade': tStats.passPercent,
              'testSummary': tStats.passCount + ' passing, ' + tStats.failCount + ' failing, ' + tStats.skipCount + ' skipped',
              'coverageGrade': coverage,
              'coverStderr': doc.coverStderr,
              'scriptVersion': doc.container.scriptVersion,
              'suiteVersion': doc.container.suiteVersion,
              'failedTests': doc.testReport.allFailures.map(function(test) {
                var name = test.title;
                var code = name.substring(name.indexOf('~')+1, name.lastIndexOf('~'));
                return code + ': ' + name.substring(name.lastIndexOf('~')+1);
                //return code + ': ' + name.substring(name.lastIndexOf('~')+1, name.indexOf('.')+1);
              })
            })
          }
        }
      }