-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathbefore_after_all_hooks_context.feature
112 lines (94 loc) · 2.64 KB
/
before_after_all_hooks_context.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
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
Feature: Before/After All Hooks Context
It should be possible to preserve context from a BeforeAll hook
and have the context be available to the scenarios in the World
Background:
Given a file named "cucumber.json" with:
"""
{
"default": {
"worldParameters": {
"widgets": true
}
}
}
"""
And a file named "features/a.feature" with:
"""
Feature: some feature
Scenario: first scenario
Given first step
Scenario: second scenario
Given second step
"""
Scenario: BeforeAll hooks can update world parameters before tests start
Given a file named "features/support/hooks.js" with:
"""
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber')
const {expect} = require('chai')
BeforeAll(function() {
expect(this.parameters).to.deep.eq({
widgets: true
})
this.parameters.foo = 1
})
Given('first step', function() {
expect(this.parameters).to.deep.eq({
widgets: true,
foo: 1
})
})
Given('second step', function() {
expect(this.parameters).to.deep.eq({
widgets: true,
foo: 1
})
})
AfterAll(function() {
expect(this.parameters).to.deep.eq({
widgets: true,
foo: 1
})
})
"""
When I run cucumber-js
Then it passes
Scenario: Many BeforeAll hooks can accumulate updates to the world parameters
Given a file named "features/support/hooks.js" with:
"""
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber')
const {expect} = require('chai')
BeforeAll(function() {
this.parameters.foo = 1
})
BeforeAll(function() {
this.parameters.bar = 2
})
Given('first step', function() {
expect(this.parameters).to.deep.eq({
widgets: true,
foo: 1,
bar: 2
})
})
Given('second step', function() {})
"""
When I run cucumber-js
Then it passes
Scenario: Works the same way on the parallel runtime
Given a file named "features/support/hooks.js" with:
"""
const {AfterAll, BeforeAll, Given} = require('@cucumber/cucumber')
const {expect} = require('chai')
BeforeAll(function() {
this.parameters.foo = 1
})
Given('first step', function() {
expect(this.parameters).to.deep.eq({
widgets: true,
foo: 1
})
})
Given('second step', function() {})
"""
When I run cucumber-js with `--parallel 2`
Then it passes