1
+ /* eslint-env mocha */
1
2
'use strict' ;
3
+ var path = require ( 'path' ) ;
2
4
var assert = require ( 'assert' ) ;
3
5
var gutil = require ( 'gulp-util' ) ;
4
- var jscs = require ( './' ) ;
5
6
var streamAssert = require ( 'stream-assert' ) ;
7
+ var jscs = require ( './' ) ;
6
8
7
9
var stdoutWrite = process . stdout . write ;
8
10
var stdoutStub ;
9
11
10
12
function stubStdout ( ) {
11
13
stdoutStub = '' ;
12
- process . stdout . write = function ( str ) {
14
+ process . stdout . write = function ( str ) {
13
15
stdoutStub += str ;
14
16
} ;
15
17
}
@@ -37,13 +39,13 @@ it('should check code style of JS files', function (cb) {
37
39
38
40
stream . write ( new gutil . File ( {
39
41
base : __dirname ,
40
- path : __dirname + '/ fixture.js',
42
+ path : path . join ( __dirname , ' fixture.js') ,
41
43
contents : new Buffer ( 'var x = 1,y = 2;' )
42
44
} ) ) ;
43
45
44
46
stream . write ( new gutil . File ( {
45
47
base : __dirname ,
46
- path : __dirname + '/ fixture2.js',
48
+ path : path . join ( __dirname , ' fixture2.js') ,
47
49
contents : new Buffer ( 'var x = { a: 1 };' )
48
50
} ) ) ;
49
51
@@ -62,7 +64,7 @@ it('should check code style of JS files using a preset', function (cb) {
62
64
63
65
stream . write ( new gutil . File ( {
64
66
base : __dirname ,
65
- path : __dirname + '/ fixture.js',
67
+ path : path . join ( __dirname , ' fixture.js') ,
66
68
contents : new Buffer ( 'var x = 1,y = 2;' )
67
69
} ) ) ;
68
70
@@ -77,7 +79,7 @@ it('should pass valid files', function (cb) {
77
79
} ) . on ( 'end' , cb ) . resume ( ) ;
78
80
79
81
stream . write ( new gutil . File ( {
80
- path : __dirname + '/ fixture.js',
82
+ path : path . join ( __dirname , ' fixture.js') ,
81
83
contents : new Buffer ( 'var x = 1; var y = 2;' )
82
84
} ) ) ;
83
85
@@ -93,14 +95,14 @@ it('should respect "excludeFiles" from config', function (cb) {
93
95
94
96
stream . write ( new gutil . File ( {
95
97
base : __dirname ,
96
- path : __dirname + '/ excluded.js',
98
+ path : path . join ( __dirname , ' excluded.js') ,
97
99
contents : new Buffer ( 'var x = { a: 1 };' )
98
100
} ) ) ;
99
101
100
102
stream . end ( ) ;
101
103
} ) ;
102
104
103
- it ( 'should accept both esnext and configPath options' , function ( cb ) {
105
+ it ( 'should accept both esnext and configPath options' , function ( cb ) {
104
106
var stream = jscs ( {
105
107
esnext : true ,
106
108
configPath : '.jscsrc'
@@ -116,16 +118,14 @@ it('should accept both esnext and configPath options', function(cb) {
116
118
117
119
stream . write ( new gutil . File ( {
118
120
base : __dirname ,
119
- path : __dirname + '/ fixture.js',
121
+ path : path . join ( __dirname , ' fixture.js') ,
120
122
contents : new Buffer ( 'import x from \'x\'; var x = 1, y = 2;' )
121
123
} ) ) ;
122
124
123
125
stream . end ( ) ;
124
126
} ) ;
125
127
126
128
it ( 'should accept the fix option' , function ( cb ) {
127
- var data = '' ;
128
-
129
129
var stream = jscs ( {
130
130
fix : true ,
131
131
configPath : '.jscsrc'
@@ -139,7 +139,7 @@ it('should accept the fix option', function (cb) {
139
139
140
140
stream . write ( new gutil . File ( {
141
141
base : __dirname ,
142
- path : __dirname + '/ fixture.js',
142
+ path : path . join ( __dirname , ' fixture.js') ,
143
143
contents : new Buffer ( 'var x = { a: 1, b: 2 }' )
144
144
} ) ) ;
145
145
@@ -164,15 +164,15 @@ describe('Reporter', function () {
164
164
stubStdout ( ) ;
165
165
var stream = jscs ( ) ;
166
166
167
- stream . pipe ( jscs . reporter ( ) ) . on ( 'end' , function ( err ) {
167
+ stream . pipe ( jscs . reporter ( ) ) . on ( 'end' , function ( ) {
168
168
assert ( / M u l t i p l e v a r d e c l a r a t i o n [ ^ ] * - - - \^ / . test ( stdoutStub ) ) ;
169
169
teardown ( ) ;
170
170
cb ( ) ;
171
171
} ) . resume ( ) ;
172
172
173
173
stream . write ( new gutil . File ( {
174
174
base : __dirname ,
175
- path : __dirname + '/ fixture.js',
175
+ path : path . join ( __dirname , ' fixture.js') ,
176
176
contents : new Buffer ( 'var x = 1,y = 2;' )
177
177
} ) ) ;
178
178
@@ -183,15 +183,15 @@ describe('Reporter', function () {
183
183
stubStdout ( ) ;
184
184
var stream = jscs ( ) ;
185
185
186
- stream . pipe ( jscs . reporter ( 'inlinesingle' ) ) . on ( 'end' , function ( err ) {
186
+ stream . pipe ( jscs . reporter ( 'inlinesingle' ) ) . on ( 'end' , function ( ) {
187
187
assert ( / l i n e 1 , c o l 0 , M u l t i p l e v a r d e c l a r a t i o n / . test ( stdoutStub ) ) ;
188
188
teardown ( ) ;
189
189
cb ( ) ;
190
190
} ) . resume ( ) ;
191
191
192
192
stream . write ( new gutil . File ( {
193
193
base : __dirname ,
194
- path : __dirname + '/ fixture.js',
194
+ path : path . join ( __dirname , ' fixture.js') ,
195
195
contents : new Buffer ( 'var x = 1,y = 2;' )
196
196
} ) ) ;
197
197
@@ -210,7 +210,7 @@ describe('Reporter', function () {
210
210
211
211
stream . write ( new gutil . File ( {
212
212
base : __dirname ,
213
- path : __dirname + '/ fixture.js',
213
+ path : path . join ( __dirname , ' fixture.js') ,
214
214
contents : new Buffer ( 'var x = 1,y = 2;' )
215
215
} ) ) ;
216
216
@@ -236,20 +236,24 @@ describe('Reporter', function () {
236
236
assert ( file . jscs . success ) ;
237
237
} ) )
238
238
. pipe ( streamAssert . end ( function ( err ) {
239
- if ( err ) return cb ( err ) ;
239
+ if ( err ) {
240
+ cb ( err ) ;
241
+ return ;
242
+ }
243
+
240
244
assert ( passedErrorAssertion , 'Did not emit an error' ) ;
241
245
cb ( ) ;
242
246
} ) ) ;
243
247
244
248
stream . write ( new gutil . File ( {
245
249
base : __dirname ,
246
- path : __dirname + '/ fixture.js',
250
+ path : path . join ( __dirname , ' fixture.js') ,
247
251
contents : new Buffer ( 'var x = 1,y = 2;' )
248
252
} ) ) ;
249
253
250
254
stream . write ( new gutil . File ( {
251
255
base : __dirname ,
252
- path : __dirname + '/ passing.js',
256
+ path : path . join ( __dirname , ' passing.js') ,
253
257
contents : new Buffer ( 'var x = 1; var y = 2;' )
254
258
} ) ) ;
255
259
@@ -265,20 +269,20 @@ describe('Reporter', function () {
265
269
assert ( err instanceof Error && / J S C S / . test ( err . message ) ) ;
266
270
cb ( ) ;
267
271
} )
268
- . pipe ( streamAssert . second ( function ( file ) {
272
+ . pipe ( streamAssert . second ( function ( ) {
269
273
cb ( new Error ( 'Did not emit an error immediately' ) ) ;
270
274
} ) )
271
275
. pipe ( streamAssert . end ( ) ) ;
272
276
273
277
stream . write ( new gutil . File ( {
274
278
base : __dirname ,
275
- path : __dirname + '/ fixture.js',
279
+ path : path . join ( __dirname , ' fixture.js') ,
276
280
contents : new Buffer ( 'var x = 1,y = 2;' )
277
281
} ) ) ;
278
282
279
283
stream . write ( new gutil . File ( {
280
284
base : __dirname ,
281
- path : __dirname + '/ passing.js',
285
+ path : path . join ( __dirname , ' passing.js') ,
282
286
contents : new Buffer ( 'var x = 1; var y = 2;' )
283
287
} ) ) ;
284
288
0 commit comments