Skip to content

Commit

Permalink
feat(index.js): use webdriver to call the API
Browse files Browse the repository at this point in the history
  • Loading branch information
felixzapata committed Aug 8, 2016
1 parent c27c932 commit 99de412
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
'use strict';
var gutil = require('gulp-util');
var vm = require('vm');
var fs = require('fs');
var through = require('through2');
var cheerio = require('cheerio');
var DOMParser = require('xmldom').DOMParser;
var context;
//var axe = require(__dirname + '/node_modules/axe-core/axe.min.js');
var axe = require('axe-core');
var AxeBuilder = require('axe-webdriverjs');
var WebDriver = require('selenium-webdriver');
var PLUGIN_NAME = 'gulp-axe-core';

//vm.runInThisContext(fs.readFileSync(__dirname + '/node_modules/axe-core/axe.js'));

//vm.runInThisContext(axe);
var driver = new WebDriver.Builder()
.forBrowser('firefox')
.build();

module.exports = function (options) {
/*if (!options.foo) {
throw new gutil.PluginError('gulp-axe-core', '`foo` required');
}*/


return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-axe-core', 'Streaming not supported'));
cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
return;
}

try {

//context = cheerio.load(file.contents.toString());
//context = file.contents.toString();
context = new DOMParser().parseFromString(file.contents.toString(), 'text/html');

//file.contents = new Buffer(axe.a11yCheck(context.firstChild, options));
//this.push(file);

//console.log(context.documentElement.attributes['0'].ownerDocument)

//console.log(context);

axe.a11yCheck(context, null, function(result) {
console.log(result);
});
driver
.get(file.path)
.then(function () {
AxeBuilder(driver)
.analyze(function (results) {
console.log(results);
});
});

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

cb();
Expand Down

0 comments on commit 99de412

Please sign in to comment.