Skip to content

Commit

Permalink
feat(index.js): resolve all promises to save a file with all the results
Browse files Browse the repository at this point in the history
  • Loading branch information
felixzapata committed Aug 9, 2016
1 parent 180b9a0 commit a91f091
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
var gutil = require('gulp-util');
var through = require('through2');
var fileUrl = require('file-url');
var fs = require('fs-extra');
var AxeBuilder = require('axe-webdriverjs');
var WebDriver = require('selenium-webdriver');
var Promise = require('promise');
var reporter = require('./lib/reporter');
var PLUGIN_NAME = 'gulp-axe-core';

var promise;
var promises = [];
var url = '';
var result;

module.exports = function (customOptions) {

var createResults = function(cb) {
Promise.all(promises).then(function(results) {
if(options.createReportFile) {
fs.writeFileSync(dest, JSON.stringify(results, null, ' '));
if(options.saveOutputIn !== '') {
fs.writeFileSync(options.saveOutputIn, JSON.stringify(results, null, ' '), { encoding: 'utf8' });
}
result = reporter(results, options.threshold);
driver.quit().then(function() {
Expand All @@ -29,7 +31,7 @@ module.exports = function (customOptions) {
var defaultOptions = {
browser: 'firefox',
server: null,
createReportFile: false,
saveOutputIn: '',
threshold: 0
};

Expand Down Expand Up @@ -64,20 +66,14 @@ module.exports = function (customOptions) {
});
});

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

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

cb();

};
return through.obj(bufferContents);
return through.obj(bufferContents, createResults);
};

0 comments on commit a91f091

Please sign in to comment.