-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
cli_steps.ts
112 lines (100 loc) · 3.38 KB
/
cli_steps.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { When, Then, DataTable } from '../../'
import { expect } from 'chai'
import { normalizeText } from '../support/helpers'
import stringArgv from 'string-argv'
import Mustache from 'mustache'
import {
valueOrDefault,
doesNotHaveValue,
doesHaveValue,
} from '../../src/value_checker'
import { World } from '../support/world'
When(
/^I run cucumber-js(?: with `(|.+)`)?$/,
{ timeout: 10000 },
async function(this: World, args: string) {
const renderedArgs = Mustache.render(valueOrDefault(args, ''), this)
const stringArgs = stringArgv(renderedArgs)
return this.run(this.localExecutablePath, stringArgs)
}
)
When(
/^I run cucumber-js with all formatters(?: and `(|.+)`)?$/,
{ timeout: 10000 },
async function(this: World, args: string) {
if (doesNotHaveValue(args)) {
args = ''
}
// message is always outputted as part of run
const formats = ['json:json.out']
args += ' ' + formats.map(f => `--format ${f}`).join(' ')
const renderedArgs = Mustache.render(args, this)
const stringArgs = stringArgv(renderedArgs)
return this.run(this.localExecutablePath, stringArgs)
}
)
When(
/^I run cucumber-js \(installed (locally|globally)\)$/,
{ timeout: 10000 },
async function(this: World, location: string) {
if (location === 'locally') {
return this.run(this.localExecutablePath, [])
}
return this.run(this.globalExecutablePath, [])
}
)
Then(/^it passes$/, () => {}) // eslint-disable-line @typescript-eslint/no-empty-function
Then(/^it fails$/, function(this: World) {
const actualCode = doesHaveValue(this.lastRun.error)
? this.lastRun.error.code
: 0
expect(actualCode).not.to.eql(0)
this.verifiedLastRunError = true
})
Then(/^it outputs the text:$/, function(this: World, text: string) {
const actualOutput = normalizeText(this.lastRun.output)
const expectedOutput = normalizeText(text)
expect(actualOutput).to.eql(expectedOutput)
})
Then(/^the output contains the text:$/, function(this: World, text: string) {
const actualOutput = normalizeText(this.lastRun.output)
const expectedOutput = normalizeText(text)
expect(actualOutput).to.include(expectedOutput)
})
Then('the output does not contain the text:', function(
this: World,
text: string
) {
const actualOutput = normalizeText(this.lastRun.output)
const expectedOutput = normalizeText(text)
expect(actualOutput).not.to.include(expectedOutput)
})
Then(/^the error output contains the text snippets:$/, function(
this: World,
table: DataTable
) {
const actualOutput = normalizeText(this.lastRun.errorOutput)
table.rows().forEach(row => {
const expectedOutput = normalizeText(row[0])
expect(actualOutput).to.include(expectedOutput)
})
})
Then(/^the error output contains the text:$/, function(
this: World,
text: string
) {
const actualOutput = normalizeText(this.lastRun.errorOutput)
const expectedOutput = normalizeText(text)
expect(actualOutput).to.include(expectedOutput)
})
Then(/^I see the version of Cucumber$/, function(this: World) {
const version = require('../../package.json').version
const actualOutput = this.lastRun.output
const expectedOutput = `${version}\n`
expect(actualOutput).to.eql(expectedOutput)
})
Then(/^I see the help text for Cucumber$/, function(this: World) {
const actualOutput = this.lastRun.output
const expectedOutput = 'Usage: cucumber-js'
expect(actualOutput).to.include(expectedOutput)
})