Skip to content

Commit

Permalink
Prefix attempt titles with that of parent test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
novemberborn committed Feb 16, 2020
1 parent a69e4f2 commit 7ee3a0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions lib/test.js
Expand Up @@ -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!
}

Expand Down
14 changes: 7 additions & 7 deletions test/test-try-commit.js
Expand Up @@ -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 1attempt 1')),
b.try(c => t.is(c.title, 'test attempt 1attempt 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();
});
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7ee3a0e

Please sign in to comment.