Skip to content

Commit

Permalink
fix(assert): Add default name for no test name.
Browse files Browse the repository at this point in the history
 * Add `DEFAULT_TEST_NAME`.
 * Ensure `res.name` has a value or use `DEFAULT_TEST_NAME`.
  • Loading branch information
alvaropinot authored and ljharb committed May 25, 2018
1 parent f88d449 commit 825fff7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var regexTester = require('safe-regex-test');
var isPassing = regexTester(/^(tests|pass)\s+\d+$/);
var isFailing = regexTester(/^fail\s+\d+$/);

var DEFAULT_TEST_NAME = 'test';

module.exports = function (opts) {
var tap = parser();
var out = through2();
Expand Down Expand Up @@ -58,8 +60,10 @@ module.exports = function (opts) {
var ok = res.ok ? 'ok' : 'not ok';
var c = res.ok ? 32 : 31;
if (!test) {
// Whenenver there is no test name, provide a default one.
var name = res.name || DEFAULT_TEST_NAME;
// mocha produces TAP results this way, whatever
var s = trimWidth(trim(res.name));
var s = trimWidth(trim(name));
push(out, sprintf(
'\x1b[1m\x1b[' + c + 'm%s\x1b[0m\n',
trimWidth((res.ok ? '✓' : '⨯') + ' ' + s, res.ok)
Expand All @@ -68,7 +72,7 @@ module.exports = function (opts) {
}

var fmt = '\r %s \x1b[1m\x1b[' + c + 'm%d\x1b[0m %s\x1b[K';
var str = sprintf(fmt, ok, res.number, trimWidth(res.name, res.ok));
var str = sprintf(fmt, ok, res.number, trimWidth(name, res.ok));

if (!res.ok) {
var y = ++test.offset + 1;
Expand Down

0 comments on commit 825fff7

Please sign in to comment.