@@ -3,8 +3,12 @@ import { expect } from 'chai'
33import FakeTimers , { InstalledClock } from '@sinonjs/fake-timers'
44import { reindent } from 'reindent-template-literals'
55import timeMethods from '../time'
6- import { getUsageSupportCodeLibrary } from '../../test/fixtures/usage_steps'
6+ import {
7+ getBasicUsageSupportCodeLibrary ,
8+ getOrderedUsageSupportCodeLibrary ,
9+ } from '../../test/fixtures/usage/usage_steps'
710import { testFormatter } from '../../test/formatter_helpers'
11+ import { UsageOrder } from './helpers'
812
913describe ( 'UsageFormatter' , ( ) => {
1014 let clock : InstalledClock
@@ -33,7 +37,7 @@ describe('UsageFormatter', () => {
3337 describe ( 'unused' , ( ) => {
3438 it ( 'outputs the step definitions as unused' , async ( ) => {
3539 // Arrange
36- const supportCodeLibrary = getUsageSupportCodeLibrary ( clock )
40+ const supportCodeLibrary = getBasicUsageSupportCodeLibrary ( clock )
3741
3842 // Act
3943 const output = await testFormatter ( {
@@ -47,11 +51,11 @@ describe('UsageFormatter', () => {
4751 ┌────────────────┬──────────┬───────────────────┐
4852 │ Pattern / Text │ Duration │ Location │
4953 ├────────────────┼──────────┼───────────────────┤
50- │ abc │ UNUSED │ usage_steps.ts:11 │
54+ │ abc │ UNUSED │ usage_steps.ts:13 │
5155 ├────────────────┼──────────┼───────────────────┤
52- │ /def?/ │ UNUSED │ usage_steps.ts:16 │
56+ │ /def?/ │ UNUSED │ usage_steps.ts:18 │
5357 ├────────────────┼──────────┼───────────────────┤
54- │ ghi │ UNUSED │ usage_steps.ts:25 │
58+ │ ghi │ UNUSED │ usage_steps.ts:27 │
5559 └────────────────┴──────────┴───────────────────┘
5660
5761 ` )
@@ -70,7 +74,7 @@ describe('UsageFormatter', () => {
7074 uri : 'a.feature' ,
7175 } ,
7276 ]
73- const supportCodeLibrary = getUsageSupportCodeLibrary ( clock )
77+ const supportCodeLibrary = getBasicUsageSupportCodeLibrary ( clock )
7478
7579 // Act
7680 const output = await testFormatter ( {
@@ -86,13 +90,13 @@ describe('UsageFormatter', () => {
8690 ┌────────────────┬──────────┬───────────────────┐
8791 │ Pattern / Text │ Duration │ Location │
8892 ├────────────────┼──────────┼───────────────────┤
89- │ abc │ UNUSED │ usage_steps.ts:11 │
93+ │ abc │ UNUSED │ usage_steps.ts:13 │
9094 ├────────────────┼──────────┼───────────────────┤
91- │ /def?/ │ - │ usage_steps.ts:16 │
95+ │ /def?/ │ - │ usage_steps.ts:18 │
9296 │ de │ - │ a.feature:4 │
9397 │ def │ - │ a.feature:3 │
9498 ├────────────────┼──────────┼───────────────────┤
95- │ ghi │ UNUSED │ usage_steps.ts:25 │
99+ │ ghi │ UNUSED │ usage_steps.ts:27 │
96100 └────────────────┴──────────┴───────────────────┘
97101
98102 ` )
@@ -101,15 +105,15 @@ describe('UsageFormatter', () => {
101105 } )
102106
103107 describe ( 'not in dry run' , ( ) => {
104- it ( 'outputs the step definition without durations' , async ( ) => {
108+ it ( 'outputs the step definition with durations' , async ( ) => {
105109 // Arrange
106110 const sources = [
107111 {
108112 data : 'Feature: a\nScenario: b\nWhen def\nThen de' ,
109113 uri : 'a.feature' ,
110114 } ,
111115 ]
112- const supportCodeLibrary = getUsageSupportCodeLibrary ( clock )
116+ const supportCodeLibrary = getBasicUsageSupportCodeLibrary ( clock )
113117
114118 // Act
115119 const output = await testFormatter ( {
@@ -124,19 +128,91 @@ describe('UsageFormatter', () => {
124128 ┌────────────────┬──────────┬───────────────────┐
125129 │ Pattern / Text │ Duration │ Location │
126130 ├────────────────┼──────────┼───────────────────┤
127- │ /def?/ │ 1.50ms │ usage_steps.ts:16 │
131+ │ /def?/ │ 1.50ms │ usage_steps.ts:18 │
128132 │ def │ 2.00ms │ a.feature:3 │
129133 │ de │ 1.00ms │ a.feature:4 │
130134 ├────────────────┼──────────┼───────────────────┤
131- │ abc │ UNUSED │ usage_steps.ts:11 │
135+ │ abc │ UNUSED │ usage_steps.ts:13 │
132136 ├────────────────┼──────────┼───────────────────┤
133- │ ghi │ UNUSED │ usage_steps.ts:25 │
137+ │ ghi │ UNUSED │ usage_steps.ts:27 │
134138 └────────────────┴──────────┴───────────────────┘
135139
136140 ` )
137141 )
138142 } )
139143 } )
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+ } )
140216 } )
141217 } )
142218} )
0 commit comments