From 7ee3a0e5940a105dec447851c777ea44555e8220 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sun, 9 Feb 2020 17:20:39 +0100 Subject: [PATCH] Prefix attempt titles with that of parent test Since titles must be unique throughout the test file, it's easier if attempt titles are always prefixed with the already unique title of the parent test. --- lib/test.js | 6 ++++-- test/test-try-commit.js | 14 +++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/test.js b/lib/test.js index 02d68e940..441ef4e61 100644 --- a/lib/test.js +++ b/lib/test.js @@ -83,8 +83,10 @@ class ExecutionContext extends assert.Assertions { let {title, isSet, isValid, isEmpty} = buildTitle(implementation); if (!isSet || isEmpty) { - title = `${test.title} (attempt ${test.attemptCount + 1})`; - } else if (!isValid) { + title = `${test.title} ─ attempt ${test.attemptCount + 1}`; + } else if (isValid) { + title = `${test.title} ─ ${title}`; + } else { throw new TypeError('`t.try()` titles must be strings'); // Throw synchronously! } diff --git a/test/test-try-commit.js b/test/test-try-commit.js index a163220c5..2ba492cc4 100644 --- a/test/test-try-commit.js +++ b/test/test-try-commit.js @@ -209,15 +209,15 @@ test('try-commit has proper titles, when going in depth and width', async t => { await Promise.all([ a.try(async b => { - t.is(b.title, 'test (attempt 1)'); + t.is(b.title, 'test ─ attempt 1'); await Promise.all([ - b.try(c => t.is(c.title, 'test (attempt 1) (attempt 1)')), - b.try(c => t.is(c.title, 'test (attempt 1) (attempt 2)')) + b.try(c => t.is(c.title, 'test ─ attempt 1 ─ attempt 1')), + b.try(c => t.is(c.title, 'test ─ attempt 1 ─ attempt 2')) ]); }), - a.try(b => t.is(b.title, 'test (attempt 2)')), - a.try(b => t.is(b.title, 'test (attempt 3)')) + a.try(b => t.is(b.title, 'test ─ attempt 2')), + a.try(b => t.is(b.title, 'test ─ attempt 3')) ]); }).run(); }); @@ -404,11 +404,11 @@ test('try-commit does not allow to use .end() in attempt when parent is regular test('try-commit accepts macros', async t => { const macro = b => { - t.is(b.title, ' Title'); + t.is(b.title, 'test ─ Title'); b.pass(); }; - macro.title = providedTitle => `${providedTitle ? providedTitle : ''} Title`; + macro.title = (providedTitle = '') => `${providedTitle} Title`.trim(); const result = await ava(async a => { const res = await a.try(macro);