-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.coffee
210 lines (156 loc) · 5.88 KB
/
test.coffee
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# module deps
assert = require 'assert'
chalk = require 'chalk'
coffeelint = require 'coffeelint'
# SUT
StylishReporter = require './index'
reporter = StylishReporter.reporter
describe 'coffeelint-stylish', ->
describe 'should export a constructor', ->
fake_error_report =
paths:
'index.coffee': ['results_of_index.coffee']
'test.coffee': ['results_of_test.coffee']
stylish_instance = null
beforeEach ->
stylish_instance = new StylishReporter fake_error_report
it 'satisfying the coffeelint external reporter api', ->
assert.strictEqual stylish_instance.error_report, fake_error_report
assert.strictEqual typeof stylish_instance.publish, 'function'
it 'with instances referring back to .reporter internally', ->
_reporter = StylishReporter.reporter
ret1 = false
ret2 = false
# mock on
StylishReporter.reporter = (filename, results) ->
if (filename is 'index.coffee') and
(results is fake_error_report.paths['index.coffee']) and
(ret1 is false)
then ret1 = true
if (filename is 'test.coffee') and
(results is fake_error_report.paths['test.coffee']) and
(ret2 is false)
then ret2 = true
undefined
# run reporter
stylish_instance.publish()
# mock out
StylishReporter.reporter = _reporter
assert ret1
assert ret2
describe '.reporter should prettily report coffeelint results', ->
it 'with a filename', ->
ret = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
ret = /my name is/ig.test chalk.stripColor str
# run reporter
reporter 'my name is', coffeelint.lint 'yeah()', {}
# mock out
process.stdout.write = _log
assert ret
it 'without a filename', ->
ret = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
ret = /No problems/ig.test chalk.stripColor str
# run reporter
reporter null, coffeelint.lint 'yeah()', {}
# mock out
process.stdout.write = _log
assert ret
it 'even if they are bad (1 warn)', ->
ret1 = false
ret2 = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
ret1 = /line 1 Line contains a trailing semicolon/ig.test(
chalk.stripColor str
)
ret2 = /1 warn/ig.test chalk.stripColor str
# run reporter
reporter '', coffeelint.lint(
'yeah();',
no_trailing_semicolons: level: 'warn'
)
# mock out
process.stdout.write = _log
assert ret1
assert ret2
it 'even if they are worse (1 error)', ->
ret1 = false
ret2 = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
ret1 = /line 1 Line contains a trailing semicolon/ig.test(
chalk.stripColor str
)
ret2 = /1 error/ig.test chalk.stripColor str
# run reporter
reporter '', coffeelint.lint 'yeah();', {}
# mock out
process.stdout.write = _log
assert ret1
assert ret2
it 'even if they are bad and worse', ->
ret1 = false
ret2 = false
ret3 = false
ret4 = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
ret1 = /line 1 Line contains a trailing semicolon/ig.test(
chalk.stripColor str
)
ret2 = /1 error/ig.test chalk.stripColor str
ret3 = /line 1 Unnecessary fat arrow/ig.test(
chalk.stripColor str
)
ret4 = /1 warning/ig.test chalk.stripColor str
# run reporter
reporter 'test', coffeelint.lint 'do => yeah();', {}
# mock out
process.stdout.write = _log
assert ret1
assert ret2
it 'even if they are double bad', ->
warns = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
warns = /2 warnings/ig.test chalk.stripColor str
# run reporter
reporter 'test', coffeelint.lint 'do => => yeah()'
# mock out
process.stdout.write = _log
assert warns
it 'even if they are double worse', ->
warns = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
warns = /2 errors/ig.test chalk.stripColor str
# run reporter
reporter 'test', coffeelint.lint(
'do => => yeah()',
no_unnecessary_fat_arrows: level: 'error'
)
# mock out
process.stdout.write = _log
assert warns
it 'even if there are no results', ->
ret = false
_log = process.stdout.write
# mock on
process.stdout.write = (str = '') ->
ret = /no results/ig.test chalk.stripColor str
# run reporter
reporter 'no results'
# mock out
process.stdout.write = _log
assert ret