Skip to content

Commit

Permalink
feat(multiple): analyze multiples files and save report with all the …
Browse files Browse the repository at this point in the history
…results
  • Loading branch information
felixzapata committed Aug 11, 2016
1 parent 30eac56 commit e86a5c0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 55 deletions.
40 changes: 20 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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);
Expand All @@ -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));
Expand Down
70 changes: 35 additions & 35 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
}

};

0 comments on commit e86a5c0

Please sign in to comment.