Skip to content

Commit

Permalink
feat(title): include index and times in full title, close #1
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Aug 10, 2017
1 parent 2f47bfd commit 9f3acb7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ output:

```
repeat-it
✓ 1 repeated test
✓ 2 repeated test
✓ 3 repeated test
✓ 4 repeated test
✓ 5 repeated test
✓ 6 repeated test
✓ 7 repeated test
✓ 8 repeated test
✓ 9 repeated test
✓ 10 repeated test
✓ 1/10 repeated test
✓ 2/10 repeated test
✓ 3/10 repeated test
✓ 4/10 repeated test
✓ 5/10 repeated test
✓ 6/10 repeated test
✓ 7/10 repeated test
✓ 8/10 repeated test
✓ 9/10 repeated test
✓ 10/10 repeated test
10 passing (10ms)
```
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ function checkTimes (times) {
console.assert(isNonNegative(times), 'repeat times should be non-negative')
}

function formatMessage (title, times) {
return function finishFormat (k) {
return k + 1 + '/' + times + ' ' + title
}
}

function only (times) {
if (!isNumber(times)) {
// probably plain it('name', ...) call
Expand All @@ -31,8 +37,9 @@ function only (times) {

return function (title, fn) {
let k
const fullTitle = formatMessage(title, times)
for (k = 0; k < times; k += 1) {
oldIt.only(k + 1 + ' ' + title, fn)
oldIt.only(fullTitle(k), fn)
}
}
}
Expand All @@ -47,8 +54,9 @@ function repeatIt (times) {

return function (title, fn) {
let k
const fullTitle = formatMessage(title, times)
for (k = 0; k < times; k += 1) {
oldIt(k + 1 + ' ' + title, fn)
oldIt(fullTitle(k), fn)
}
}
}
Expand Down

0 comments on commit 9f3acb7

Please sign in to comment.