Skip to content

Commit 7ee3a0e

Browse files
committedFeb 16, 2020
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.
1 parent a69e4f2 commit 7ee3a0e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed
 

‎lib/test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ class ExecutionContext extends assert.Assertions {
8383
let {title, isSet, isValid, isEmpty} = buildTitle(implementation);
8484

8585
if (!isSet || isEmpty) {
86-
title = `${test.title} (attempt ${test.attemptCount + 1})`;
87-
} else if (!isValid) {
86+
title = `${test.title} ─ attempt ${test.attemptCount + 1}`;
87+
} else if (isValid) {
88+
title = `${test.title}${title}`;
89+
} else {
8890
throw new TypeError('`t.try()` titles must be strings'); // Throw synchronously!
8991
}
9092

‎test/test-try-commit.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ test('try-commit has proper titles, when going in depth and width', async t => {
209209

210210
await Promise.all([
211211
a.try(async b => {
212-
t.is(b.title, 'test (attempt 1)');
212+
t.is(b.title, 'test attempt 1');
213213

214214
await Promise.all([
215-
b.try(c => t.is(c.title, 'test (attempt 1) (attempt 1)')),
216-
b.try(c => t.is(c.title, 'test (attempt 1) (attempt 2)'))
215+
b.try(c => t.is(c.title, 'test attempt 1attempt 1')),
216+
b.try(c => t.is(c.title, 'test attempt 1attempt 2'))
217217
]);
218218
}),
219-
a.try(b => t.is(b.title, 'test (attempt 2)')),
220-
a.try(b => t.is(b.title, 'test (attempt 3)'))
219+
a.try(b => t.is(b.title, 'test attempt 2')),
220+
a.try(b => t.is(b.title, 'test attempt 3'))
221221
]);
222222
}).run();
223223
});
@@ -404,11 +404,11 @@ test('try-commit does not allow to use .end() in attempt when parent is regular
404404

405405
test('try-commit accepts macros', async t => {
406406
const macro = b => {
407-
t.is(b.title, ' Title');
407+
t.is(b.title, 'test ─ Title');
408408
b.pass();
409409
};
410410

411-
macro.title = providedTitle => `${providedTitle ? providedTitle : ''} Title`;
411+
macro.title = (providedTitle = '') => `${providedTitle} Title`.trim();
412412

413413
const result = await ava(async a => {
414414
const res = await a.try(macro);

0 commit comments

Comments
 (0)
Please sign in to comment.