Skip to content

Commit af57600

Browse files
committed
Pass name as a named parameter in test-each
1 parent 542ad20 commit af57600

File tree

9 files changed

+27
-21
lines changed

9 files changed

+27
-21
lines changed

test/echo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { METHODS } from './helpers/methods.js'
77
testEach(
88
METHODS,
99
[{ opts: { echo: false } }, { opts: { echo: true } }],
10-
(title, methodProps, data) =>
11-
test(`'echo' option | ${title}`, t =>
10+
({ name }, methodProps, data) =>
11+
test(`'echo' option | ${name}`, t =>
1212
snapshotTest({ t, methodProps, data })),
1313
)

test/exec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { testEach } from './helpers/test_each/main.js'
44
import { snapshotTest } from './helpers/snapshot.js'
55
import { EXEC_METHODS } from './helpers/methods.js'
66

7-
testEach(EXEC_METHODS, [{}], (title, methodProps, data) =>
8-
test(`exec() | ${title}`, t => snapshotTest({ t, methodProps, data })),
7+
testEach(EXEC_METHODS, [{}], ({ name }, methodProps, data) =>
8+
test(`exec() | ${name}`, t => snapshotTest({ t, methodProps, data })),
99
)

test/helpers/test_each/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export const testEach = function(...inputArgs) {
1111

1212
const names = getNames(args)
1313

14-
const results = args.map((values, index) => func(names[index], ...values))
14+
const results = args.map((values, index) => {
15+
const name = names[index]
16+
return func({ name }, ...values)
17+
})
1518

1619
// Can use `Promise.all(results)` if `func` is async
1720
return { args, results }

test/helpers/test_each/serialize.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { inspect } from 'util'
22

33
import { isPlainObject } from './utils.js'
44

5-
// Serialize an argument so it can be used in the title
5+
// Serialize an argument so it can be used in the names
66
export const serializeArg = function(arg) {
77
if (hasName(arg)) {
88
return arg.name
@@ -34,7 +34,7 @@ const serializeFunction = function(func) {
3434
return func.name
3535
}
3636

37-
// Make title short and on a single line
37+
// Make names short and on a single line
3838
const INSPECT_OPTS = {
3939
breakLength: Infinity,
4040
depth: 1,

test/input.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { METHODS } from './helpers/methods.js'
77
testEach(
88
METHODS,
99
[{ command: true }, { command: ' ' }],
10-
(title, methodProps, data) =>
11-
test(`Invalid command | ${title}`, t =>
10+
({ name }, methodProps, data) =>
11+
test(`Invalid command | ${name}`, t =>
1212
snapshotTest({ t, methodProps, data })),
1313
)
1414

1515
testEach(
1616
METHODS,
1717
[{ opts: { uid: 0.5 } }, { command: 'invalid', read: false }],
18-
(title, methodProps, data) =>
19-
test(`Errored command | ${title}`, t =>
18+
({ name }, methodProps, data) =>
19+
test(`Errored command | ${name}`, t =>
2020
snapshotTest({ t, methodProps, data })),
2121
)

test/options.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ testEach(
3737
{ opts: { result: 'invalid' } },
3838
{ opts: { from: 'invalid' } },
3939
],
40-
(title, methodProps, data) =>
41-
test(`Invalid options | ${title}`, t =>
40+
({ name }, methodProps, data) =>
41+
test(`Invalid options | ${name}`, t =>
4242
snapshotTest({ t, methodProps, data })),
4343
)
4444

45-
testEach(METHODS, [{}, { opts: {} }], (title, methodProps, data) =>
46-
test(`No options | ${title}`, t => snapshotTest({ t, methodProps, data })),
45+
testEach(METHODS, [{}, { opts: {} }], ({ name }, methodProps, data) =>
46+
test(`No options | ${name}`, t => snapshotTest({ t, methodProps, data })),
4747
)

test/stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ testEach(
2020
{ opts: { encoding: 'utf8' } },
2121
{ opts: { stripFinalNewline: true } },
2222
],
23-
(title, methodProps, data) =>
24-
test(`stream() | ${title}`, t => snapshotTest({ t, methodProps, data })),
23+
({ name }, methodProps, data) =>
24+
test(`stream() | ${name}`, t => snapshotTest({ t, methodProps, data })),
2525
)

test/task.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { testEach } from './helpers/test_each/main.js'
44
import { snapshotTest } from './helpers/snapshot.js'
55
import { TASK_METHODS } from './helpers/methods.js'
66

7-
testEach(TASK_METHODS, [{}, { task: 'nested' }], (title, methodProps, data) =>
8-
test(`task() | ${title}`, t => snapshotTest({ t, methodProps, data })),
7+
testEach(
8+
TASK_METHODS,
9+
[{}, { task: 'nested' }],
10+
({ name }, methodProps, data) =>
11+
test(`task() | ${name}`, t => snapshotTest({ t, methodProps, data })),
912
)

test/verbose.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ testEach(
1717
{ opts: { verbose: true, stdio: 'pipe' } },
1818
{ opts: { verbose: true, stdio: 'pipe', stdout: 'pipe', stderr: 'pipe' } },
1919
],
20-
(title, methodProps, data) =>
21-
test(`'verbose' option | ${title}`, t =>
20+
({ name }, methodProps, data) =>
21+
test(`'verbose' option | ${name}`, t =>
2222
snapshotTest({ t, methodProps, data })),
2323
)

0 commit comments

Comments
 (0)