|
1 | 1 | import { serializeArg } from './serialize.js' |
2 | 2 |
|
3 | | -// Retrieve unique test titles for each iteration. |
| 3 | +// Retrieve unique test names for each iteration. |
4 | 4 | // To customize names inside a specific iterable, add `name` properties to it, |
5 | 5 | // for example with `Array.map()`. |
6 | | -// To customize whole titles, generate them inside the iterated function using |
| 6 | +// To customize whole names, generate them inside the iterated function using |
7 | 7 | // all values. |
8 | 8 | export const getNames = function(args) { |
9 | | - return args.map(getTitle).map(fixDuplicate) |
| 9 | + return args.map(getName).map(fixDuplicate) |
10 | 10 | } |
11 | 11 |
|
12 | | -const getTitle = function(args) { |
13 | | - return args.map(getName).join(' ') |
| 12 | +const getName = function(args) { |
| 13 | + const argNames = args.map(getArgName) |
| 14 | + const name = argNames.join(' ') |
| 15 | + return name |
14 | 16 | } |
15 | 17 |
|
16 | | -const getName = function(arg) { |
17 | | - const name = serializeArg(arg) |
18 | | - const nameA = name.trim() |
19 | | - const nameB = truncateName(nameA) |
20 | | - return nameB |
| 18 | +const getArgName = function(arg) { |
| 19 | + const argName = serializeArg(arg) |
| 20 | + const argNameA = argName.trim() |
| 21 | + const argNameB = truncateName(argNameA) |
| 22 | + return argNameB |
21 | 23 | } |
22 | 24 |
|
23 | 25 | // Make names short by truncating them |
24 | | -const truncateName = function(name) { |
25 | | - if (name.length <= MAX_NAME_LENGTH) { |
26 | | - return name |
| 26 | +const truncateName = function(argName) { |
| 27 | + if (argName.length <= MAX_NAME_LENGTH) { |
| 28 | + return argName |
27 | 29 | } |
28 | 30 |
|
29 | | - const nameA = name.slice(0, MAX_NAME_LENGTH) |
30 | | - return `${nameA}...` |
| 31 | + const argNameA = argName.slice(0, MAX_NAME_LENGTH) |
| 32 | + return `${argNameA}...` |
31 | 33 | } |
32 | 34 |
|
33 | 35 | const MAX_NAME_LENGTH = 60 |
34 | 36 |
|
35 | | -// Ensure titles are unique by appending the index when we find duplicates |
36 | | -const fixDuplicate = function(title, index, titles) { |
37 | | - if (!isDuplicate(title, index, titles)) { |
38 | | - return title |
| 37 | +// Ensure names are unique by appending the index when we find duplicates |
| 38 | +const fixDuplicate = function(name, index, names) { |
| 39 | + if (!isDuplicate(name, index, names)) { |
| 40 | + return name |
39 | 41 | } |
40 | 42 |
|
41 | | - return `${title} (${index})` |
| 43 | + return `${name} (${index})` |
42 | 44 | } |
43 | 45 |
|
44 | | -const isDuplicate = function(title, index, titles) { |
45 | | - return titles.some((titleA, indexA) => titleA === title && index !== indexA) |
| 46 | +const isDuplicate = function(name, index, names) { |
| 47 | + return names.some((nameA, indexA) => nameA === name && index !== indexA) |
46 | 48 | } |
0 commit comments