-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathusage_json_formatter_spec.ts
93 lines (87 loc) · 2.13 KB
/
usage_json_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
import { afterEach, beforeEach, describe, it } from 'mocha'
import { expect } from 'chai'
import FakeTimers, { InstalledClock } from '@sinonjs/fake-timers'
import timeMethods from '../time'
import { getUsageSupportCodeLibrary } from '../../test/fixtures/usage_steps'
import { testFormatter } from '../../test/formatter_helpers'
describe('UsageJsonFormatter', () => {
let clock: InstalledClock
beforeEach(() => {
clock = FakeTimers.withGlobal(timeMethods).install()
})
afterEach(() => {
clock.uninstall()
})
it('outputs the usage in json format', async () => {
// Arrange
const sources = [
{
data: 'Feature: a\nScenario: b\nGiven abc\nWhen def',
uri: 'a.feature',
},
]
const supportCodeLibrary = getUsageSupportCodeLibrary(clock)
// Act
const output = await testFormatter({
sources,
supportCodeLibrary,
type: 'usage-json',
})
const parsedOutput = JSON.parse(output)
// Assert
expect(parsedOutput).to.eql([
{
code: parsedOutput[0].code,
line: 16,
matches: [
{
duration: {
seconds: 0,
nanos: 2000000,
},
line: 4,
text: 'def',
uri: 'a.feature',
},
],
meanDuration: {
seconds: 0,
nanos: 2000000,
},
pattern: 'def?',
patternType: 'RegularExpression',
uri: 'usage_steps.ts',
},
{
code: parsedOutput[1].code,
line: 11,
matches: [
{
duration: {
seconds: 0,
nanos: 1000000,
},
line: 3,
text: 'abc',
uri: 'a.feature',
},
],
meanDuration: {
seconds: 0,
nanos: 1000000,
},
pattern: 'abc',
patternType: 'CucumberExpression',
uri: 'usage_steps.ts',
},
{
code: parsedOutput[2].code,
line: 25,
matches: [],
pattern: 'ghi',
patternType: 'CucumberExpression',
uri: 'usage_steps.ts',
},
])
})
})