diff --git a/lib/modules/content/index.js b/lib/modules/content/index.js index bc3ec36a..17b4c943 100644 --- a/lib/modules/content/index.js +++ b/lib/modules/content/index.js @@ -60,15 +60,18 @@ module.exports = function FileContent(options) { })(); (function executeChecksAgainstFiles() { - async.eachSeries(patterns, (pattern, nextPattern) => { - async.eachSeries(fileManager.languageFiles, (file, nextFile) => { - fileManager.readFile(file, (err, contents) => { + const checkPatternAgainstFiles = (pattern, nextPattern) => { + const checkPatternAgainstLanguageFile = (file, nextFile) => { + const validateFileContents = (err, contents) => { if(err) { return nextFile(); } pattern.check(file, contents); - nextFile(); - }); - }, nextPattern); - }, done); + async.setImmediate(nextFile); + }; + fileManager.readFile(file, validateFileContents); + }; + async.eachSeries(fileManager.languageFiles, checkPatternAgainstLanguageFile, nextPattern); + }; + async.eachSeries(patterns, checkPatternAgainstFiles, done); })(); }; diff --git a/lib/modules/entropy/index.js b/lib/modules/entropy/index.js index f4640823..fc382c5a 100644 --- a/lib/modules/entropy/index.js +++ b/lib/modules/entropy/index.js @@ -46,7 +46,7 @@ module.exports = function Entropy(options) { } } } while (m); - nextFile(); + async.setImmediate(nextFile); }; (function executeChecksAgainstFiles() { diff --git a/test/modules/contents.js b/test/modules/contents.js index 319ef1a4..f0637c94 100644 --- a/test/modules/contents.js +++ b/test/modules/contents.js @@ -6,18 +6,19 @@ const should = require('should'); const FileManager = require('../../lib/fileManager'); describe('Contents', () => { - let contents, mockResults; + let contents, mockResults, fileManager; beforeEach(() => { mockResults = deride.stub(['low', 'medium', 'high', 'critical']); const nullLogger = deride.stub(['log', 'debug', 'error']); - const fileManager = new FileManager({ - target: path.join(__dirname, '../samples/nodejs'), - logger: nullLogger - }); contents = new Contents({ patterns: path.join(__dirname, '../samples/contents.js') }); + fileManager = deride.wrap(new FileManager({ + target: path.join(__dirname, '../samples/nodejs'), + logger: nullLogger + })); + should(contents.handles(fileManager)).eql(true); }); @@ -27,4 +28,11 @@ describe('Contents', () => { }); contents.run(mockResults, done); }); + + it('should not explode when there are more than 115 files', done => { + for(var x = 0; x < 3000; x++) { + fileManager.languageFiles.push(fileManager.languageFiles[1]); + } + contents.run(mockResults, done); + }); }); diff --git a/test/scan.js b/test/scan.js index 07842c86..80434702 100644 --- a/test/scan.js +++ b/test/scan.js @@ -38,4 +38,5 @@ describe('Scan', () => { done(); }); }); + });