lib/pa11y.js
async function pa11y(url, options = {}, callback) {
	const state = {};

	/* eslint-disable prefer-rest-params */
	// Check for presence of a callback function
	if (typeof arguments[arguments.length - 1] === 'function') {
		callback = arguments[arguments.length - 1];
	} else {
		callback = undefined;
	}
	/* eslint-enable prefer-rest-params */

	try {

		// Switch parameters if only an options object is provided,
		// and default the options
		if (typeof url !== 'string') {
			options = url;
			url = options.url;
		}
		url = sanitizeUrl(url);
		options = defaultOptions(options);

		// Verify that the given options are valid
		verifyOptions(options);

		// Call the actual Pa11y test runner with
		// a timeout if it takes too long
		const results = await promiseTimeout(
			runPa11yTest(url, options, state),
			options.timeout,
			`Pa11y timed out (${options.timeout}ms)`
		);

		// Run callback if present, and resolve with results
		if (callback) {
			return callback(null, results);
		}
		return results;

	} catch (error) {
		if (state.browser && state.autoClose) {
			state.browser.close();
		} else if (state.page && state.autoClosePage) {
			state.page.close();
		}

		// Run callback if present, and reject with error
		if (callback) {
			return callback(error);
		}
		throw error;
	}
}
async function pa11y(url, options = {}, callback) {
	const state = {};

	/* eslint-disable prefer-rest-params */
	// Check for presence of a callback function
	if (typeof arguments[arguments.length - 1] === 'function') {
		callback = arguments[arguments.length - 1];
	} else {
		callback = undefined;
	}
	/* eslint-enable prefer-rest-params */

	try {

		// Switch parameters if only an options object is provided,
		// and default the options
		if (typeof url !== 'string') {
			options = url;
			url = options.url;
		}
		url = sanitizeUrl(url);
		options = defaultOptions(options);

		// Verify that the given options are valid
		verifyOptions(options);

		// Call the actual Pa11y test runner with
		// a timeout if it takes too long
		const results = await promiseTimeout(
			runPa11yTest(url, options, state),
			options.timeout,
			`Pa11y timed out (${options.timeout}ms)`
		);

		// Run callback if present, and resolve with results
		if (callback) {
			return callback(null, results);
		}
		return results;

	} catch (error) {
		if (state.browser && state.autoClose) {
			state.browser.close();
		} else if (state.page && state.autoClosePage) {
			state.page.close();
		}

		// Run callback if present, and reject with error
		if (callback) {
			return callback(error);
		}
		throw error;
	}
}
async function pa11y ( url , options = { } , callback ) { const state = { } ; /* eslint-disable prefer-rest-params */ // Check for presence of a callback function if ( typeof arguments [ arguments . length - 1 ] === 'function' ) { callback = arguments [ arguments . length - 1 ] ; } else { callback = undefined ; } /* eslint-enable prefer-rest-params */ try { // Switch parameters if only an options object is provided, // and default the options if ( typeof url !== 'string' ) { options = url ; url = options . url ; } url = sanitizeUrl ( url ) ; options = defaultOptions ( options ) ; // Verify that the given options are valid verifyOptions ( options ) ; // Call the actual Pa11y test runner with // a timeout if it takes too long const results = await promiseTimeout ( runPa11yTest ( url , options , state ) , options . timeout , ` ${ options . timeout } ` ) ; // Run callback if present, and resolve with results if ( callback ) { return callback ( null , results ) ; } return results ; } catch ( error ) { if ( state . browser && state . autoClose ) { state . browser . close ( ) ; } else if ( state . page && state . autoClosePage ) { state . page . close ( ) ; } // Run callback if present, and reject with error if ( callback ) { return callback ( error ) ; } throw error ; } }
Run accessibility tests on a web page.
@public
@param {String} [url] - The URL to run tests against.
@param {Object} [options={}] - Options to change the way tests run.
@param {Function} [callback] - An optional callback to use instead of promises.
@returns {Promise} Returns a promise which resolves with a results object.
Run accessibility tests on a web page .