Skip to content

Commit

Permalink
fix: \n ignored in links
Browse files Browse the repository at this point in the history
  • Loading branch information
forsti0506 committed Sep 12, 2021
1 parent cefefdf commit e2d2c53
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ errors, shows the tab-order and other features.

| Statements | Branches | Functions | Lines |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](https://img.shields.io/badge/statements-34.23%25-red.svg) | ![Branches](https://img.shields.io/badge/branches-23.82%25-red.svg) | ![Functions](https://img.shields.io/badge/functions-23.91%25-red.svg) | ![Lines](https://img.shields.io/badge/lines-35.64%25-red.svg) |
| ![Statements](https://img.shields.io/badge/statements-12.45%25-red.svg) | ![Branches](https://img.shields.io/badge/branches-11.11%25-red.svg) | ![Functions](https://img.shields.io/badge/functions-8.89%25-red.svg) | ![Lines](https://img.shields.io/badge/lines-13.13%25-red.svg) |

### Install

Expand Down
9 changes: 6 additions & 3 deletions lib/utils/analyze-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const elementsToClick: Map<string, string[]> = new Map<string, string[]>();

const rootDomain = { value: '' };

const savedScreenshotHtmls: Map<string, string> = new Map();

export async function analyzeSite(
axeSpecs: Spec,
firstpage: Page,
Expand All @@ -34,7 +36,7 @@ export async function analyzeSite(
await page.setViewport(viewport);
}

const result = await analyzeUrl(page, url, axeSpecs, config, alreadyVisited);
const result = await analyzeUrl(page, url, axeSpecs, config, alreadyVisited, savedScreenshotHtmls);
await page.close();
return result;
}, 4),
Expand All @@ -59,7 +61,7 @@ export async function analyzeSite(
}
log('Start analyze of ' + url);

resultsByUrl.push(await analyzeUrl(firstpage, url, axeSpecs, config, alreadyVisited));
resultsByUrl.push(await analyzeUrl(firstpage, url, axeSpecs, config, alreadyVisited, savedScreenshotHtmls));

const html = await firstpage.content();
const links = getLinks(
Expand All @@ -85,7 +87,7 @@ export async function analyzeSite(
if (alreadyVisited.get(link)) {
return null;
}
const result = await analyzeUrl(page, link, axeSpecs, config, alreadyVisited);
const result = await analyzeUrl(page, link, axeSpecs, config, alreadyVisited, savedScreenshotHtmls);
await page.close();
return result;
}, 4),
Expand Down Expand Up @@ -126,6 +128,7 @@ export async function analyzeSite(
}
}
}
savedScreenshotHtmls.clear();
return resultsByUrl.filter(notEmpty);
}

Expand Down
3 changes: 1 addition & 2 deletions lib/utils/analyze-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import { createUrlResult } from './create-url-result';
import { acceptCookieConsent } from './accept-consent-screens';
import { saveScreenshot } from './helper-saving-screenshots';

const savedScreenshotHtmls: Map<string, string> = new Map();

export async function analyzeUrl(
page: Page,
url: string,
axeSpecs: Spec,
config: Config,
alreadyVisited: Map<string, SitecheckerViewport>,
savedScreenshotHtmls: Map<string, string>,
): Promise<ResultByUrl | null> {
if ((await page.url()) !== url) {
await page.goto(url, { waitUntil: 'load' });
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/get-links.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import JSDOM from 'jsdom';
import chalk from 'chalk';
import { getUniqueSelector } from './UniqueSelector';
import { getUniqueSelector } from './unique-selector';
import { debug, endsWithAny, isAbsoluteUrl, shouldElementBeIgnored } from './helper-functions';
import { Config, SitecheckerViewport } from '../models/config';

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/helper-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function waitForHTML(page: Page, timeout = 30000, debugMode = false
}

export function getEscaped(link: string): string {
return link.replace(/[`~ !@#$%^&*()_|+\-=?;:'",.<>{}\\[\]/]/gi, '_');
return link.replace(/[`~ !@#$%^&*()_|+\-=?;:'",.<>{}\\[\]/]/gi, '_').replace('\n', '');
}
export function shouldElementBeIgnored(element: Element, elementstoIgnore: string[] | undefined): boolean {
if (!elementstoIgnore) return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import puppeteer from 'puppeteer';
import { Config } from '../models/config';
import { executeLogin } from './login';
import { cleanUpAfterTest, initBeforeTest } from './test-helper-functions';
import { cleanUpAfterTest, initBeforeTest } from './test-helper-functions.spec';

describe('login', () => {
let config: Config;
Expand Down
38 changes: 38 additions & 0 deletions lib/utils/mark-all-tabable-items.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Config } from '../models/config';
import { markAllTabableItems } from './mark-all-tabable-items';
import { cleanUpAfterTest, initBeforeTest } from './test-helper-functions.spec';
import { ResultByUrl } from '../models/a11y-sitechecker-result';
import puppeteer from 'puppeteer';
import 'jest';

describe('markAllTabaleItems', () => {
let config: Config;
let urlResult: ResultByUrl;

beforeEach(async () => {
config = await initBeforeTest();
config.timeout = 15000;
config.debugMode = true;
});
afterEach(() => {
return cleanUpAfterTest(config);
});
test('should not be able to login', async () => {
expect.assertions(1);

const browser = await puppeteer.launch(config.launchOptions);
const pages = await browser.pages();
await pages[0].goto('https://www.forsti.eu');
jest.spyOn(pages[0], 'evaluate').mockImplementation((fn) => {
return Promise.resolve(['test1', 'test2']);
});

try {
return expect(
markAllTabableItems(pages[0], 'https://www.forsti.eu', config, urlResult),
).resolves.not.toThrow();
} catch (e) {
fail(e);
}
});
});
1 change: 0 additions & 1 deletion lib/utils/mark-all-tabable-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export async function markAllTabableItems(
async (focusableElement, i, debugMode) => {
const element = document.querySelector(focusableElement);
if (!element) return;

const elementVisible = window.isElementVisible(focusableElement);
window.debug(debugMode, JSON.stringify(element.getBoundingClientRect()));
if (!elementVisible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export async function initBeforeTest(): Promise<Config> {
json: true,
config: './tests/config.json',
debugMode: false,
launchOptions: {
devtools: true,
headless: false,
},
};
return setupConfig(optionValues);
}
File renamed without changes.

0 comments on commit e2d2c53

Please sign in to comment.