Skip to content

Commit

Permalink
Ensure t.try() assigns unique titles when multiple implementations ar…
Browse files Browse the repository at this point in the history
…e passed
  • Loading branch information
novemberborn committed Feb 16, 2020
1 parent 7ee3a0e commit 55a3649
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class ExecutionContext extends assert.Assertions {
throw new TypeError('Expected an implementation.');
}

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

if (!isSet || isEmpty) {
title = `${test.title} ─ attempt ${test.attemptCount + 1}`;
title = `${test.title} ─ attempt ${test.attemptCount + 1 + index}`;
} else if (isValid) {
title = `${test.title}${title}`;
} else {
Expand Down
22 changes: 16 additions & 6 deletions test/helper/ava-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ const Test = require('../../lib/test');
const ContextRef = require('../../lib/context-ref');

function withExperiments(experiments = {}) {
function ava(fn, contextRef) {
const uniqueTestTitles = new Set();
const registerUniqueTitle = title => {
if (uniqueTestTitles.has(title)) {
return false;
}

uniqueTestTitles.add(title);
return true;
};

function ava(fn, contextRef, title = 'test') {
return new Test({
contextRef: contextRef || new ContextRef(),
experiments,
failWithoutAssertions: true,
fn,
registerUniqueTitle: () => true,
registerUniqueTitle,
metadata: {type: 'test', callback: false},
title: 'test'
title
});
}

Expand All @@ -20,7 +30,7 @@ function withExperiments(experiments = {}) {
experiments,
failWithoutAssertions: true,
fn,
registerUniqueTitle: () => true,
registerUniqueTitle,
metadata: {type: 'test', callback: false, failing: true},
title: 'test.failing'
});
Expand All @@ -32,7 +42,7 @@ function withExperiments(experiments = {}) {
experiments,
failWithoutAssertions: true,
fn,
registerUniqueTitle: () => true,
registerUniqueTitle,
metadata: {type: 'test', callback: true},
title: 'test.cb'
});
Expand All @@ -44,7 +54,7 @@ function withExperiments(experiments = {}) {
experiments,
failWithoutAssertions: true,
fn,
registerUniqueTitle: () => true,
registerUniqueTitle,
metadata: {type: 'test', callback: true, failing: true},
title: 'test.cb.failing'
});
Expand Down

0 comments on commit 55a3649

Please sign in to comment.