|
| 1 | +/*! aXe-grunt-webdriver |
| 2 | + * Copyright (c) 2015 Deque Systems, Inc. |
| 3 | + * |
| 4 | + * Your use of this Source Code Form is subject to the terms of the Mozilla Public |
| 5 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 | + * |
| 8 | + * This entire copyright notice must appear in every copy of this file you |
| 9 | + * distribute or in any file that contains substantial portions of this source |
| 10 | + * code. |
| 11 | + */ |
| 12 | + |
| 13 | +'use strict'; |
| 14 | + |
| 15 | +module.exports = function( grunt ) { |
| 16 | + var WebDriver = require( "selenium-webdriver" ), |
| 17 | + AxeBuilder = require( "axe-webdriverjs" ), |
| 18 | + Promise = require( "promise" ), |
| 19 | + path = require( "path" ), |
| 20 | + reporter = require( "../lib/reporter" ); |
| 21 | + |
| 22 | + grunt.registerMultiTask( "axe-webdriver", "Grunt plugin for aXe utilizing WebDriverJS", function () { |
| 23 | + var options = this.options( { |
| 24 | + browser: "firefox", |
| 25 | + server: null, |
| 26 | + threshold: 0 |
| 27 | + } ); |
| 28 | + |
| 29 | + var done = this.async (); |
| 30 | + var driver = new WebDriver.Builder () |
| 31 | + .forBrowser( options.browser ) |
| 32 | + .build (); |
| 33 | + |
| 34 | + var dest = this.data.dest; |
| 35 | + Promise.all( this.data.urls.map( function( url ) { |
| 36 | + return new Promise( function( resolve, reject ) { |
| 37 | + |
| 38 | + driver |
| 39 | + .get( url ) |
| 40 | + .then( function() { |
| 41 | + new AxeBuilder( driver ) |
| 42 | + .analyze( function( results ) { |
| 43 | + results.url = url; |
| 44 | + resolve( results ); |
| 45 | + } ); |
| 46 | + } ); |
| 47 | + } ); |
| 48 | + })).then( function( results ) { |
| 49 | + if ( dest ) { |
| 50 | + grunt.file.write( dest, JSON.stringify( results, null, " " ) ); |
| 51 | + } |
| 52 | + var result = reporter( grunt, results, options.threshold ); |
| 53 | + driver.quit().then( function () { |
| 54 | + done( result ); |
| 55 | + } ); |
| 56 | + } ); |
| 57 | + } ); |
| 58 | +}; |
0 commit comments