diff --git a/index.js b/index.js index fde199a..c0c0033 100644 --- a/index.js +++ b/index.js @@ -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(); @@ -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) @@ -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;