Skip to content

Commit

Permalink
logic to record skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gruber committed Jan 29, 2015
1 parent 214b304 commit 2d4a63b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var Base = mocha.reporters.Base,
generateReport = reportGen.generateReport,
saveToFile = reportGen.saveToFile;

var totalTestsRegistered = 0;

module.exports = Mochawesome;

/**
Expand Down Expand Up @@ -85,13 +87,17 @@ function Mochawesome (runner) {
allFailures: allFailures.map(cleanTest)
};

var passPercentage = Math.round((obj.stats.passes / (obj.stats.tests - obj.stats.pending))*1000)/10;
var pendingPercentage = Math.round((obj.stats.pending / obj.stats.tests)*1000)/10;
obj.stats.testsRegistered = totalTestsRegistered;

var passPercentage = Math.round((obj.stats.passes / (obj.stats.testsRegistered - obj.stats.pending))*1000)/10;
var pendingPercentage = Math.round((obj.stats.pending / obj.stats.testsRegistered)*1000)/10;

obj.stats.passPercent = passPercentage;
obj.stats.pendingPercent = pendingPercentage;
obj.stats.other = (obj.stats.passes + obj.stats.failures + obj.stats.pending) - obj.stats.tests;
obj.stats.hasOther = obj.stats.other > 0;
obj.stats.skipped = obj.stats.testsRegistered - obj.stats.tests;
obj.stats.hasSkipped = obj.stats.skipped > 0;
obj.stats.failures = obj.stats.failures - obj.stats.other;
obj.stats.passPercentClass = _getPercentClass(passPercentage);
obj.stats.pendingPercentClass = _getPercentClass(pendingPercentage);
Expand Down Expand Up @@ -156,23 +162,29 @@ function cleanSuite (suite) {
var passingTests = _.where(cleanTests, {state: 'passed'});
var failingTests = _.where(cleanTests, {state: 'failed'});
var pendingTests = _.where(cleanTests, {pending: true});
var skippedTests = _.where(cleanTests, {skipped: true});
var duration = 0;

_.each(cleanTests, function (test) {
duration += test.duration;
});

totalTestsRegistered += suite.tests ? suite.tests.length : 0;

suite.tests = cleanTests;
suite.fullFile = suite.file || '';
suite.file = suite.file ? suite.file.replace(process.cwd(), '') : '';
suite.passes = passingTests;
suite.failures = failingTests;
suite.pending = pendingTests;
suite.skipped = skippedTests;
suite.isEmpty = suite.tests.length === 0;
suite.hasSkipped = suite.skipped.length > 0;
suite.totalTests = suite.tests.length;
suite.totalPasses = passingTests.length;
suite.totalFailures = failingTests.length;
suite.totalPending = pendingTests.length;
suite.totalSkipped = skippedTests.length;
suite.duration = duration;

if (suite.root) {
Expand All @@ -188,15 +200,18 @@ function cleanSuite (suite) {
'passes',
'failures',
'pending',
'skipped',
'totalTests',
'totalPasses',
'totalFailures',
'totalPending',
'totalSkipped',
'root',
'uuid',
'duration',
'rootEmpty',
'isEmpty',
'hasSkipped',
'_timeout'
]);
}
Expand All @@ -218,7 +233,7 @@ function cleanTest (test) {
code = Highlight.highlightAuto(code, ['javascript']).value;
}

return {
var cleaned = {
title: test.title,
fullTitle: test.fullTitle(),
timedOut: test.timedOut,
Expand All @@ -234,6 +249,10 @@ function cleanTest (test) {
uuid: uuid.v4(),
parentUUID: test.parent.uuid
};

cleaned.skipped = (!cleaned.pass && !cleaned.fail && !cleaned.pending);

return cleaned;
}

/**
Expand Down

0 comments on commit 2d4a63b

Please # to comment.