Skip to content

Commit

Permalink
feat(promises): resolve every promise and show the results
Browse files Browse the repository at this point in the history
  • Loading branch information
felixzapata committed Aug 9, 2016
1 parent 2f08f6f commit 5dc6d3c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,23 @@ module.exports = function (customOptions) {
});
});

promises.push(promise);
//promises.push(promise);

promise.then(function(results){
if(options.createReportFile) {
fs.writeFileSync(dest, JSON.stringify(results, null, ' '));
}
result = reporter(results, options.threshold);
}).catch(cb);

driver.quit().then(function() {
cb(result);
});

} catch (err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, err));
}
cb();

};
return through.obj(bufferContents, createResults);
return through.obj(bufferContents);
};
73 changes: 35 additions & 38 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,44 @@ function color(code, str) {
return '\u001b[' + code + 'm' + str + '\u001b[0m';
}

module.exports = function(results, threshold) {
module.exports = function(result, threshold) {
var pass = true;
results.forEach(function(result) {
console.log(result.url);
var violations = result.violations;
if (violations.length) {
if (threshold < 0) {
console.log(chalk.green('Found ' + violations.length + ' accessibility violations: (no threshold)'));
} else if (violations.length > threshold) {
pass = false;
console.log(chalk.red('Found ' + violations.length + ' accessibility violations:'));
} else {
console.log(chalk.green('Found ' + violations.length + ' accessibility violations: (under threshold of ' + threshold + ')'));
}
violations.forEach(function(ruleResult) {
console.log(' ' + color(31, '\u00D7') + ' ' + ruleResult.help);
console.log(result.url);
var violations = result.violations;
if (violations.length) {
if (threshold < 0) {
console.log(chalk.green('Found ' + violations.length + ' accessibility violations: (no threshold)'));
} else if (violations.length > threshold) {
pass = false;
console.log(chalk.red('Found ' + violations.length + ' accessibility violations:'));
} else {
console.log(chalk.green('Found ' + violations.length + ' accessibility violations: (under threshold of ' + threshold + ')'));
}
violations.forEach(function(ruleResult) {
console.log(' ' + color(31, '\u00D7') + ' ' + ruleResult.help);

ruleResult.nodes.forEach(function(violation, index) {
console.log(' ' + (index + 1) + '. ' + JSON.stringify(violation.target));
ruleResult.nodes.forEach(function(violation, index) {
console.log(' ' + (index + 1) + '. ' + JSON.stringify(violation.target));

if (violation.any.length) {
console.log(' Fix any of the following:');
violation.any.forEach(function(check) {
console.log(' \u2022 ' + check.message);
});
}

var alls = violation.all.concat(violation.none);
if (alls.length) {
console.log(' Fix all of the following:');
alls.forEach(function(check) {
console.log(' \u2022 ' + check.message);
});
}
console.log('\n');
});
});
} else {
console.log(chalk.green('Found no accessibility violations.'));
}
});
if (violation.any.length) {
console.log(' Fix any of the following:');
violation.any.forEach(function(check) {
console.log(' \u2022 ' + check.message);
});
}

var alls = violation.all.concat(violation.none);
if (alls.length) {
console.log(' Fix all of the following:');
alls.forEach(function(check) {
console.log(' \u2022 ' + check.message);
});
}
console.log('\n');
});
});
} else {
console.log(chalk.green('Found no accessibility violations.'));
}
return pass;
};

0 comments on commit 5dc6d3c

Please sign in to comment.