1+ /* eslint-env mocha */
12'use strict' ;
3+ var path = require ( 'path' ) ;
24var assert = require ( 'assert' ) ;
35var gutil = require ( 'gulp-util' ) ;
4- var jscs = require ( './' ) ;
56var streamAssert = require ( 'stream-assert' ) ;
7+ var jscs = require ( './' ) ;
68
79var stdoutWrite = process . stdout . write ;
810var stdoutStub ;
911
1012function stubStdout ( ) {
1113 stdoutStub = '' ;
12- process . stdout . write = function ( str ) {
14+ process . stdout . write = function ( str ) {
1315 stdoutStub += str ;
1416 } ;
1517}
@@ -37,13 +39,13 @@ it('should check code style of JS files', function (cb) {
3739
3840 stream . write ( new gutil . File ( {
3941 base : __dirname ,
40- path : __dirname + '/ fixture.js',
42+ path : path . join ( __dirname , ' fixture.js') ,
4143 contents : new Buffer ( 'var x = 1,y = 2;' )
4244 } ) ) ;
4345
4446 stream . write ( new gutil . File ( {
4547 base : __dirname ,
46- path : __dirname + '/ fixture2.js',
48+ path : path . join ( __dirname , ' fixture2.js') ,
4749 contents : new Buffer ( 'var x = { a: 1 };' )
4850 } ) ) ;
4951
@@ -62,7 +64,7 @@ it('should check code style of JS files using a preset', function (cb) {
6264
6365 stream . write ( new gutil . File ( {
6466 base : __dirname ,
65- path : __dirname + '/ fixture.js',
67+ path : path . join ( __dirname , ' fixture.js') ,
6668 contents : new Buffer ( 'var x = 1,y = 2;' )
6769 } ) ) ;
6870
@@ -77,7 +79,7 @@ it('should pass valid files', function (cb) {
7779 } ) . on ( 'end' , cb ) . resume ( ) ;
7880
7981 stream . write ( new gutil . File ( {
80- path : __dirname + '/ fixture.js',
82+ path : path . join ( __dirname , ' fixture.js') ,
8183 contents : new Buffer ( 'var x = 1; var y = 2;' )
8284 } ) ) ;
8385
@@ -93,14 +95,14 @@ it('should respect "excludeFiles" from config', function (cb) {
9395
9496 stream . write ( new gutil . File ( {
9597 base : __dirname ,
96- path : __dirname + '/ excluded.js',
98+ path : path . join ( __dirname , ' excluded.js') ,
9799 contents : new Buffer ( 'var x = { a: 1 };' )
98100 } ) ) ;
99101
100102 stream . end ( ) ;
101103} ) ;
102104
103- it ( 'should accept both esnext and configPath options' , function ( cb ) {
105+ it ( 'should accept both esnext and configPath options' , function ( cb ) {
104106 var stream = jscs ( {
105107 esnext : true ,
106108 configPath : '.jscsrc'
@@ -116,16 +118,14 @@ it('should accept both esnext and configPath options', function(cb) {
116118
117119 stream . write ( new gutil . File ( {
118120 base : __dirname ,
119- path : __dirname + '/ fixture.js',
121+ path : path . join ( __dirname , ' fixture.js') ,
120122 contents : new Buffer ( 'import x from \'x\'; var x = 1, y = 2;' )
121123 } ) ) ;
122124
123125 stream . end ( ) ;
124126} ) ;
125127
126128it ( 'should accept the fix option' , function ( cb ) {
127- var data = '' ;
128-
129129 var stream = jscs ( {
130130 fix : true ,
131131 configPath : '.jscsrc'
@@ -139,7 +139,7 @@ it('should accept the fix option', function (cb) {
139139
140140 stream . write ( new gutil . File ( {
141141 base : __dirname ,
142- path : __dirname + '/ fixture.js',
142+ path : path . join ( __dirname , ' fixture.js') ,
143143 contents : new Buffer ( 'var x = { a: 1, b: 2 }' )
144144 } ) ) ;
145145
@@ -164,15 +164,15 @@ describe('Reporter', function () {
164164 stubStdout ( ) ;
165165 var stream = jscs ( ) ;
166166
167- stream . pipe ( jscs . reporter ( ) ) . on ( 'end' , function ( err ) {
167+ stream . pipe ( jscs . reporter ( ) ) . on ( 'end' , function ( ) {
168168 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 ) ) ;
169169 teardown ( ) ;
170170 cb ( ) ;
171171 } ) . resume ( ) ;
172172
173173 stream . write ( new gutil . File ( {
174174 base : __dirname ,
175- path : __dirname + '/ fixture.js',
175+ path : path . join ( __dirname , ' fixture.js') ,
176176 contents : new Buffer ( 'var x = 1,y = 2;' )
177177 } ) ) ;
178178
@@ -183,15 +183,15 @@ describe('Reporter', function () {
183183 stubStdout ( ) ;
184184 var stream = jscs ( ) ;
185185
186- stream . pipe ( jscs . reporter ( 'inlinesingle' ) ) . on ( 'end' , function ( err ) {
186+ stream . pipe ( jscs . reporter ( 'inlinesingle' ) ) . on ( 'end' , function ( ) {
187187 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 ) ) ;
188188 teardown ( ) ;
189189 cb ( ) ;
190190 } ) . resume ( ) ;
191191
192192 stream . write ( new gutil . File ( {
193193 base : __dirname ,
194- path : __dirname + '/ fixture.js',
194+ path : path . join ( __dirname , ' fixture.js') ,
195195 contents : new Buffer ( 'var x = 1,y = 2;' )
196196 } ) ) ;
197197
@@ -210,7 +210,7 @@ describe('Reporter', function () {
210210
211211 stream . write ( new gutil . File ( {
212212 base : __dirname ,
213- path : __dirname + '/ fixture.js',
213+ path : path . join ( __dirname , ' fixture.js') ,
214214 contents : new Buffer ( 'var x = 1,y = 2;' )
215215 } ) ) ;
216216
@@ -236,20 +236,24 @@ describe('Reporter', function () {
236236 assert ( file . jscs . success ) ;
237237 } ) )
238238 . pipe ( streamAssert . end ( function ( err ) {
239- if ( err ) return cb ( err ) ;
239+ if ( err ) {
240+ cb ( err ) ;
241+ return ;
242+ }
243+
240244 assert ( passedErrorAssertion , 'Did not emit an error' ) ;
241245 cb ( ) ;
242246 } ) ) ;
243247
244248 stream . write ( new gutil . File ( {
245249 base : __dirname ,
246- path : __dirname + '/ fixture.js',
250+ path : path . join ( __dirname , ' fixture.js') ,
247251 contents : new Buffer ( 'var x = 1,y = 2;' )
248252 } ) ) ;
249253
250254 stream . write ( new gutil . File ( {
251255 base : __dirname ,
252- path : __dirname + '/ passing.js',
256+ path : path . join ( __dirname , ' passing.js') ,
253257 contents : new Buffer ( 'var x = 1; var y = 2;' )
254258 } ) ) ;
255259
@@ -265,20 +269,20 @@ describe('Reporter', function () {
265269 assert ( err instanceof Error && / J S C S / . test ( err . message ) ) ;
266270 cb ( ) ;
267271 } )
268- . pipe ( streamAssert . second ( function ( file ) {
272+ . pipe ( streamAssert . second ( function ( ) {
269273 cb ( new Error ( 'Did not emit an error immediately' ) ) ;
270274 } ) )
271275 . pipe ( streamAssert . end ( ) ) ;
272276
273277 stream . write ( new gutil . File ( {
274278 base : __dirname ,
275- path : __dirname + '/ fixture.js',
279+ path : path . join ( __dirname , ' fixture.js') ,
276280 contents : new Buffer ( 'var x = 1,y = 2;' )
277281 } ) ) ;
278282
279283 stream . write ( new gutil . File ( {
280284 base : __dirname ,
281- path : __dirname + '/ passing.js',
285+ path : path . join ( __dirname , ' passing.js') ,
282286 contents : new Buffer ( 'var x = 1; var y = 2;' )
283287 } ) ) ;
284288
0 commit comments