forked from NickTomlin/protractor-flake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (39 loc) · 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import cucumber from './cucumber'
import { resolve, extname } from 'path'
import multi from './multi'
import standard from './standard'
let all = { cucumber, multi, standard }
function handleObject (parserObject) {
if (typeof parserObject.parse !== 'function') {
throw new Error(`Invalid Parser Object specified. Your parser must define a \`parse\` method`)
}
return parserObject
}
function handlePath (parserPath) {
// 'my-custom-parser' or './my-custom-parser'
try {
return require(parserPath)
} catch (e) {}
// /path/to/parser or ../path/to/parser
try {
return require(resolve(parserPath))
} catch (e) {}
throw new Error(`Invalid Custom Parser Path Specified: ${parserPath}`)
}
function handleFlakeParser (parserName) {
if (all[parserName]) {
return all[parserName]
} else {
throw new Error(`Invalid Parser Specified: ${parserName}`)
}
}
function getParser (parser = '') {
if (parser.hasOwnProperty('parse')) {
return handleObject(parser)
}
if (extname(parser)) {
return handlePath(parser)
}
return handleFlakeParser(parser)
}
export default { all, getParser }