diff --git a/bin/mocha.js b/bin/mocha.js old mode 100644 new mode 100755 diff --git a/lib/reporters/spec.js b/lib/reporters/spec.js index 8497249f73..fa587560d9 100644 --- a/lib/reporters/spec.js +++ b/lib/reporters/spec.js @@ -45,46 +45,60 @@ function Spec(runner, options) { return Array(indents).join(' '); } - runner.on(EVENT_RUN_BEGIN, function () { + runner.on(EVENT_RUN_BEGIN, function() { Base.consoleLog(); }); - runner.on(EVENT_SUITE_BEGIN, function (suite) { + runner.on(EVENT_SUITE_BEGIN, function(suite) { ++indents; Base.consoleLog(color('suite', '%s%s'), indent(), suite.title); }); - runner.on(EVENT_SUITE_END, function () { + runner.on(EVENT_SUITE_END, function() { --indents; if (indents === 1) { Base.consoleLog(); } }); - runner.on(EVENT_TEST_PENDING, function (test) { + runner.on(EVENT_TEST_PENDING, function(test) { var fmt = indent() + color('pending', ' - %s'); Base.consoleLog(fmt, test.title); }); - runner.on(EVENT_TEST_PASS, function (test) { + runner.on(EVENT_TEST_PASS, function(test) { + function logRetries() { + if (test._currentRetry > 0) { + /* + Included message within format so it can be passed into `Base.consoleLog` as one argument + */ + var retryFmt = color( + 'bright yellow', + ` (retry x${test._currentRetry})` + ); + return retryFmt; + } else { + return ''; + } + } var fmt; if (test.speed === 'fast') { fmt = indent() + color('checkmark', ' ' + Base.symbols.ok) + color('pass', ' %s'); - Base.consoleLog(fmt, test.title); + Base.consoleLog(fmt, test.title, logRetries()); } else { fmt = indent() + color('checkmark', ' ' + Base.symbols.ok) + color('pass', ' %s') + color(test.speed, ' (%dms)'); - Base.consoleLog(fmt, test.title, test.duration); + Base.consoleLog(fmt, test.title, test.duration, logRetries()); } }); - runner.on(EVENT_TEST_FAIL, function (test) { + runner.on(EVENT_TEST_FAIL, function(test) { Base.consoleLog(indent() + color('fail', ' %d) %s'), ++n, test.title); }); diff --git a/test/integration/retries.spec.js b/test/integration/retries.spec.js index a9cb46a42c..97302b416d 100644 --- a/test/integration/retries.spec.js +++ b/test/integration/retries.spec.js @@ -6,12 +6,12 @@ var runJSON = helpers.runMochaJSON; var args = []; var bang = require('../../lib/reporters/base').symbols.bang; -describe('retries', function () { - it('are ran in correct order', function (done) { +describe('retries', function() { + it('are ran in correct order', function(done) { helpers.runMocha( 'retries/hooks.fixture.js', ['--reporter', 'dot'], - function (err, res) { + function(err, res) { var lines, expected; if (err) { @@ -21,10 +21,10 @@ describe('retries', function () { lines = res.output .split(helpers.SPLIT_DOT_REPORTER_REGEXP) - .map(function (line) { + .map(function(line) { return line.trim(); }) - .filter(function (line) { + .filter(function(line) { return line.length; }) .slice(0, -1); @@ -49,7 +49,7 @@ describe('retries', function () { 'after' ]; - expected.forEach(function (line, i) { + expected.forEach(function(line, i) { assert.strictEqual(lines[i], line); }); @@ -59,8 +59,8 @@ describe('retries', function () { ); }); - it('should exit early if test passes', function (done) { - runJSON('retries/early-pass.fixture.js', args, function (err, res) { + it('should exit early if test passes', function(done) { + runJSON('retries/early-pass.fixture.js', args, function(err, res) { if (err) { return done(err); } @@ -74,8 +74,8 @@ describe('retries', function () { }); }); - it('should let test override', function (done) { - runJSON('retries/nested.fixture.js', args, function (err, res) { + it('should let test override', function(done) { + runJSON('retries/nested.fixture.js', args, function(err, res) { if (err) { done(err); return; @@ -89,11 +89,11 @@ describe('retries', function () { }); }); - it('should not hang w/ async test', function (done) { + it('should not hang w/ async test', function(done) { helpers.runMocha( 'retries/async.fixture.js', ['--reporter', 'dot'], - function (err, res) { + function(err, res) { var lines, expected; if (err) { @@ -103,10 +103,10 @@ describe('retries', function () { lines = res.output .split(helpers.SPLIT_DOT_REPORTER_REGEXP) - .map(function (line) { + .map(function(line) { return line.trim(); }) - .filter(function (line) { + .filter(function(line) { return line.length; }) .slice(0, -1); @@ -125,7 +125,7 @@ describe('retries', function () { 'after' ]; - expected.forEach(function (line, i) { + expected.forEach(function(line, i) { assert.strictEqual(lines[i], line); }); @@ -134,4 +134,37 @@ describe('retries', function () { } ); }); + + it('should return current retry count out of total retry count', function(done) { + helpers.runMocha( + 'retries/early-pass.fixture.js', + ['--reporter', 'spec'], + function(err, res) { + var lines, expected; + + if (err) { + done(err); + return; + } + + lines = res.output + .split(helpers.SPLIT_DOT_REPORTER_REGEXP) + .map(function(line) { + return line.trim(); + }) + .filter(function(line) { + return line.length; + }) + .slice(0, -1); + + var retryPattern = /\(retry x\d+\)/; + + var actual = lines[1].match(retryPattern)[0]; + var expected = '(retry x1)'; + + assert.equal(actual, expected); + done(); + } + ); + }); }); diff --git a/test/reporters/spec.spec.js b/test/reporters/spec.spec.js index 39115ffa35..55c168c179 100644 --- a/test/reporters/spec.spec.js +++ b/test/reporters/spec.spec.js @@ -15,22 +15,22 @@ var EVENT_TEST_FAIL = events.EVENT_TEST_FAIL; var EVENT_TEST_PASS = events.EVENT_TEST_PASS; var EVENT_TEST_PENDING = events.EVENT_TEST_PENDING; -describe('Spec reporter', function () { +describe('Spec reporter', function() { var runReporter = makeRunReporter(Spec); var expectedTitle = 'expectedTitle'; - var noop = function () {}; + var noop = function() { }; - beforeEach(function () { + beforeEach(function() { sinon.stub(Base, 'useColors').value(false); }); - afterEach(function () { + afterEach(function() { sinon.restore(); }); - describe('event handlers', function () { - describe("on 'suite' event", function () { - it('should return title', function () { + describe('event handlers', function() { + describe("on 'suite' event", function() { + it('should return title', function() { var suite = { title: expectedTitle }; @@ -42,7 +42,7 @@ describe('Spec reporter', function () { suite ); var options = {}; - var stdout = runReporter({epilogue: noop}, runner, options); + var stdout = runReporter({ epilogue: noop }, runner, options); sinon.restore(); var expectedArray = [expectedTitle + '\n']; @@ -50,8 +50,8 @@ describe('Spec reporter', function () { }); }); - describe("on 'pending' event", function () { - it('should return title', function () { + describe("on 'pending' event", function() { + it('should return title', function() { var suite = { title: expectedTitle }; @@ -63,7 +63,7 @@ describe('Spec reporter', function () { suite ); var options = {}; - var stdout = runReporter({epilogue: noop}, runner, options); + var stdout = runReporter({ epilogue: noop }, runner, options); sinon.restore(); var expectedArray = [' - ' + expectedTitle + '\n']; @@ -71,14 +71,14 @@ describe('Spec reporter', function () { }); }); - describe("on 'pass' event", function () { - describe('when test speed is slow', function () { - it('should return expected tick, title, and duration', function () { + describe("on 'pass' event", function() { + describe('when test speed is slow', function() { + it('should return expected tick, title, and duration', function() { var expectedDuration = 2; var test = { title: expectedTitle, duration: expectedDuration, - slow: function () { + slow: function() { return 1; } }; @@ -90,7 +90,7 @@ describe('Spec reporter', function () { test ); var options = {}; - var stdout = runReporter({epilogue: noop}, runner, options); + var stdout = runReporter({ epilogue: noop }, runner, options); sinon.restore(); var expectedString = @@ -101,18 +101,18 @@ describe('Spec reporter', function () { ' (' + expectedDuration + 'ms)' + - '\n'; + ' \n'; expect(stdout[0], 'to be', expectedString); }); }); - describe('when test speed is fast', function () { - it('should return expected tick, title without a duration', function () { + describe('when test speed is fast', function() { + it('should return expected tick, title without a duration', function() { var expectedDuration = 1; var test = { title: expectedTitle, duration: expectedDuration, - slow: function () { + slow: function() { return 2; } }; @@ -124,18 +124,18 @@ describe('Spec reporter', function () { test ); var options = {}; - var stdout = runReporter({epilogue: noop}, runner, options); + var stdout = runReporter({ epilogue: noop }, runner, options); sinon.restore(); var expectedString = - ' ' + Base.symbols.ok + ' ' + expectedTitle + '\n'; + ' ' + Base.symbols.ok + ' ' + expectedTitle + ' \n'; expect(stdout[0], 'to be', expectedString); }); }); }); - describe("on 'fail' event", function () { - it('should return title and function count', function () { + describe("on 'fail' event", function() { + it('should return title and function count', function() { var functionCount = 1; var test = { title: expectedTitle @@ -148,7 +148,7 @@ describe('Spec reporter', function () { test ); var options = {}; - var stdout = runReporter({epilogue: noop}, runner, options); + var stdout = runReporter({ epilogue: noop }, runner, options); sinon.restore(); var expectedArray = [