Skip to content

Commit

Permalink
perf(test:endpoint): reduce number of eslint commands run
Browse files Browse the repository at this point in the history
  • Loading branch information
Awk34 committed Jan 25, 2017
1 parent 0e690a3 commit 6faa7f0
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/test/endpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,34 @@ function runEndpointGen(name, opt={}) {
});
}

let eslintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/eslint');
function testFile(command, _path) {
_path = path.normalize(_path);
return fs.accessAsync(_path, fs.R_OK).then(() => {
return runCmd(`${command} ${_path}`);
});
const ESLINT_CMD = path.join(TEST_DIR, '/fixtures/node_modules/.bin/eslint');

/**
* @param {string[]} files
* @param {string} [flags]
*/
function eslintFiles(files, flags = '') {
return runCmd(`${ESLINT_CMD} ${flags} ${files.join(' ')}`);
}

function eslintDir(dir, name, folder) {
if(!folder) folder = name;
let endpointDir = path.join(dir, 'server/api', folder);
let files = fs.readdirAsync(endpointDir);

let regFiles = fs.readdirAsync(endpointDir)
let regFiles = files
.then(files => files.filter(file => minimatch(file, '**/!(*.spec|*.mock|*.integration).js', {dot: true})))
.map(file => testFile(eslintCmd, path.join('./server/api/', folder, file)));
.then(files => files.map(file => path.join('./server/api/', folder, file)));

let specFiles = fs.readdirAsync(endpointDir)
let specFiles = files
.then(files => files.filter(file => minimatch(file, '**/+(*.spec|*.mock|*.integration).js', {dot: true})))
.map(file => testFile(`${eslintCmd} --env node,es6,mocha --global sinon,expect`, path.join('./server/api/', folder, file)));
.then(files => files.map(file => path.join('./server/api/', folder, file)));

let regLint = regFiles.then(files => eslintFiles(files));

let specLint = specFiles.then(files => eslintFiles(files, '--env node,es6,mocha --global sinon,expect'));

return Promise.all([regFiles, specFiles]);
return Promise.all([regLint, specLint]);
}

var config;
Expand Down

0 comments on commit 6faa7f0

Please sign in to comment.