Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Commit

Permalink
add XO
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 31, 2015
1 parent 4e82a40 commit 92d2bcf
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -8,7 +8,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[{package.json,*.yml}]
indent_size = 2

[*.md]
Expand Down
31 changes: 0 additions & 31 deletions .gitignore
@@ -1,32 +1 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

# WebStorm
.idea
*.idea
11 changes: 7 additions & 4 deletions audits.js
@@ -1,3 +1,7 @@
/* eslint-env phantomjs, browser */
/* globals axs */
'use strict';

/**
* Conducts audits using the Chrome Accessibility Tools and PhantomJS.
*/
Expand All @@ -21,7 +25,7 @@ console.error = function () {

// Need to polyfill bind...
webpage.onInitialized = function () {
webpage.injectJs(BIND_POLYFILL_PATH);
webpage.injectJs(BIND_POLYFILL_PATH);
};

webpage.settings.resourceTimeout = PAGE_TIMEOUT;
Expand All @@ -43,7 +47,7 @@ webpage.onError = opts.verbose ? function (err, trace) {

webpage.open(opts.url, function (status) {
if (status === 'fail') {
console.error('Couldn\'t load url: ' + opts.url);
console.error('Couldn\'t load url: ' + JSON.stringify(opts.url));
phantom.exit(1);
}

Expand Down Expand Up @@ -97,9 +101,8 @@ webpage.open(opts.url, function (status) {
// Must do crazy song and dance to get phantom to exit properly
// https://github.com/ariya/phantomjs/issues/12697
webpage.close();
setTimeout(function() {
setTimeout(function () {
phantom.exit();
}, 0);
}, opts.delay * 1000);

});
60 changes: 30 additions & 30 deletions cli.js
Expand Up @@ -37,45 +37,45 @@ if (cli.input.length === 0) {

// Parse the CLI input into valid paths using glob and protocolify.
var urls = globby.sync(cli.input, {
// Ensure not-found paths (like "google.com"), are returned.
nonull: true
// Ensure not-found paths (like "google.com"), are returned.
nonull: true
}).map(protocolify);

eachAsync(urls, function (url, i, next) {
a11y(url, cli.flags, function (err, reports) {
if (err) {
console.error(err.message);
process.exit(err.code || 1);
}
a11y(url, cli.flags, function (err, reports) {
if (err) {
console.error(err.message);
process.exit(err.code || 1);
}

if (cli.flags.verbose) {
console.log(reports);
return;
}
if (cli.flags.verbose) {
console.log(reports);
return;
}

var passes = '';
var failures = '';
var passes = '';
var failures = '';

console.log('');
console.log('');

if (!process.stdout.isTTY || urls.length > 1) {
console.log(chalk.underline(chalk.cyan(humanizeUrl(url) + '\n')));
}
if (!process.stdout.isTTY || urls.length > 1) {
console.log(chalk.underline(chalk.cyan(humanizeUrl(url) + '\n')));
}

reports.audit.forEach(function (el) {
if (el.result === 'PASS') {
passes += logSymbols.success + ' ' + el.heading + '\n';
}
reports.audit.forEach(function (el) {
if (el.result === 'PASS') {
passes += logSymbols.success + ' ' + el.heading + '\n';
}

if (el.result === 'FAIL') {
failures += logSymbols.error + ' ' + el.heading + '\n';
failures += el.elements + '\n\n';
}
});
if (el.result === 'FAIL') {
failures += logSymbols.error + ' ' + el.heading + '\n';
failures += el.elements + '\n\n';
}
});

console.log(indentString(failures, ' ', 2));
console.log(indentString(passes, ' ', 2));
console.log(indentString(failures, ' ', 2));
console.log(indentString(passes, ' ', 2));

next();
});
next();
});
});
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -17,12 +17,11 @@
}
],
"bin": "cli.js",
"preferGlobal": true,
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "ava test/test.js",
"test": "xo && ava test/test.js",
"demo": "./cli.js theverge.com"
},
"files": [
Expand Down Expand Up @@ -63,6 +62,10 @@
"update-notifier": "^0.5.0"
},
"devDependencies": {
"ava": "^0.1.0"
"ava": "*",
"xo": "*"
},
"xo": {
"space": 4
}
}
19 changes: 12 additions & 7 deletions test/test.js
Expand Up @@ -8,7 +8,7 @@ function auditsWithHeader(reports, header) {
return reports.audit.filter(function (aud) {
return aud.heading === header;
});
};
}

test('test that an empty URL fails', function (t) {
t.throws(function () {
Expand All @@ -25,47 +25,52 @@ test('fail if no callback is supplied', function (t) {
});

test('test local input generates a report if callback is second param', function (t) {
t.plan(2);
t.plan(3);

a11y('fixture.html', function (err, reports) {
t.error(err);
var ariaReports = auditsWithHeader(reports, 'ARIA state and property values must be valid');
t.is(ariaReports.length, 1);
t.is(ariaReports[0] && ariaReports[0].result, 'FAIL');
});
});

test('test local input generates a report if callback is third param', function (t) {
t.plan(2);
t.plan(3);

a11y('fixture.html', null, function (err, reports) {
t.error(err);
var ariaReports = auditsWithHeader(reports, 'ARIA state and property values must be valid');
t.is(ariaReports.length, 1);
t.is(ariaReports[0] && ariaReports[0].result, 'FAIL');
});
});

test('test local input generates a report requiring a delay', function (t) {
t.plan(2);
t.plan(3);

a11y('fixture.html', {delay: 5} , function (err, reports) {
a11y('fixture.html', {delay: 5}, function (err, reports) {
t.error(err);
var delayReports = auditsWithHeader(reports, 'role=main should only appear on significant elements');
t.is(delayReports.length, 1);
t.is(delayReports[0] && delayReports[0].result, 'FAIL');
});
});

test('test local input generates a verbose report', function (t) {
t.plan(1);
t.plan(2);

a11y('fixture.html', {verbose: true}, function (err, reports) {
t.error(err);
t.true(reports.report.indexOf('*** Begin accessibility audit results ***') !== -1);
});
});

test('test local input generates a report that includes all failures for a given violation', function (t) {
t.plan(2);
t.plan(3);

a11y('fixture.html', function (err, reports) {
t.error(err);
var matchingReports = auditsWithHeader(reports, 'This element has an unsupported ARIA attribute');
t.is(matchingReports.length, 1);
t.is(matchingReports[0] && matchingReports[0].elements.match(/\n/g).length, 6);
Expand Down

0 comments on commit 92d2bcf

Please sign in to comment.