-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
hook_parameter.feature
80 lines (73 loc) · 2.18 KB
/
hook_parameter.feature
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
Feature: Hook Parameters
@spawn
Scenario: before hook parameter
Given a file named "features/my_feature.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given a step
"""
And a file named "features/step_definitions/my_steps.js" with:
"""
import {defineSupportCode} from 'cucumber'
defineSupportCode(({When}) => {
When(/^a step$/, function() {})
})
"""
And a file named "features/support/hooks.js" with:
"""
import {defineSupportCode} from 'cucumber'
defineSupportCode(({Before}) => {
Before(function(testCase) {
console.log(testCase.sourceLocation.uri + ":" + testCase.sourceLocation.line)
})
})
"""
When I run cucumber.js
Then the output contains the text:
"""
features/my_feature.feature:2
"""
@spawn
Scenario: after hook parameter
Given a file named "features/my_feature.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given a passing step
Scenario: another scenario
Given a failing step
"""
And a file named "features/step_definitions/my_steps.js" with:
"""
import {defineSupportCode} from 'cucumber'
defineSupportCode(({When}) => {
When(/^a passing step$/, function() {})
When(/^a failing step$/, function() { throw new Error("my error") })
})
"""
And a file named "features/support/hooks.js" with:
"""
import {defineSupportCode, Status} from 'cucumber'
defineSupportCode(({After}) => {
After(function(testCase) {
let message = testCase.sourceLocation.uri + ":" + testCase.sourceLocation.line + " "
if (testCase.result.status === Status.FAILED) {
message += "failed"
} else {
message += "did not fail"
}
console.log(message)
})
})
"""
When I run cucumber.js
Then it fails
And the output contains the text:
"""
features/my_feature.feature:2 did not fail
"""
And the output contains the text:
"""
features/my_feature.feature:5 failed
"""