-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
index.ts
85 lines (80 loc) · 2.05 KB
/
index.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import debug from 'debug'
import { ArgvParser } from '../configuration'
import { IFormatterStream } from '../formatter'
import { loadConfiguration, runCucumber } from '../api'
import { getKeywords, getLanguages } from './i18n'
import { validateInstall } from './install_validator'
export interface ICliRunResult {
shouldExitImmediately: boolean
success: boolean
}
export default class Cli {
private readonly argv: string[]
private readonly cwd: string
private readonly stdout: IFormatterStream
private readonly stderr: IFormatterStream
private readonly env: NodeJS.ProcessEnv
constructor({
argv,
cwd,
stdout,
stderr = process.stderr,
env,
}: {
argv: string[]
cwd: string
stdout: IFormatterStream
stderr?: IFormatterStream
env: NodeJS.ProcessEnv
}) {
this.argv = argv
this.cwd = cwd
this.stdout = stdout
this.stderr = stderr
this.env = env
}
async run(): Promise<ICliRunResult> {
const debugEnabled = debug.enabled('cucumber')
if (debugEnabled) {
await validateInstall()
}
const { options, configuration: argvConfiguration } = ArgvParser.parse(
this.argv
)
if (options.i18nLanguages) {
this.stdout.write(getLanguages())
return {
shouldExitImmediately: true,
success: true,
}
}
if (options.i18nKeywords) {
this.stdout.write(getKeywords(options.i18nKeywords))
return {
shouldExitImmediately: true,
success: true,
}
}
const environment = {
cwd: this.cwd,
stdout: this.stdout,
stderr: this.stderr,
env: this.env,
debug: debugEnabled,
}
const { useConfiguration: configuration, runConfiguration } =
await loadConfiguration(
{
file: options.config,
profiles: options.profile,
provided: argvConfiguration,
},
environment
)
const { success } = await runCucumber(runConfiguration, environment)
return {
shouldExitImmediately: configuration.forceExit,
success,
}
}
}