Skip to content

Commit 07d78eb

Browse files
committed
refactor(gen:test:endpoint): refactor jshint into more generic testFile, add jscsCmd
1 parent 20cfbe6 commit 07d78eb

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/test/endpoint.test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,16 @@ function runEndpointGen(name, opt={}) {
9999

100100
gen
101101
.on('error', reject)
102-
.on('end', () => resolve(dir))
102+
.on('end', () => resolve(dir));
103103
});
104104
}
105105

106106
let jshintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/jshint');
107-
function jshint(_path, opt={}) {
107+
let jscsCmd = path.join(TEST_DIR, '/fixtures/node_modules/gulp-jscs/node_modules/.bin/jscs');
108+
function testFile(command, _path) {
108109
_path = path.normalize(_path);
109-
return fs.accessAsync(_path, fs.R_OK).then(err => {
110-
let {config} = opt;
111-
let cmd = `${jshintCmd} ${path.normalize(_path)}`;
112-
if(config) cmd += ` --config ${config}`;
113-
return runCmd(cmd);
110+
return fs.accessAsync(_path, fs.R_OK).then(() => {
111+
return runCmd(`${command} ${_path}`);
114112
});
115113
}
116114

@@ -120,11 +118,11 @@ function jshintDir(dir, name, folder) {
120118

121119
let regFiles = fs.readdirAsync(endpointDir)
122120
.then(files => files.filter(file => minimatch(file, '**/!(*.spec|*.mock|*.integration).js', {dot: true})))
123-
.map(file => jshint(path.join('./server/api/', folder, file)));
121+
.map(file => testFile(jshintCmd, path.join('./server/api/', folder, file)));
124122

125123
let specFiles = fs.readdirAsync(endpointDir)
126124
.then(files => files.filter(file => minimatch(file, '**/+(*.spec|*.mock|*.integration).js', {dot: true})))
127-
.map(file => jshint(path.join('./server/api/', folder, file), {config: 'server/.jshintrc-spec'}));
125+
.map(file => testFile(`${jshintCmd} --config server/.jshintrc-spec`, path.join('./server/api/', folder, file)));
128126

129127
return Promise.all([regFiles, specFiles]);
130128
}

0 commit comments

Comments
 (0)