@@ -7,6 +7,9 @@ Promise.promisifyAll(fs);
77import helpers from 'yeoman-test' ;
88import assert from 'yeoman-assert' ;
99import minimatch from 'minimatch' ;
10+ import Checker from 'jscs' ;
11+ const jscs = new Checker ( ) ;
12+ jscs . registerDefaultRules ( ) ;
1013import * as getExpectedFiles from './get-expected-files' ;
1114import {
1215 copyAsync ,
@@ -104,7 +107,6 @@ function runEndpointGen(name, opt={}) {
104107}
105108
106109let jshintCmd = path . join ( TEST_DIR , '/fixtures/node_modules/.bin/jshint' ) ;
107- let jscsCmd = path . join ( TEST_DIR , '/fixtures/node_modules/gulp-jscs/node_modules/.bin/jscs' ) ;
108110function testFile ( command , _path ) {
109111 _path = path . normalize ( _path ) ;
110112 return fs . accessAsync ( _path , fs . R_OK ) . then ( ( ) => {
@@ -130,8 +132,23 @@ function jscsDir(dir, name, folder) {
130132 if ( ! folder ) folder = name ;
131133 let endpointDir = path . join ( dir , 'server/api' , folder ) ;
132134
133- return fs . readdirAsync ( endpointDir )
134- . map ( file => testFile ( jscsCmd , path . join ( './server/api/' , folder , file ) ) ) ; ;
135+ return fs . readdirAsync ( endpointDir ) . then ( files => {
136+ return Promise . map ( files , file => {
137+ return fs . readFileAsync ( path . join ( 'server/api' , folder , file ) , 'utf8' ) . then ( data => {
138+ let results = jscs . checkString ( data )
139+ let errors = results . getErrorList ( ) ;
140+ if ( errors . length === 0 ) {
141+ return Promise . resolve ( ) ;
142+ } else {
143+ errors . forEach ( error => {
144+ var colorizeOutput = true ;
145+ console . log ( results . explainError ( error , colorizeOutput ) + '\n' ) ;
146+ } ) ;
147+ return Promise . reject ( ) ;
148+ }
149+ } ) ;
150+ } ) ;
151+ } ) ;
135152}
136153
137154var config ;
@@ -141,6 +158,10 @@ before(function() {
141158 return Promise . all ( [
142159 runGen ( defaultOptions ) . then ( _dir => {
143160 genDir = _dir ;
161+
162+ return fs . readFileAsync ( path . join ( genDir , '.jscsrc' ) , 'utf8' ) . then ( data => {
163+ jscs . configure ( JSON . parse ( data ) ) ;
164+ } ) ;
144165 } ) ,
145166 getConfig ( path . join ( TEST_DIR , 'fixtures/.yo-rc.json' ) ) . then ( _config => {
146167 _config [ 'generator-angular-fullstack' ] . insertRoutes = false ;
0 commit comments