diff --git a/index.js b/index.js index f2d01fb..198deb6 100644 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ var reporter = require('./lib/reporter'); var PLUGIN_NAME = 'gulp-axe-core'; var promise; -var promises = []; +var results = []; module.exports = function (customOptions) { @@ -27,21 +27,18 @@ module.exports = function (customOptions) { var driver = new WebDriver.Builder().forBrowser(options.browser).build(); var createResults = function(cb) { - Promise.all(promises).then(function(results) { - var dest = ''; - if(options.saveOutputIn !== '') { - dest = path.join(options.folderOutputReport, options.saveOutputIn); - fs.writeFileSync(dest, JSON.stringify(results, null, ' ')); - } - reporter(results, options.threshold); - driver.quit(); - cb(); - }); + + var dest = ''; + if(options.saveOutputIn !== '') { + dest = path.join(options.folderOutputReport, options.saveOutputIn); + fs.writeFileSync(dest, JSON.stringify(results, null, ' ')); + } + driver.quit(); + cb(); + }; var bufferContents = function (file, enc, cb) { - - promises = []; if (file.isNull()) { cb(null, file); @@ -58,18 +55,21 @@ module.exports = function (customOptions) { driver.get(fileUrl(file.path)).then(function() { var startTimestamp = new Date().getTime(); new AxeBuilder(driver) - .analyze(function(results) { - results.url = file.path; - results.timestamp = new Date().getTime(); - results.time = results.timestamp - startTimestamp; - resolve(results); + .analyze(function(result) { + result.url = file.path; + result.timestamp = new Date().getTime(); + result.time = result.timestamp - startTimestamp; + resolve(result); }); }); }); - promises.push(promise); + promise.then(function(result) { + results.push(result); + reporter(result, options.threshold); + cb(); + }); - cb(); } catch (err) { this.emit('error', new gutil.PluginError(PLUGIN_NAME, err)); diff --git a/lib/reporter.js b/lib/reporter.js index f75ddd9..73027d1 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -6,43 +6,43 @@ function color(code, str) { return '\u001b[' + code + 'm' + str + '\u001b[0m'; } -module.exports = function(results, threshold) { - results.forEach(function(result) { - gutil.log(gutil.colors.cyan('File to test: ' + result.url)); - var violations = result.violations; - if (violations.length) { - if (threshold < 0) { - gutil.log(gutil.colors.green('Found ' + violations.length + ' accessibility violations: (no threshold)')); - } else if (violations.length > threshold) { - gutil.log(gutil.colors.red('Found ' + violations.length + ' accessibility violations:')); - } else { - gutil.log(gutil.colors.green('Found ' + violations.length + ' accessibility violations: (under threshold of ' + threshold + ')')); - } - violations.forEach(function(ruleResult) { - gutil.log(' ' + color(31, '\u00D7') + ' ' + ruleResult.help); +module.exports = function(result, threshold) { + + var violations = result.violations; + gutil.log(gutil.colors.cyan('File to test: ' + result.url)); + if (violations.length) { + if (threshold < 0) { + gutil.log(gutil.colors.green('Found ' + violations.length + ' accessibility violations: (no threshold)')); + } else if (violations.length > threshold) { + gutil.log(gutil.colors.red('Found ' + violations.length + ' accessibility violations:')); + } else { + gutil.log(gutil.colors.green('Found ' + violations.length + ' accessibility violations: (under threshold of ' + threshold + ')')); + } + violations.forEach(function(ruleResult) { + gutil.log(' ' + color(31, '\u00D7') + ' ' + ruleResult.help); - ruleResult.nodes.forEach(function(violation, index) { - gutil.log(' ' + (index + 1) + '. ' + JSON.stringify(violation.target)); + ruleResult.nodes.forEach(function(violation, index) { + gutil.log(' ' + (index + 1) + '. ' + JSON.stringify(violation.target)); - if (violation.any.length) { - gutil.log(' Fix any of the following:'); - violation.any.forEach(function(check) { - gutil.log(' \u2022 ' + check.message); - }); - } + if (violation.any.length) { + gutil.log(' Fix any of the following:'); + violation.any.forEach(function(check) { + gutil.log(' \u2022 ' + check.message); + }); + } - var alls = violation.all.concat(violation.none); - if (alls.length) { - gutil.log(' Fix all of the following:'); - alls.forEach(function(check) { - gutil.log(' \u2022 ' + check.message); - }); - } - gutil.log('\n'); - }); + var alls = violation.all.concat(violation.none); + if (alls.length) { + gutil.log(' Fix all of the following:'); + alls.forEach(function(check) { + gutil.log(' \u2022 ' + check.message); + }); + } + gutil.log('\n'); }); - } else { - gutil.log(gutil.colors.green('Found no accessibility violations.')); - } - }); + }); + } else { + gutil.log(gutil.colors.green('Found no accessibility violations.')); + } + }; \ No newline at end of file