Skip to content

Commit 93d7cb6

Browse files
committed
test(gen:endpont): use jscs programmatically
1 parent 5389c14 commit 93d7cb6

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"gulp-plumber": "^1.1.0",
7373
"gulp-util": "^3.0.7",
7474
"jit-grunt": "~0.10.0",
75+
"jscs": "^3.0.3",
7576
"lazypipe": "^1.0.1",
7677
"merge-stream": "^1.0.0",
7778
"minimatch": "^3.0.0",

Diff for: src/test/endpoint.test.js

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Promise.promisifyAll(fs);
77
import helpers from 'yeoman-test';
88
import assert from 'yeoman-assert';
99
import minimatch from 'minimatch';
10+
import Checker from 'jscs';
11+
const jscs = new Checker();
12+
jscs.registerDefaultRules();
1013
import * as getExpectedFiles from './get-expected-files';
1114
import {
1215
copyAsync,
@@ -104,7 +107,6 @@ function runEndpointGen(name, opt={}) {
104107
}
105108

106109
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');
108110
function 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

137154
var 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;

Diff for: templates/app/.jscsrc

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"excludeFiles": [
33
"client/app/app.constant.js"
44
],
5-
"esnext": true,
65
"maximumLineLength": {
76
"value": 100,
87
"allowComments": true,

0 commit comments

Comments
 (0)