1 | 'use strict'
|
2 | const typeOf = arg =>
|
3 | typeof arg === 'object' ? (arg ? 'object' : 'null')
|
4 | : typeof arg
|
5 |
|
6 | module.exports = (name_, extra_, cb_, defaultName) => {
|
7 | let name
|
8 | let extra
|
9 | let cb
|
10 |
|
11 | const args = [name_, extra_, cb_]
|
12 |
|
13 |
|
14 |
|
15 | defaultName = defaultName || ''
|
16 |
|
17 | for (let i = 0; i < 3 && i < args.length; i++) {
|
18 | const arg = args[i]
|
19 | const type = typeOf(arg)
|
20 | if (name === undefined && (type === 'string' || type === 'number'))
|
21 | name = '' + arg
|
22 | else if (type === 'object') {
|
23 | extra = arg
|
24 | if (name === undefined)
|
25 | name = null
|
26 | } else if (type === 'function') {
|
27 | if (extra === undefined)
|
28 | extra = {}
|
29 | if (name === undefined)
|
30 | name = null
|
31 | cb = arg
|
32 | } else if (arg === false) {
|
33 |
|
34 |
|
35 | continue
|
36 | } else if (type !== 'undefined')
|
37 | throw new TypeError('unknown argument passed to parseTestArgs: ' + type)
|
38 | }
|
39 |
|
40 | if (!extra)
|
41 | extra = {}
|
42 |
|
43 | if (!cb && defaultName !== '/dev/stdin')
|
44 | extra.todo = extra.todo || true
|
45 |
|
46 | if (!name && extra.name)
|
47 | name = extra.name
|
48 |
|
49 | if (!name && cb && cb.name)
|
50 | name = cb.name
|
51 |
|
52 | name = name || defaultName
|
53 | extra.name = name
|
54 | extra.cb = cb || todoCb
|
55 | return extra
|
56 | }
|
57 |
|
58 | const todoCb = () => {
|
59 | throw new Error('callback called for TODO test')
|
60 | }
|