@d-zero/a11y-check-axe-scenario 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/axe.js CHANGED
@@ -1,3 +1,4 @@
1
+ import AxePuppeteer from '@axe-core/puppeteer';
1
2
  import { createScenario } from '@d-zero/a11y-check-core';
2
3
  import { Cache } from '@d-zero/shared/cache';
3
4
  import { convertResultsFromViolations } from './convert-results-from-violations.js';
@@ -5,13 +6,14 @@ const scenarioId = 'a11y-check/axe';
5
6
  export default createScenario((options) => {
6
7
  const cache = new Cache(scenarioId, options?.cacheDir);
7
8
  return {
9
+ modulePath: import.meta.url,
8
10
  id: scenarioId,
9
11
  async exec(page, sizeName, log) {
10
12
  if (options?.cache === false) {
11
13
  await cache.clear();
12
14
  }
13
15
  const axeLog = (message) => log(`🪓 ${message}`);
14
- const key = (await page.url()) + '#' + sizeName;
16
+ const key = page.url() + '#' + sizeName;
15
17
  const cached = await cache.load(key, (key, value) => {
16
18
  if (key === 'timestamp') {
17
19
  return new Date(Date.parse(value));
@@ -23,10 +25,13 @@ export default createScenario((options) => {
23
25
  violations: await convertResultsFromViolations(page, cached, sizeName, options?.screenshot ?? false, axeLog),
24
26
  };
25
27
  }
26
- const axeResults = await page.axe({
27
- lang: options?.lang ?? 'ja',
28
- log: axeLog,
29
- });
28
+ const axeResults = await new AxePuppeteer(page)
29
+ .configure({
30
+ locale: {
31
+ lang: options?.lang ?? 'ja',
32
+ },
33
+ })
34
+ .analyze();
30
35
  await cache.store(key, axeResults);
31
36
  return {
32
37
  violations: await convertResultsFromViolations(page, axeResults, sizeName, options?.screenshot ?? false, axeLog),
@@ -1,6 +1,13 @@
1
1
  import type { Style } from '@d-zero/a11y-check-core';
2
- import type { Page } from '@d-zero/puppeteer-page';
3
2
  import type { NodeResult } from 'axe-core';
3
+ import type { Page } from 'puppeteer';
4
+ /**
5
+ *
6
+ * @param page
7
+ * @param node
8
+ * @param screenshot
9
+ * @param log
10
+ */
4
11
  export declare function convertResultsFromNode(page: Page, node: NodeResult, screenshot: boolean, log: (log: string) => void): Promise<{
5
12
  screenshot: string | null;
6
13
  style: Style | null;
@@ -1,5 +1,12 @@
1
1
  import path from 'node:path';
2
2
  import { hash } from '@d-zero/shared/hash';
3
+ /**
4
+ *
5
+ * @param page
6
+ * @param node
7
+ * @param screenshot
8
+ * @param log
9
+ */
3
10
  export async function convertResultsFromNode(page, node, screenshot, log) {
4
11
  const target = node.target[0] && typeof node.target[0] === 'string' ? node.target[0] : null;
5
12
  if (!target) {
@@ -9,9 +16,10 @@ export async function convertResultsFromNode(page, node, screenshot, log) {
9
16
  let screenshotName = null;
10
17
  if (screenshot && target) {
11
18
  log(`Screenshot: ${target}`);
12
- const url = await page.url();
19
+ const url = page.url();
13
20
  const ssName = hash(url + target) + '.png';
14
- const elementScreenshot = await page.elementScreenshot(target, {
21
+ const el = await page.waitForSelector(target);
22
+ const elementScreenshot = await el?.screenshot({
15
23
  path: path.resolve(process.cwd(), '.cache', ssName),
16
24
  });
17
25
  if (elementScreenshot) {
@@ -1,4 +1,12 @@
1
1
  import type { Violation } from '@d-zero/a11y-check-core';
2
- import type { Page } from '@d-zero/puppeteer-page';
3
2
  import type { AxeResults } from 'axe-core';
3
+ import type { Page } from 'puppeteer';
4
+ /**
5
+ *
6
+ * @param page
7
+ * @param axeResults
8
+ * @param sizeName
9
+ * @param screenshot
10
+ * @param log
11
+ */
4
12
  export declare function convertResultsFromViolations(page: Page, axeResults: AxeResults, sizeName: string, screenshot: boolean, log: (log: string) => void): Promise<Violation[]>;
@@ -3,6 +3,14 @@ import { detectLevel } from './detect-level.js';
3
3
  import { inferExplanation } from './infer-explanation.js';
4
4
  import { p } from './pargraph.js';
5
5
  import { tagsToSCs } from './tags-to-scs.js';
6
+ /**
7
+ *
8
+ * @param page
9
+ * @param axeResults
10
+ * @param sizeName
11
+ * @param screenshot
12
+ * @param log
13
+ */
6
14
  export async function convertResultsFromViolations(page, axeResults, sizeName, screenshot, log) {
7
15
  const results = [];
8
16
  const violations = [...axeResults.incomplete, ...axeResults.violations];
@@ -13,7 +21,7 @@ export async function convertResultsFromViolations(page, axeResults, sizeName, s
13
21
  const explanation = inferExplanation(violation.id, node, nodeResult?.style ?? null);
14
22
  results.push({
15
23
  id: '',
16
- url: await page.url(),
24
+ url: page.url(),
17
25
  tool: `${axeResults.testEngine.name} (v${axeResults.testEngine.version})`,
18
26
  timestamp: new Date(axeResults.timestamp),
19
27
  component: nodeResult?.landmark ?? null,
@@ -1 +1,5 @@
1
+ /**
2
+ *
3
+ * @param tags
4
+ */
1
5
  export declare function detectLevel(tags: readonly string[]): "A" | "AA" | "AAA" | null;
@@ -1,3 +1,7 @@
1
+ /**
2
+ *
3
+ * @param tags
4
+ */
1
5
  export function detectLevel(tags) {
2
6
  return tags.includes('wcag2a')
3
7
  ? 'A'
@@ -1 +1,5 @@
1
+ /**
2
+ *
3
+ * @param tags
4
+ */
1
5
  export declare function detectLevel(tags: readonly string[]): "A" | "AA" | "AAA" | null;
@@ -1,3 +1,7 @@
1
+ /**
2
+ *
3
+ * @param tags
4
+ */
1
5
  export function detectLevel(tags) {
2
6
  return tags.includes('wcag2')
3
7
  ? 'A'
@@ -1,4 +1,10 @@
1
1
  import type { AxeRuleId, Explanation } from './types.js';
2
2
  import type { Style } from '@d-zero/a11y-check-core';
3
3
  import type { NodeResult } from 'axe-core';
4
+ /**
5
+ *
6
+ * @param id
7
+ * @param node
8
+ * @param style
9
+ */
4
10
  export declare function inferExplanation(id: AxeRuleId, node: NodeResult, style: Style | null): Explanation | null;
@@ -1,5 +1,11 @@
1
1
  import { colorContrastCheck, ColorContrastError } from '@d-zero/a11y-check-core';
2
2
  import { br, p } from './pargraph.js';
3
+ /**
4
+ *
5
+ * @param id
6
+ * @param node
7
+ * @param style
8
+ */
3
9
  export function inferExplanation(id, node, style) {
4
10
  switch (id) {
5
11
  case 'accesskeys': {
@@ -1,2 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {...any} texts
4
+ */
1
5
  export declare function p(...texts: (string | null | undefined)[]): string;
6
+ /**
7
+ *
8
+ * @param {...any} texts
9
+ */
2
10
  export declare function br(...texts: (string | null | undefined)[]): string;
package/dist/pargraph.js CHANGED
@@ -1,6 +1,14 @@
1
+ /**
2
+ *
3
+ * @param {...any} texts
4
+ */
1
5
  export function p(...texts) {
2
6
  return texts.filter(Boolean).join('\n\n');
3
7
  }
8
+ /**
9
+ *
10
+ * @param {...any} texts
11
+ */
4
12
  export function br(...texts) {
5
13
  return texts.filter(Boolean).join('\n');
6
14
  }
@@ -1,2 +1,10 @@
1
+ /**
2
+ *
3
+ * @param tags
4
+ */
1
5
  export declare function tagsToSCs(tags: string[]): string;
6
+ /**
7
+ *
8
+ * @param tag
9
+ */
2
10
  export declare function tagToSC(tag: string): "1.1.1" | "1.2.1" | "1.2.2" | "1.2.3" | "1.2.4" | "1.2.5" | "1.2.6" | "1.2.7" | "1.2.8" | "1.2.9" | "1.3.1" | "1.3.2" | "1.3.3" | "1.3.4" | "1.3.5" | "1.3.6" | "1.4.1" | "1.4.2" | "1.4.3" | "1.4.4" | "1.4.5" | "1.4.6" | "1.4.7" | "1.4.8" | "1.4.9" | "1.4.10" | "1.4.11" | "1.4.12" | "1.4.13" | "2.1.1" | "2.1.2" | "2.1.3" | "2.1.4" | "2.2.1" | "2.2.2" | "2.2.3" | "2.2.4" | "2.2.5" | "2.2.6" | "2.3.1" | "2.3.2" | "2.3.3" | "2.4.1" | "2.4.2" | "2.4.3" | "2.4.4" | "2.4.5" | "2.4.6" | "2.4.7" | "2.4.8" | "2.4.9" | "2.4.10" | "2.4.11" | "2.4.12" | "2.4.13" | "2.5.1" | "2.5.2" | "2.5.3" | "2.5.4" | "2.5.5" | "2.5.6" | "2.5.7" | "2.5.8" | "3.1.1" | "3.1.2" | "3.1.3" | "3.1.4" | "3.1.5" | "3.1.6" | "3.2.1" | "3.2.2" | "3.2.3" | "3.2.4" | "3.2.5" | "3.2.6" | "3.3.1" | "3.3.2" | "3.3.3" | "3.3.4" | "3.3.5" | "3.3.6" | "3.3.7" | "3.3.8" | "3.3.9" | "4.1.2" | "4.1.3" | null;
@@ -2,9 +2,17 @@ import { wcag } from '@d-zero/db-wcag';
2
2
  const scVersions = new Set(
3
3
  // @ts-ignore
4
4
  Object.keys(wcag.successCriterions['wcag_2.2'].en));
5
+ /**
6
+ *
7
+ * @param tags
8
+ */
5
9
  export function tagsToSCs(tags) {
6
10
  return tags.map(tagToSC).filter(Boolean).join('\n');
7
11
  }
12
+ /**
13
+ *
14
+ * @param tag
15
+ */
8
16
  export function tagToSC(tag) {
9
17
  if (!tag.startsWith('wcag') || tag.endsWith('a')) {
10
18
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/a11y-check-axe-scenario",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Accessibility Checker Axe Scenario",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
@@ -24,13 +24,18 @@
24
24
  "clean": "tsc --build --clean"
25
25
  },
26
26
  "dependencies": {
27
- "@d-zero/a11y-check-core": "0.2.0",
27
+ "@axe-core/puppeteer": "4.10.1",
28
+ "@d-zero/a11y-check-core": "0.4.0",
28
29
  "@d-zero/db-wcag": "1.0.0-alpha.1",
29
- "@d-zero/shared": "0.6.0"
30
+ "@d-zero/shared": "0.8.0"
30
31
  },
31
32
  "devDependencies": {
32
- "@d-zero/puppeteer-page": "0.2.0",
33
- "axe-core": "4.10.2"
33
+ "axe-core": "4.10.3",
34
+ "puppeteer": "24.9.0"
34
35
  },
35
- "gitHead": "1eb1c03400580040119121e11ffb33acd876fe1b"
36
+ "peerDependencies": {
37
+ "axe-core": "4.10.3",
38
+ "puppeteer": "24.8.2"
39
+ },
40
+ "gitHead": "4e9cc7b87e0fef91b6f2d4edfb66ca9134b2491b"
36
41
  }
@@ -1,3 +0,0 @@
1
- import type { AxeResults } from 'axe-core';
2
- import type { Page } from 'puppeteer';
3
- export declare function runAxePuppeteer(page: Page, lang: string, log: (log: string) => void): Promise<AxeResults>;
@@ -1,17 +0,0 @@
1
- import { AxePuppeteer } from '@axe-core/puppeteer';
2
- import { delay } from '@d-zero/shared/delay';
3
- export async function runAxePuppeteer(page, lang, log) {
4
- const mod = await import(`axe-core/locales/${lang}.json`, {
5
- with: { type: 'json' },
6
- });
7
- const locale = mod.default;
8
- log(`Analyze%dots%`);
9
- const axeResults = await new AxePuppeteer(page)
10
- .configure({
11
- locale,
12
- })
13
- .analyze();
14
- log(`Found ${axeResults.violations.length} violations, ${axeResults.incomplete.length} incomplete issues`);
15
- await delay(600);
16
- return axeResults;
17
- }
package/dist/sc.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function sc(tags: string[]): string;
package/dist/sc.js DELETED
@@ -1,23 +0,0 @@
1
- import { wcag } from '@d-zero/db-wcag';
2
- const scVersions = new Set(
3
- // @ts-ignore
4
- Object.keys(wcag.successCriterions['wcag_2.2'].en));
5
- export function sc(tags) {
6
- return tags.map(_sc).filter(Boolean).join('\n');
7
- }
8
- function _sc(tag) {
9
- if (!tag.startsWith('wcag') || tag.endsWith('a')) {
10
- return null;
11
- }
12
- const num = /\d+/.exec(tag)?.[0];
13
- if (!num) {
14
- return null;
15
- }
16
- for (const version of scVersions) {
17
- const crushedNum = version.replaceAll('.', '');
18
- if (tag === crushedNum) {
19
- return version;
20
- }
21
- }
22
- return null;
23
- }