From 825fff74759f47dcb4c21c41be4b84ce92f857c4 Mon Sep 17 00:00:00 2001 From: Alvaro Pinot Date: Fri, 25 May 2018 00:19:02 -0400 Subject: [PATCH] fix(assert): Add default name for no test name. * Add `DEFAULT_TEST_NAME`. * Ensure `res.name` has a value or use `DEFAULT_TEST_NAME`. --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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;