-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathusage_formatter_spec.ts
142 lines (124 loc) · 6.16 KB
/
usage_formatter_spec.ts
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { afterEach, beforeEach, describe, it } from 'mocha'
import { expect } from 'chai'
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import { reindent } from 'reindent-template-literals'
import timeMethods from '../time'
import { getUsageSupportCodeLibrary } from '../../test/fixtures/usage_steps'
import { testFormatter } from '../../test/formatter_helpers'
describe('UsageFormatter', () => {
let clock: InstalledClock
beforeEach(() => {
clock = FakeTimers.withGlobal(timeMethods).install()
})
afterEach(() => {
clock.uninstall()
})
describe('no step definitions', () => {
it('outputs "No step definitions"', async () => {
// Arrange
// Act
const output = await testFormatter({ type: 'usage' })
// Assert
expect(output).to.eql('No step definitions')
})
})
describe('with step definitions', () => {
describe('unused', () => {
it('outputs the step definitions as unused', async () => {
// Arrange
const supportCodeLibrary = getUsageSupportCodeLibrary(clock)
// Act
const output = await testFormatter({
supportCodeLibrary,
type: 'usage',
})
// Assert
expect(output).to.eql(
reindent(`
┌────────────────┬──────────┬───────────────────┐
│ Pattern / Text │ Duration │ Location │
├────────────────┼──────────┼───────────────────┤
│ abc │ UNUSED │ usage_steps.ts:11 │
├────────────────┼──────────┼───────────────────┤
│ /def?/ │ UNUSED │ usage_steps.ts:16 │
├────────────────┼──────────┼───────────────────┤
│ ghi │ UNUSED │ usage_steps.ts:25 │
└────────────────┴──────────┴───────────────────┘
`)
)
})
})
describe('used', () => {
describe('in dry run', () => {
it('outputs the step definition without durations', async () => {
// Arrange
const runtimeOptions = { dryRun: true }
const sources = [
{
data: 'Feature: a\nScenario: b\nWhen def\nThen de',
uri: 'a.feature',
},
]
const supportCodeLibrary = getUsageSupportCodeLibrary(clock)
// Act
const output = await testFormatter({
runtimeOptions,
sources,
supportCodeLibrary,
type: 'usage',
})
// Assert
expect(output).to.eql(
reindent(`
┌────────────────┬──────────┬───────────────────┐
│ Pattern / Text │ Duration │ Location │
├────────────────┼──────────┼───────────────────┤
│ abc │ UNUSED │ usage_steps.ts:11 │
├────────────────┼──────────┼───────────────────┤
│ /def?/ │ - │ usage_steps.ts:16 │
│ de │ - │ a.feature:4 │
│ def │ - │ a.feature:3 │
├────────────────┼──────────┼───────────────────┤
│ ghi │ UNUSED │ usage_steps.ts:25 │
└────────────────┴──────────┴───────────────────┘
`)
)
})
})
describe('not in dry run', () => {
it('outputs the step definition without durations', async () => {
// Arrange
const sources = [
{
data: 'Feature: a\nScenario: b\nWhen def\nThen de',
uri: 'a.feature',
},
]
const supportCodeLibrary = getUsageSupportCodeLibrary(clock)
// Act
const output = await testFormatter({
sources,
supportCodeLibrary,
type: 'usage',
})
// Assert
expect(output).to.eql(
reindent(`
┌────────────────┬──────────┬───────────────────┐
│ Pattern / Text │ Duration │ Location │
├────────────────┼──────────┼───────────────────┤
│ /def?/ │ 1.50ms │ usage_steps.ts:16 │
│ def │ 2.00ms │ a.feature:3 │
│ de │ 1.00ms │ a.feature:4 │
├────────────────┼──────────┼───────────────────┤
│ abc │ UNUSED │ usage_steps.ts:11 │
├────────────────┼──────────┼───────────────────┤
│ ghi │ UNUSED │ usage_steps.ts:25 │
└────────────────┴──────────┴───────────────────┘
`)
)
})
})
})
})
})