Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(assert): Add default name for no test name. #27

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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