@d-zero/a11y-check-axe-scenario 0.3.0 → 0.4.0

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,15 @@ 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,
10
+ moduleParams: JSON.stringify(options ?? {}),
8
11
  id: scenarioId,
9
12
  async exec(page, sizeName, log) {
10
13
  if (options?.cache === false) {
11
14
  await cache.clear();
12
15
  }
13
16
  const axeLog = (message) => log(`🪓 ${message}`);
14
- const key = (await page.url()) + '#' + sizeName;
17
+ const key = page.url() + '#' + sizeName;
15
18
  const cached = await cache.load(key, (key, value) => {
16
19
  if (key === 'timestamp') {
17
20
  return new Date(Date.parse(value));
@@ -23,10 +26,13 @@ export default createScenario((options) => {
23
26
  violations: await convertResultsFromViolations(page, cached, sizeName, options?.screenshot ?? false, axeLog),
24
27
  };
25
28
  }
26
- const axeResults = await page.axe({
27
- lang: options?.lang ?? 'ja',
28
- log: axeLog,
29
- });
29
+ const axeResults = await new AxePuppeteer(page)
30
+ .configure({
31
+ locale: {
32
+ lang: options?.lang ?? 'ja',
33
+ },
34
+ })
35
+ .analyze();
30
36
  await cache.store(key, axeResults);
31
37
  return {
32
38
  violations: await convertResultsFromViolations(page, axeResults, sizeName, options?.screenshot ?? false, axeLog),
@@ -1,6 +1,6 @@
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
4
  /**
5
5
  *
6
6
  * @param page
@@ -16,9 +16,10 @@ export async function convertResultsFromNode(page, node, screenshot, log) {
16
16
  let screenshotName = null;
17
17
  if (screenshot && target) {
18
18
  log(`Screenshot: ${target}`);
19
- const url = await page.url();
19
+ const url = page.url();
20
20
  const ssName = hash(url + target) + '.png';
21
- const elementScreenshot = await page.elementScreenshot(target, {
21
+ const el = await page.waitForSelector(target);
22
+ const elementScreenshot = await el?.screenshot({
22
23
  path: path.resolve(process.cwd(), '.cache', ssName),
23
24
  });
24
25
  if (elementScreenshot) {
@@ -1,6 +1,6 @@
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
4
  /**
5
5
  *
6
6
  * @param page
@@ -1,7 +1,7 @@
1
1
  import { convertResultsFromNode } from './convert-results-from-node.js';
2
2
  import { detectLevel } from './detect-level.js';
3
3
  import { inferExplanation } from './infer-explanation.js';
4
- import { p } from './pargraph.js';
4
+ import { p } from './paragraph.js';
5
5
  import { tagsToSCs } from './tags-to-scs.js';
6
6
  /**
7
7
  *
@@ -21,7 +21,7 @@ export async function convertResultsFromViolations(page, axeResults, sizeName, s
21
21
  const explanation = inferExplanation(violation.id, node, nodeResult?.style ?? null);
22
22
  results.push({
23
23
  id: '',
24
- url: await page.url(),
24
+ url: page.url(),
25
25
  tool: `${axeResults.testEngine.name} (v${axeResults.testEngine.version})`,
26
26
  timestamp: new Date(axeResults.timestamp),
27
27
  component: nodeResult?.landmark ?? null,
@@ -1,5 +1,5 @@
1
1
  import { colorContrastCheck, ColorContrastError } from '@d-zero/a11y-check-core';
2
- import { br, p } from './pargraph.js';
2
+ import { br, p } from './paragraph.js';
3
3
  /**
4
4
  *
5
5
  * @param id
@@ -132,7 +132,7 @@ export function inferExplanation(id, node, style) {
132
132
  }
133
133
  case ColorContrastError.DOES_NOT_DETERMINE_BACKGROUND: {
134
134
  needCheck = 'WARNING';
135
- message = '背景色が判定できないかったので#FFFFFFとして判定しています。';
135
+ message = '背景色が判定できなかったので#FFFFFFとして判定しています。';
136
136
  contrastResult = style
137
137
  ? colorContrastCheck({
138
138
  ...style,
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {...any} texts
4
+ */
5
+ export declare function p(...texts: (string | null | undefined)[]): string;
6
+ /**
7
+ *
8
+ * @param {...any} texts
9
+ */
10
+ export declare function br(...texts: (string | null | undefined)[]): string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ *
3
+ * @param {...any} texts
4
+ */
5
+ export function p(...texts) {
6
+ return texts.filter(Boolean).join('\n\n');
7
+ }
8
+ /**
9
+ *
10
+ * @param {...any} texts
11
+ */
12
+ export function br(...texts) {
13
+ return texts.filter(Boolean).join('\n');
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/a11y-check-axe-scenario",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
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.3.0",
27
+ "@axe-core/puppeteer": "4.10.2",
28
+ "@d-zero/a11y-check-core": "0.5.0",
28
29
  "@d-zero/db-wcag": "1.0.0-alpha.1",
29
- "@d-zero/shared": "0.7.0"
30
+ "@d-zero/shared": "0.9.0"
30
31
  },
31
32
  "devDependencies": {
32
- "@d-zero/puppeteer-page": "0.3.0",
33
- "axe-core": "4.10.2"
33
+ "axe-core": "4.10.3",
34
+ "puppeteer": "24.10.1"
34
35
  },
35
- "gitHead": "e4fd17857e31022d121527b00fd7f009dbdb2142"
36
+ "peerDependencies": {
37
+ "axe-core": "4.10.3",
38
+ "puppeteer": "24.10.1"
39
+ },
40
+ "gitHead": "04c6969564182c36ee38ef41e78130936dfa4863"
36
41
  }