Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6faa7f0

Browse filesBrowse files
committed
perf(test:endpoint): reduce number of eslint commands run
1 parent 0e690a3 commit 6faa7f0
Copy full SHA for 6faa7f0

File tree

1 file changed

+18
-11
lines changed
Filter options

1 file changed

+18
-11
lines changed

‎src/test/endpoint.test.js

Copy file name to clipboardExpand all lines: src/test/endpoint.test.js
+18-11
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,34 @@ function runEndpointGen(name, opt={}) {
6767
});
6868
}
6969

70-
let eslintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/eslint');
71-
function testFile(command, _path) {
72-
_path = path.normalize(_path);
73-
return fs.accessAsync(_path, fs.R_OK).then(() => {
74-
return runCmd(`${command} ${_path}`);
75-
});
70+
const ESLINT_CMD = path.join(TEST_DIR, '/fixtures/node_modules/.bin/eslint');
71+
72+
/**
73+
* @param {string[]} files
74+
* @param {string} [flags]
75+
*/
76+
function eslintFiles(files, flags = '') {
77+
return runCmd(`${ESLINT_CMD} ${flags} ${files.join(' ')}`);
7678
}
7779

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

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

86-
let specFiles = fs.readdirAsync(endpointDir)
89+
let specFiles = files
8790
.then(files => files.filter(file => minimatch(file, '**/+(*.spec|*.mock|*.integration).js', {dot: true})))
88-
.map(file => testFile(`${eslintCmd} --env node,es6,mocha --global sinon,expect`, path.join('./server/api/', folder, file)));
91+
.then(files => files.map(file => path.join('./server/api/', folder, file)));
92+
93+
let regLint = regFiles.then(files => eslintFiles(files));
94+
95+
let specLint = specFiles.then(files => eslintFiles(files, '--env node,es6,mocha --global sinon,expect'));
8996

90-
return Promise.all([regFiles, specFiles]);
97+
return Promise.all([regLint, specLint]);
9198
}
9299

93100
var config;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.