Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pa11y-ci

Package Overview
Dependencies
Maintainers
7
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pa11y-ci - npm Package Compare versions

Comparing version 2.3.1 to 2.4.0

test/integration/cli-config.test.js

54

bin/pa11y-ci.js

@@ -19,7 +19,7 @@ #!/usr/bin/env node

const pkg = require('../package.json');
const program = require('commander');
const commander = require('commander');
// Here we're using Commander to specify the CLI options
program
commander
.version(pkg.version)

@@ -59,3 +59,3 @@ .usage('[options] <paths>')

// Parse the args into valid paths using glob and protocolify
const urls = globby.sync(program.args, {
const urls = globby.sync(commander.args, {
// Ensure not-found paths (like "google.com"), are returned

@@ -69,8 +69,8 @@ nonull: true

// Load config based on the `--config` flag
return loadConfig(program.config);
return loadConfig(commander.config);
})
.then(config => {
// Load a sitemap based on the `--sitemap` flag
if (program.sitemap) {
return loadSitemapIntoConfig(program, config);
if (commander.sitemap) {
return loadSitemapIntoConfig(commander, config);
}

@@ -85,3 +85,3 @@ return config;

// Output JSON if asked for it
if (program.json) {
if (commander.json) {
console.log(JSON.stringify(report, (key, value) => {

@@ -98,3 +98,3 @@ if (value instanceof Error) {

// errors are below threshold or everything passes
if (report.errors >= parseInt(program.threshold, 10) && report.passes < report.total) {
if (report.errors >= parseInt(commander.threshold, 10) && report.passes < report.total) {
process.exit(2);

@@ -129,3 +129,3 @@ } else {

}
if (program.config && !config) {
if (commander.config && !config) {
return reject(new Error(`The config file "${configPath}" could not be loaded`));

@@ -140,4 +140,4 @@ }

// Allow loaded configs to return a promise
Promise.resolve(config).then(config => {
resolve(defaultConfig(config || {}));
Promise.resolve(config).then(loadedConfig => {
resolve(defaultConfig(loadedConfig || {}));
});

@@ -203,3 +203,3 @@ });

config.defaults.wrapWidth = process.stdout.columns || undefined;
if (program.json) {
if (commander.json) {
delete config.defaults.log;

@@ -212,4 +212,3 @@ }

// URLs, and add them to an existing config object
function loadSitemapIntoConfig(program, config) {
const sitemapUrl = program.sitemap;
function loadSitemapIntoConfig(program, initialConfig) {
const sitemapFind = (

@@ -227,14 +226,18 @@ program.sitemapFind ?

return Promise.resolve()
.then(() => {
return fetch(sitemapUrl);
})
.then(response => {
return response.text();
})
function getUrlsFromSitemap(sitemapUrl, config) {
return Promise.resolve()
.then(() => fetch(sitemapUrl))
.then(response => response.text())
.then(body => {
const $ = cheerio.load(body, {
xmlMode: true
});
const $ = cheerio.load(body, {xmlMode: true});
const isSitemapIndex = $('sitemapindex').length > 0;
if (isSitemapIndex) {
return Promise.all($('sitemap > loc').toArray().map(element => {
return getUrlsFromSitemap($(element).text(), config);
})).then(configs => {
return configs.pop();
});
}
$('url > loc').toArray().forEach(element => {

@@ -259,2 +262,5 @@ let url = $(element).text();

});
}
return getUrlsFromSitemap(program.sitemap, initialConfig);
}

@@ -1,88 +0,96 @@

# Changelog
## 2.4.0 (2020-08-18)
* Adds support for parsing sitemapindex (Thanks @42tte)
* Better test coverage (Thanks @kkoskelin)
* Updated dependencies and devDependencies
* Less eslint warnings
* Restrict dependency upgrades to bugfixes to avoid potential breakages when updating or integrating with other apps
* Minor documentation improvements and fixes
## 2.3.1 (2020-08-17)
* Add missing puppeteer dependency
Add missing puppeteer dependency
## 2.3.0 (2019-05-14)
* Add useIncognitoBrowserContext option for test runs
* Add useIncognitoBrowserContext option for test runs
## 2.2.0 (2019-04-16)
* Allow loaded config to return promises
* Allow loaded config to return promises
## 2.1.1 (2018-04-24)
* Pin puppeteer at 1.0.0 to fix file URL issues
* Pin puppeteer at 1.0.0 to fix file URL issues
## 2.1.0 (2018-04-09)
* Respect the Pa11y `threshold` configuration option for individual urls when determining whether to pass or fail
* Respect the Pa11y `threshold` configuration option for individual urls when determining whether to pass or fail
## 2.0.1 (2018-03-14)
* Fix an issue with reporting null contexts
* Fix an issue with reporting null contexts
## 2.0.0 (2018-03-12)
* See the [migration guide](https://github.com/pa11y/pa11y-ci/blob/master/MIGRATION.md#migrating-from-10-to-20) for details
* See the [migration guide](https://github.com/pa11y/pa11y-ci/blob/master/MIGRATION.md#migrating-from-10-to-20) for details
## 1.3.1 (2017-12-06)
* Fix the way configurations are loaded
* Fix the way configurations are loaded
## 1.3.0 (2017-10-18)
* Add the ability to specify paths and URLs as command-line arguments
* Documentation updates
* Add the ability to specify paths and URLs as command-line arguments
* Documentation updates
## 1.2.0 (2017-06-02)
* Add the ability to make Pa11y CI perform POST requests
* Documentation and linting updates
* Add the ability to make Pa11y CI perform POST requests
* Documentation and linting updates
## 1.1.1 (2017-03-13)
* Update readme to document `--sitemap-exclude`
* Update readme to document `--sitemap-exclude`
## 1.1.0 (2017-03-11)
* Add a `--sitemap-exclude` parameter to the command-line interface
* Add a `--sitemap-exclude` parameter to the command-line interface
## 1.0.2 (2017-03-08)
* Use Pa11y 4.7.0+
* Use Pa11y 4.7.0+
## 1.0.1 (2017-03-08)
* Use default wrapWidth if process.stdout.columns is reported as 0
* Use default wrapWidth if process.stdout.columns is reported as 0
## 1.0.0 (2017-03-07)
* Initial stable release
* Initial stable release
## 0.5.0 pre-release (2016-12-16)
* Add and document the `verifyPage` option
* Add and document the `verifyPage` option
## 0.4.0 pre-release (2016-12-05)
* Exit with an error if config files have syntax errors
* Exit with an error if config files have syntax errors
## 0.3.1 pre-release (2016-11-30)
* Updates pa11y dependency to ^4.2
* Updates pa11y dependency to ^4.2
## 0.3.0 pre-release (2016-09-20)
* Add a `--threshold` parameter to the command-line interface
* Add a `--threshold` parameter to the command-line interface
## 0.2.0 pre-release (2016-07-26)
* Add support for find/replace in sitemap URLs
* Add support for find/replace in sitemap URLs
## 0.1.0 pre-release (2016-07-05)
* Initial release
* Initial release

@@ -18,2 +18,3 @@ //

/* istanbul ignore next */
// eslint-disable-next-line no-empty-function
const noop = () => {};

@@ -73,2 +74,26 @@

function processResults(results, reportConfig, url) {
const withinThreshold = reportConfig.threshold ?
results.issues.length <= reportConfig.threshold :
false;
let message = ` ${chalk.cyan('>')} ${url} - `;
if (results.issues.length && !withinThreshold) {
message += chalk.red(`${results.issues.length} errors`);
log.error(message);
report.results[url] = results.issues;
report.errors += results.issues.length;
} else {
message += chalk.green(`${results.issues.length} errors`);
if (withinThreshold) {
message += chalk.green(
` (within threshold of ${reportConfig.threshold})`
);
}
log.info(message);
report.results[url] = [];
report.passes += 1;
}
}
// This is the actual test runner, which the queue will

@@ -85,9 +110,6 @@ // execute on each of the URLs

}
config.browser = config.useIncognitoBrowserContext ?
await testBrowser.createIncognitoBrowserContext() :
testBrowser;
if (config.useIncognitoBrowserContext) {
config.browser = await testBrowser.createIncognitoBrowserContext();
} else {
config.browser = testBrowser;
}
// Run the Pa11y test on the current URL and add

@@ -97,22 +119,10 @@ // results to the report object

const results = await pa11y(url, config);
const withinThreshold = config.threshold ? results.issues.length <= config.threshold : false;
let message = ` ${chalk.cyan('>')} ${url} - `;
if (results.issues.length && !withinThreshold) {
message += chalk.red(`${results.issues.length} errors`);
log.error(message);
report.results[url] = results.issues;
report.errors += results.issues.length;
} else {
message += chalk.green(`${results.issues.length} errors`);
if (withinThreshold) {
message += chalk.green(` (within threshold of ${config.threshold})`);
}
log.info(message);
report.results[url] = [];
report.passes += 1;
}
processResults(results, config, url);
} catch (error) {
log.error(` ${chalk.cyan('>')} ${url} - ${chalk.red('Failed to run')}`);
report.results[url] = [error];
} finally {
if (config.useIncognitoBrowserContext) {
config.browser.close();
}
}

@@ -143,3 +153,5 @@ }

} else {
const context = (result.context ? result.context.replace(/\s+/g, ' ') : '[no context]');
const context = result.context ?
result.context.replace(/\s+/g, ' ') :
'[no context]';
log.error([

@@ -146,0 +158,0 @@ '',

{
"name": "pa11y-ci",
"version": "2.3.1",
"version": "2.4.0",
"description": "Pa11y CI is a CI-centric accessibility test runner, built using Pa11y",

@@ -21,19 +21,20 @@ "keywords": [],

"dependencies": {
"async": "^2.4.1",
"chalk": "^1.1.3",
"cheerio": "^0.22",
"commander": "^2.9.0",
"globby": "^6.1.0",
"lodash": "^4.17.4",
"node-fetch": "^1.7.0",
"pa11y": "^5.0.3",
"protocolify": "^2.0.0",
"puppeteer": "^1.15.0",
"wordwrap": "^1.0.0"
"async": "~2.6.3",
"chalk": "~1.1.3",
"cheerio": "~1.0.0-rc.3",
"commander": "~2.20.3",
"globby": "~6.1.0",
"lodash": "~4.17.20",
"node-fetch": "~2.6.0",
"pa11y": "~5.3.0",
"protocolify": "~3.0.0",
"puppeteer": "~1.20.0",
"wordwrap": "~1.0.0"
},
"devDependencies": {
"@rowanmanning/make": "^2.1.0",
"eslint": "^3.19.0",
"mocha": "^3.4.2",
"mocha": "^7.2.0",
"mockery": "^2.0.0",
"nyc": "^11.0.1",
"nyc": "^15.1.0",
"pa11y-lint-config": "^1.2.0",

@@ -40,0 +41,0 @@ "proclaim": "^3.4.4",

@@ -77,3 +77,3 @@

You can specify a default set of [pa11y configurations] that should be used for each test run. These should be added to a `default` object in your config. For example:
You can specify a default set of [pa11y configurations] that should be used for each test run. These should be added to a `defaults` object in your config. For example:

@@ -84,7 +84,5 @@ ```json

"timeout": 1000,
"page": {
"viewport": {
"width": 320,
"height": 480
}
"viewport": {
"width": 320,
"height": 480
}

@@ -91,0 +89,0 @@ },

@@ -16,3 +16,3 @@ 'use strict';

if (urlPath === '/sitemap.xml') {
if (urlPath.includes('.xml')) {
response.writeHead(200, {

@@ -19,0 +19,0 @@ 'Content-Type': 'text/xml'

@@ -9,6 +9,11 @@ 'use strict';

const mockBrowser = puppeteer.mockBrowser = {
close: sinon.stub()
};
const mockBrowser = (puppeteer.mockBrowser = {
close: sinon.stub(),
createIncognitoBrowserContext: sinon.spy(() => {
return {close: mockBrowser.createIncognitoBrowserContext.close};
})
});
mockBrowser.createIncognitoBrowserContext.close = sinon.stub();
puppeteer.launch.resolves(mockBrowser);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc