@@ -3,8 +3,12 @@ import { expect } from 'chai'
3
3
import FakeTimers , { InstalledClock } from '@sinonjs/fake-timers'
4
4
import { reindent } from 'reindent-template-literals'
5
5
import timeMethods from '../time'
6
- import { getUsageSupportCodeLibrary } from '../../test/fixtures/usage_steps'
6
+ import {
7
+ getBasicUsageSupportCodeLibrary ,
8
+ getOrderedUsageSupportCodeLibrary ,
9
+ } from '../../test/fixtures/usage/usage_steps'
7
10
import { testFormatter } from '../../test/formatter_helpers'
11
+ import { UsageOrder } from './helpers'
8
12
9
13
describe ( 'UsageFormatter' , ( ) => {
10
14
let clock : InstalledClock
@@ -33,7 +37,7 @@ describe('UsageFormatter', () => {
33
37
describe ( 'unused' , ( ) => {
34
38
it ( 'outputs the step definitions as unused' , async ( ) => {
35
39
// Arrange
36
- const supportCodeLibrary = getUsageSupportCodeLibrary ( clock )
40
+ const supportCodeLibrary = getBasicUsageSupportCodeLibrary ( clock )
37
41
38
42
// Act
39
43
const output = await testFormatter ( {
@@ -47,11 +51,11 @@ describe('UsageFormatter', () => {
47
51
┌────────────────┬──────────┬───────────────────┐
48
52
│ Pattern / Text │ Duration │ Location │
49
53
├────────────────┼──────────┼───────────────────┤
50
- │ abc │ UNUSED │ usage_steps.ts:11 │
54
+ │ abc │ UNUSED │ usage_steps.ts:13 │
51
55
├────────────────┼──────────┼───────────────────┤
52
- │ /def?/ │ UNUSED │ usage_steps.ts:16 │
56
+ │ /def?/ │ UNUSED │ usage_steps.ts:18 │
53
57
├────────────────┼──────────┼───────────────────┤
54
- │ ghi │ UNUSED │ usage_steps.ts:25 │
58
+ │ ghi │ UNUSED │ usage_steps.ts:27 │
55
59
└────────────────┴──────────┴───────────────────┘
56
60
57
61
` )
@@ -70,7 +74,7 @@ describe('UsageFormatter', () => {
70
74
uri : 'a.feature' ,
71
75
} ,
72
76
]
73
- const supportCodeLibrary = getUsageSupportCodeLibrary ( clock )
77
+ const supportCodeLibrary = getBasicUsageSupportCodeLibrary ( clock )
74
78
75
79
// Act
76
80
const output = await testFormatter ( {
@@ -86,13 +90,13 @@ describe('UsageFormatter', () => {
86
90
┌────────────────┬──────────┬───────────────────┐
87
91
│ Pattern / Text │ Duration │ Location │
88
92
├────────────────┼──────────┼───────────────────┤
89
- │ abc │ UNUSED │ usage_steps.ts:11 │
93
+ │ abc │ UNUSED │ usage_steps.ts:13 │
90
94
├────────────────┼──────────┼───────────────────┤
91
- │ /def?/ │ - │ usage_steps.ts:16 │
95
+ │ /def?/ │ - │ usage_steps.ts:18 │
92
96
│ de │ - │ a.feature:4 │
93
97
│ def │ - │ a.feature:3 │
94
98
├────────────────┼──────────┼───────────────────┤
95
- │ ghi │ UNUSED │ usage_steps.ts:25 │
99
+ │ ghi │ UNUSED │ usage_steps.ts:27 │
96
100
└────────────────┴──────────┴───────────────────┘
97
101
98
102
` )
@@ -101,15 +105,15 @@ describe('UsageFormatter', () => {
101
105
} )
102
106
103
107
describe ( 'not in dry run' , ( ) => {
104
- it ( 'outputs the step definition without durations' , async ( ) => {
108
+ it ( 'outputs the step definition with durations' , async ( ) => {
105
109
// Arrange
106
110
const sources = [
107
111
{
108
112
data : 'Feature: a\nScenario: b\nWhen def\nThen de' ,
109
113
uri : 'a.feature' ,
110
114
} ,
111
115
]
112
- const supportCodeLibrary = getUsageSupportCodeLibrary ( clock )
116
+ const supportCodeLibrary = getBasicUsageSupportCodeLibrary ( clock )
113
117
114
118
// Act
115
119
const output = await testFormatter ( {
@@ -124,19 +128,91 @@ describe('UsageFormatter', () => {
124
128
┌────────────────┬──────────┬───────────────────┐
125
129
│ Pattern / Text │ Duration │ Location │
126
130
├────────────────┼──────────┼───────────────────┤
127
- │ /def?/ │ 1.50ms │ usage_steps.ts:16 │
131
+ │ /def?/ │ 1.50ms │ usage_steps.ts:18 │
128
132
│ def │ 2.00ms │ a.feature:3 │
129
133
│ de │ 1.00ms │ a.feature:4 │
130
134
├────────────────┼──────────┼───────────────────┤
131
- │ abc │ UNUSED │ usage_steps.ts:11 │
135
+ │ abc │ UNUSED │ usage_steps.ts:13 │
132
136
├────────────────┼──────────┼───────────────────┤
133
- │ ghi │ UNUSED │ usage_steps.ts:25 │
137
+ │ ghi │ UNUSED │ usage_steps.ts:27 │
134
138
└────────────────┴──────────┴───────────────────┘
135
139
136
140
` )
137
141
)
138
142
} )
139
143
} )
144
+
145
+ describe ( 'sorting' , ( ) => {
146
+ const sources = [
147
+ {
148
+ data : 'Feature: a\nScenario: a\nGiven foo\nThen bar' ,
149
+ uri : 'a.feature' ,
150
+ } ,
151
+ {
152
+ data : 'Feature: b\nScenario: b\nGiven foo\nThen bar' ,
153
+ uri : 'b.feature' ,
154
+ } ,
155
+ ]
156
+
157
+ it ( 'defaults to order by execution time, decreasingly' , async ( ) => {
158
+ const supportCodeLibrary = getOrderedUsageSupportCodeLibrary ( clock )
159
+
160
+ // Act
161
+ const output = await testFormatter ( {
162
+ sources,
163
+ supportCodeLibrary,
164
+ type : 'usage' ,
165
+ } )
166
+
167
+ // Assert
168
+ expect ( output ) . to . eql (
169
+ reindent ( `
170
+ ┌────────────────┬──────────┬─────────────────┐
171
+ │ Pattern / Text │ Duration │ Location │
172
+ ├────────────────┼──────────┼─────────────────┤
173
+ │ foo │ 15.00ms │ foo_steps.ts:10 │
174
+ │ foo │ 20.00ms │ b.feature:3 │
175
+ │ foo │ 10.00ms │ a.feature:3 │
176
+ ├────────────────┼──────────┼─────────────────┤
177
+ │ bar │ 3.00ms │ bar_steps.ts:10 │
178
+ │ bar │ 4.00ms │ b.feature:4 │
179
+ │ bar │ 2.00ms │ a.feature:4 │
180
+ └────────────────┴──────────┴─────────────────┘
181
+
182
+ ` )
183
+ )
184
+ } )
185
+
186
+ it ( 'can optionally order by location' , async ( ) => {
187
+ const supportCodeLibrary = getOrderedUsageSupportCodeLibrary ( clock )
188
+
189
+ // Act
190
+ const output = await testFormatter ( {
191
+ sources,
192
+ supportCodeLibrary,
193
+ type : 'usage' ,
194
+ parsedArgvOptions : { usage : { order : UsageOrder . LOCATION } } ,
195
+ } )
196
+
197
+ // Assert
198
+ expect ( output ) . to . eql (
199
+ reindent ( `
200
+ ┌────────────────┬──────────┬─────────────────┐
201
+ │ Pattern / Text │ Duration │ Location │
202
+ ├────────────────┼──────────┼─────────────────┤
203
+ │ bar │ 3.00ms │ bar_steps.ts:10 │
204
+ │ bar │ 2.00ms │ a.feature:4 │
205
+ │ bar │ 4.00ms │ b.feature:4 │
206
+ ├────────────────┼──────────┼─────────────────┤
207
+ │ foo │ 15.00ms │ foo_steps.ts:10 │
208
+ │ foo │ 10.00ms │ a.feature:3 │
209
+ │ foo │ 20.00ms │ b.feature:3 │
210
+ └────────────────┴──────────┴─────────────────┘
211
+
212
+ ` )
213
+ )
214
+ } )
215
+ } )
140
216
} )
141
217
} )
142
218
} )
0 commit comments