Skip to content

Commit 55a3649

Browse files
committed
Ensure t.try() assigns unique titles when multiple implementations are passed
1 parent 7ee3a0e commit 55a3649

File tree

3 files changed

+81
-16
lines changed

3 files changed

+81
-16
lines changed

lib/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ class ExecutionContext extends assert.Assertions {
7979
throw new TypeError('Expected an implementation.');
8080
}
8181

82-
const attemptPromises = implementations.map(implementation => {
82+
const attemptPromises = implementations.map((implementation, index) => {
8383
let {title, isSet, isValid, isEmpty} = buildTitle(implementation);
8484

8585
if (!isSet || isEmpty) {
86-
title = `${test.title} ─ attempt ${test.attemptCount + 1}`;
86+
title = `${test.title} ─ attempt ${test.attemptCount + 1 + index}`;
8787
} else if (isValid) {
8888
title = `${test.title}${title}`;
8989
} else {

test/helper/ava-test.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@ const Test = require('../../lib/test');
22
const ContextRef = require('../../lib/context-ref');
33

44
function withExperiments(experiments = {}) {
5-
function ava(fn, contextRef) {
5+
const uniqueTestTitles = new Set();
6+
const registerUniqueTitle = title => {
7+
if (uniqueTestTitles.has(title)) {
8+
return false;
9+
}
10+
11+
uniqueTestTitles.add(title);
12+
return true;
13+
};
14+
15+
function ava(fn, contextRef, title = 'test') {
616
return new Test({
717
contextRef: contextRef || new ContextRef(),
818
experiments,
919
failWithoutAssertions: true,
1020
fn,
11-
registerUniqueTitle: () => true,
21+
registerUniqueTitle,
1222
metadata: {type: 'test', callback: false},
13-
title: 'test'
23+
title
1424
});
1525
}
1626

@@ -20,7 +30,7 @@ function withExperiments(experiments = {}) {
2030
experiments,
2131
failWithoutAssertions: true,
2232
fn,
23-
registerUniqueTitle: () => true,
33+
registerUniqueTitle,
2434
metadata: {type: 'test', callback: false, failing: true},
2535
title: 'test.failing'
2636
});
@@ -32,7 +42,7 @@ function withExperiments(experiments = {}) {
3242
experiments,
3343
failWithoutAssertions: true,
3444
fn,
35-
registerUniqueTitle: () => true,
45+
registerUniqueTitle,
3646
metadata: {type: 'test', callback: true},
3747
title: 'test.cb'
3848
});
@@ -44,7 +54,7 @@ function withExperiments(experiments = {}) {
4454
experiments,
4555
failWithoutAssertions: true,
4656
fn,
47-
registerUniqueTitle: () => true,
57+
registerUniqueTitle,
4858
metadata: {type: 'test', callback: true, failing: true},
4959
title: 'test.cb.failing'
5060
});

0 commit comments

Comments
 (0)