Skip to content

Commit

Permalink
One more test
Browse files Browse the repository at this point in the history
  • Loading branch information
kodster28 committed Aug 30, 2023
1 parent 1a7f114 commit b0f9bdb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/accessibility-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
node-version: 18.1

- name: Install dependencies
run: npm install @actions/core pa11y axios xml2js
run: npm install @actions/core pa11y puppeteer

- name: Run accessibility test
id: test-accessibility
Expand Down
26 changes: 0 additions & 26 deletions .github/workflows/accessilibity-audit-2.yml

This file was deleted.

71 changes: 36 additions & 35 deletions bin/accessibility-check.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import pa11y from "pa11y";
import axios from "axios";
import { parseString } from 'xml2js';
import puppeteer from "puppeteer";
import core from "@actions/core";

process.on('warning', e => console.warn(e.stack));
const navigationTimeout = 120000; // Set the navigation timeout to 120 seconds (120,000 milliseconds)

const sitemapUrl = 'https://developers.cloudflare.com/sitemap.xml';
const urlsToProcess = []; // Array to store URLs for processing
async function checkLinks() {
const browser = await puppeteer.launch({
headless: "new",
});
const page = await browser.newPage();

async function processUrl(url) {
try {
const results = await pa11y(url);
console.log(results);
} catch (error) {
console.log("error");
const sitemapUrl = "https://developers.cloudflare.com/sitemap.xml";
await page.goto(sitemapUrl, { timeout: navigationTimeout });

const sitemapLinks = await page.$$eval("url loc", (elements) =>
elements.map((el) => el.textContent)
);

const visitedLinks = [];
const brokenLinks = [];

for (const link of sitemapLinks) {
if (!link) {
continue; // Skip if the link is empty
}
}

axios.get(sitemapUrl)
.then(response => {
if (response.status === 200) {
parseString(response.data, (err, result) => {
if (err) {
console.error('Error parsing XML:', err);
return;
}

const urls = result.urlset.url.map(urlObj => urlObj.loc[0]);
urlsToProcess.push(...urls); // Add individual URLs to the array
});
} else {
console.error('Failed to fetch sitemap. Status code:', response.status);
}
})
.catch(error => {
console.error('An error occurred:', error);

const page2 = await browser.newPage()
const result = await pa11y(link, {
browser,
page: page2
})
.finally(() => {
// Process the URLs after the response has been handled
urlsToProcess.forEach(processUrl);
});

console.log(result);
await page2.close();
}
await page.close();
await browser.close();
}


checkLinks();

0 comments on commit b0f9bdb

Please sign in to comment.