Comparing version 2.3.1 to 2.4.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
66697
60
1489
8
208
+ Addedcheerio@1.0.0(transitive)
+ Addedcheerio-select@2.1.0(transitive)
+ Addedcss-select@5.1.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddom-serializer@2.0.0(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addeddomhandler@5.0.3(transitive)
+ Addeddomutils@3.1.0(transitive)
+ Addedencoding-sniffer@0.2.0(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedfile-url@3.0.0(transitive)
+ Addedhtmlparser2@9.1.0(transitive)
+ Addednode-fetch@2.6.13(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedparse5@7.2.1(transitive)
+ Addedparse5-htmlparser2-tree-adapter@7.1.0(transitive)
+ Addedparse5-parser-stream@7.1.2(transitive)
+ Addedprepend-http@3.0.1(transitive)
+ Addedprotocolify@3.0.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedundici@6.21.0(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-encoding@3.1.1(transitive)
+ Addedwhatwg-mimetype@4.0.0(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedcheerio@0.22.0(transitive)
- Removedcss-select@1.2.0(transitive)
- Removedcss-what@2.1.3(transitive)
- Removeddom-serializer@0.1.1(transitive)
- Removeddomelementtype@1.3.1(transitive)
- Removeddomhandler@2.4.2(transitive)
- Removeddomutils@1.5.1(transitive)
- Removedencoding@0.1.13(transitive)
- Removedentities@1.1.2(transitive)
- Removedfile-url@2.0.2(transitive)
- Removedhtmlparser2@3.10.1(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedlodash.assignin@4.2.0(transitive)
- Removedlodash.bind@4.2.1(transitive)
- Removedlodash.defaults@4.2.0(transitive)
- Removedlodash.filter@4.6.0(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedlodash.foreach@4.5.0(transitive)
- Removedlodash.map@4.6.0(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedlodash.pick@4.4.0(transitive)
- Removedlodash.reduce@4.6.0(transitive)
- Removedlodash.reject@4.6.0(transitive)
- Removedlodash.some@4.6.0(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removednth-check@1.0.2(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedprotocolify@2.0.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
Updatedasync@~2.6.3
Updatedchalk@~1.1.3
Updatedcheerio@~1.0.0-rc.3
Updatedcommander@~2.20.3
Updatedglobby@~6.1.0
Updatedlodash@~4.17.20
Updatednode-fetch@~2.6.0
Updatedpa11y@~5.3.0
Updatedprotocolify@~3.0.0
Updatedpuppeteer@~1.20.0
Updatedwordwrap@~1.0.0