@@ -7,6 +7,9 @@ Promise.promisifyAll(fs);
7
7
import helpers from 'yeoman-test' ;
8
8
import assert from 'yeoman-assert' ;
9
9
import minimatch from 'minimatch' ;
10
+ import Checker from 'jscs' ;
11
+ const jscs = new Checker ( ) ;
12
+ jscs . registerDefaultRules ( ) ;
10
13
import * as getExpectedFiles from './get-expected-files' ;
11
14
import {
12
15
copyAsync ,
@@ -104,7 +107,6 @@ function runEndpointGen(name, opt={}) {
104
107
}
105
108
106
109
let 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' ) ;
108
110
function testFile ( command , _path ) {
109
111
_path = path . normalize ( _path ) ;
110
112
return fs . accessAsync ( _path , fs . R_OK ) . then ( ( ) => {
@@ -130,8 +132,23 @@ function jscsDir(dir, name, folder) {
130
132
if ( ! folder ) folder = name ;
131
133
let endpointDir = path . join ( dir , 'server/api' , folder ) ;
132
134
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
+ } ) ;
135
152
}
136
153
137
154
var config ;
@@ -141,6 +158,10 @@ before(function() {
141
158
return Promise . all ( [
142
159
runGen ( defaultOptions ) . then ( _dir => {
143
160
genDir = _dir ;
161
+
162
+ return fs . readFileAsync ( path . join ( genDir , '.jscsrc' ) , 'utf8' ) . then ( data => {
163
+ jscs . configure ( JSON . parse ( data ) ) ;
164
+ } ) ;
144
165
} ) ,
145
166
getConfig ( path . join ( TEST_DIR , 'fixtures/.yo-rc.json' ) ) . then ( _config => {
146
167
_config [ 'generator-angular-fullstack' ] . insertRoutes = false ;
0 commit comments