-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathusage_formatter.feature
95 lines (88 loc) · 5.14 KB
/
usage_formatter.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
Feature: usage formatter
As a developer with slow or unused steps
I want a formatter which just outputs the step definition usage
So I know where my bottlenecks are and what step definitions I can remove
Scenario:
Given a file named "features/a.feature" with:
"""
Feature: a feature
Scenario: a scenario
Given step A
When step B
And slow step B
Then step C
"""
And a file named "features/step_definitions/steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When('step A', function(callback) { setTimeout(callback, 100) });
When(/^(slow )?step B$/, function(slow, callback) {
if (slow) {
setTimeout(callback, 100)
} else {
callback()
}
});
When('step C', function(callback) { setTimeout(callback, 10) });
When('step D', function() {});
"""
When I run cucumber-js with `--format usage`
Then it outputs the text:
"""
┌────────────────────┬──────────┬───────────────────────────────────────┐
│ Pattern / Text │ Duration │ Location │
├────────────────────┼──────────┼───────────────────────────────────────┤
│ step A │ <d>ms │ features/step_definitions/steps.js:3 │
│ step A │ <d>ms │ features/a.feature:3 │
├────────────────────┼──────────┼───────────────────────────────────────┤
│ /^(slow )?step B$/ │ <d>ms │ features/step_definitions/steps.js:4 │
│ slow step B │ <d>ms │ features/a.feature:5 │
│ step B │ <d>ms │ features/a.feature:4 │
├────────────────────┼──────────┼───────────────────────────────────────┤
│ step C │ <d>ms │ features/step_definitions/steps.js:11 │
│ step C │ <d>ms │ features/a.feature:6 │
├────────────────────┼──────────┼───────────────────────────────────────┤
│ step D │ UNUSED │ features/step_definitions/steps.js:12 │
└────────────────────┴──────────┴───────────────────────────────────────┘
"""
Scenario: only list 5 slowest matches
Given a file named "features/a.feature" with:
"""
Feature: a feature
Scenario Outline: a scenario
Given slow step
And step
Examples:
| <ID> |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
"""
And a file named "features/step_definitions/steps.js" with:
"""
const {When} = require('@cucumber/cucumber')
When(/^(slow )?step$/, function(slow, callback) {
if (slow) {
setTimeout(callback, 100)
} else {
callback()
}
});
"""
When I run cucumber-js with `--format usage`
Then it outputs the text:
"""
┌──────────────────┬──────────┬──────────────────────────────────────┐
│ Pattern / Text │ Duration │ Location │
├──────────────────┼──────────┼──────────────────────────────────────┤
│ /^(slow )?step$/ │ <d>ms │ features/step_definitions/steps.js:3 │
│ slow step │ <d>ms │ features/a.feature:3 │
│ slow step │ <d>ms │ features/a.feature:3 │
│ slow step │ <d>ms │ features/a.feature:3 │
│ slow step │ <d>ms │ features/a.feature:3 │
│ slow step │ <d>ms │ features/a.feature:3 │
│ 5 more │ │ │
└──────────────────┴──────────┴──────────────────────────────────────┘
"""