Skip to content

Commit

Permalink
feat: utilizing firefox and webkit browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
JakePartusch committed Feb 9, 2020
1 parent 012f6ce commit aef6931
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 13 deletions.
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,40 @@

# About

Lumberjack runs [aXe](https://www.deque.com/axe/) accessibility checks on your entire website!
Lumberjack runs [axe](https://www.deque.com/axe/) accessibility checks on your entire website!

- Lumberjack reads your website's sitemap
- It spawns multiple Chromium instances and gets to scanning
- Finally, the results are aggregated and reported back
- Reads your website's sitemap
- Spawns multiple browser instances and starts scanning with axe
- Aggregates results and reports back

# Usage

## CLI

NPX (recommended for a single run)

```
npx @jakepartusch/lumberjack --url https://google.com
```

Global Install (recommended for multiple runs)

```
npm install -g @jakepartusch/lumberjack
lumberjack --url https://google.com
```

## JavaScript (Node.js)

```
npm install @jakepartusch/lumberjack
```

```
const lumberjack = require('@jakepartusch/lumberjack');
const myFunction = async () => {
const results = await lumberjack("https://google.com")
console.log(results);
}
```
29 changes: 21 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { chromium } = require("playwright");
const { firefox, chromium, webkit } = require("playwright");
const Sitemapper = require("sitemapper");
const { chunks } = require("./src/util");

Expand All @@ -15,8 +15,7 @@ const fetchSitemapUrls = async baseUrl => {
return sites.slice(0, maxSites);
};

const runAccessibilityTestsOnUrl = async url => {
const browser = await chromium.launch();
const runAccessibilityTestsOnUrl = async (url, browser) => {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(url);
Expand All @@ -43,31 +42,45 @@ const runAccessibilityTestsOnUrl = async url => {
}))
};
});
await browser.close();
return { url, ...axeViolations };
};

const runAllChecks = async (urls, spinner) => {
const chunkedUrls = [...chunks(urls, 5)];
const chunkedUrls = [...chunks(urls, 3)];
const totalViolationsByPage = [];
for (const urlChunk of chunkedUrls) {
if (spinner) {
spinner.text = `Running accessibility checks... (${totalViolationsByPage.length ||
1} of ${urls.length} pages)`;
}
const browserPromises = [
chromium.launch(),
firefox.launch(),
webkit.launch()
];
const browsers = await Promise.all(browserPromises);
const violationPromises = [];
for (const url of urlChunk) {
violationPromises.push(runAccessibilityTestsOnUrl(url));
for (let i = 0; i < urlChunk.length; i++) {
const url = urlChunk[i];
const browser = browsers[i];
violationPromises.push(runAccessibilityTestsOnUrl(url, browser));
}
const resolvedViolationsByPage = await Promise.all(violationPromises);

const closedBrowserPromises = [];
for (const browser of browsers) {
closedBrowserPromises.push(browser.close());
}
await Promise.all(closedBrowserPromises);
totalViolationsByPage.push(...resolvedViolationsByPage);
}
return totalViolationsByPage;
};

const lumberjack = async (baseUrl, spinner) => {
const sitemapUrls = await fetchSitemapUrls(baseUrl);
return runAllChecks(sitemapUrls, spinner);
const results = runAllChecks(sitemapUrls, spinner);
return results;
};

module.exports = lumberjack;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jakepartusch/lumberjack",
"version": "0.2.0",
"version": "0.3.0",
"description": "Scans your entire website for accessibility issues",
"main": "index.js",
"bin": "./bin/cli.js",
Expand Down

0 comments on commit aef6931

Please sign in to comment.