Skip to content

Commit

Permalink
Merge 6cce26d into d814dca
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed May 20, 2016
2 parents d814dca + 6cce26d commit c938b4c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,18 @@ RunStatus.prototype.prefixTitle = function (file) {
var separator = ' ' + chalk.gray.dim(figures.pointerSmall) + ' ';

var prefix = path.relative('.', file)
.replace(this.base, '')
.replace(this.base, function (match, offset) {
// only replace this.base if it is found at the start of the path
return offset === 0 ? '' : match;
})
.replace(/\.spec/, '')
.replace(/\.test/, '')
.replace(/test\-/g, '')
.replace(/\.js$/, '')
.split(path.sep)
.filter(function (p) {
return p !== '__tests__';
})
.join(separator);

if (prefix.length > 0) {
Expand Down
69 changes: 69 additions & 0 deletions test/run-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';
var test = require('tap').test;
var chalk = require('chalk');
var figures = require('figures');
var RunStatus = require('../lib/run-status');

var sep = ' ' + chalk.gray.dim(figures.pointerSmall) + ' ';

test('requires new', function (t) {
var runStatus = RunStatus;
t.throws(function () {
runStatus({});
}, 'Class constructor RunStatus cannot be invoked without \'new\'');
t.end();
});

test('prefixTitle returns empty if prefixTitles == false', function (t) {
var runStatus = new RunStatus({prefixTitles: false});
t.is(runStatus.prefixTitle('test/run-status.js'), '');
t.end();
});

test('prefixTitle removes base if found at start of path', function (t) {
var runStatus = new RunStatus({base: 'test/'});
t.is(runStatus.prefixTitle('test/run-status.js'), 'run-status' + sep);
t.end();
});

test('prefixTitle does not remove base if found but not at start of path', function (t) {
var runStatus = new RunStatus({base: '/'});
t.is(runStatus.prefixTitle('test/run-status.js'), 'test' + sep + 'run-status' + sep);
t.end();
});

test('prefixTitle removes .js extension', function (t) {
var runStatus = new RunStatus({base: ''});
t.is(runStatus.prefixTitle('run-status.js'), 'run-status' + sep);
t.end();
});

test('prefixTitle does not remove .js from middle of path', function (t) {
var runStatus = new RunStatus({base: ''});
t.is(runStatus.prefixTitle('run-.js-status.js'), 'run-.js-status' + sep);
t.end();
});

test('prefixTitle removes __tests__ from path', function (t) {
var runStatus = new RunStatus({base: ''});
t.is(runStatus.prefixTitle('backend/__tests__/run-status.js'), 'backend' + sep + 'run-status' + sep);
t.end();
});

test('prefixTitle removes .spec from path', function (t) {
var runStatus = new RunStatus({base: ''});
t.is(runStatus.prefixTitle('backend/run-status.spec.js'), 'backend' + sep + 'run-status' + sep);
t.end();
});

test('prefixTitle removes .test from path', function (t) {
var runStatus = new RunStatus({base: ''});
t.is(runStatus.prefixTitle('backend/run-status.test.js'), 'backend' + sep + 'run-status' + sep);
t.end();
});

test('prefixTitle removes test- from path', function (t) {
var runStatus = new RunStatus({base: ''});
t.is(runStatus.prefixTitle('backend/test-run-status.js'), 'backend' + sep + 'run-status' + sep);
t.end();
});

0 comments on commit c938b4c

Please sign in to comment.