experience-lwc-accessibility-jest-run

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<!-- adk-managed-skill -->
<!-- adk-managed-skill -->

Running LWC Accessibility Jest Tests

运行LWC无障碍Jest测试

Run Sa11y accessibility unit tests on Lightning Web Components in either:
  • Core (Bazel) — when a
    WORKSPACE
    file is present.
  • Standalone (Jest) — when there's no
    WORKSPACE
    .
Selenium-level reproductions, GUS A11yBug ingestion, and other internal Salesforce-only flows are out of scope for this skill. For source-code-level WCAG review without running tests, see
experience-lwc-accessibility-validate
.
在以下两种环境中,对Lightning Web Component(LWC)运行Sa11y无障碍单元测试:
  • 核心环境(Bazel) — 当存在
    WORKSPACE
    文件时使用。
  • 独立环境(Jest) — 当不存在
    WORKSPACE
    文件时使用。
基于Selenium的复现、GUS A11yBug导入以及其他仅限Salesforce内部的流程不属于本技能的范围。如需在不运行测试的情况下进行源代码级别的WCAG评审,请查看
experience-lwc-accessibility-validate

When to Use This Skill

何时使用本技能

  • User wants to run accessibility unit tests (Sa11y Jest) locally before pushing a fix.
  • User has a known failing test file path (e.g. from an A11yBug's
    Test_Names__c
    ) and wants to target it directly.
  • User is iterating on an accessibility fix and needs the fastest pass/fail signal.
  • 用户希望在推送修复前,本地运行无障碍单元测试(Sa11y Jest)。
  • 用户已知失败测试文件路径(例如来自A11yBug的
    Test_Names__c
    字段),并希望直接针对该文件测试。
  • 用户正在迭代无障碍修复方案,需要最快的通过/失败反馈信号。

Prerequisites

前提条件

  • For Bazel Jest tests: a Salesforce core build environment (a
    WORKSPACE
    file is present).
  • For standalone Jest tests:
    @sa11y/jest
    installed and configured.
  • 对于Bazel Jest测试:需具备Salesforce核心构建环境(存在
    WORKSPACE
    文件)。
  • 对于独立Jest测试:已安装并配置
    @sa11y/jest

Workflow

工作流程

Follow running-sa11y-jest-tests.md. Pick the correct mode:
  • Core (Bazel) — use when
    WORKSPACE
    is present. Prefer single-file targets (
    //{moduleName}:{relativePath}
    ) over module targets when the failing test file path is already known (
    .test.js
    extension dropped). Bazel commands must pass
    --test_env=SA11Y_AUTO=1 --test_env=SA11Y_ENABLE_DOM_MUTATION_OBSERVER=1
    ; when debugging, add
    SA11Y_ENABLE_RENDERED_DOM_SAVE=1
    with the documented save path to avoid EPERM issues.
  • Standalone (Jest) — use when there's no
    WORKSPACE
    . Run
    npm test -- --testMatch="**/*.accessibility.test.js"
    for the whole suite, or
    npm test -- <file>
    targeting the file by the name/path given in the prompt (a bare filename when it is "in this directory"). Do not prepend
    SA11Y_*
    env vars in standalone mode — Sa11y runs automatically because
    @sa11y/jest
    is wired into the project's Jest setup; no extra environment variables are needed.
Answer only what is asked. Emit just the command(s) the prompt requests plus the exit-code meaning. Do not pad the plan with unrequested variants (watch, coverage, verbose), snapshot-update steps, or HTML-save sections unless the user explicitly asks for them.
遵循running-sa11y-jest-tests.md文档。选择正确的模式:
  • 核心环境(Bazel) — 当存在
    WORKSPACE
    文件时使用。若已知失败测试文件路径,优先使用单文件目标(
    //{moduleName}:{relativePath}
    ,需去掉
    .test.js
    扩展名)而非模块级目标。Bazel命令必须传入
    --test_env=SA11Y_AUTO=1 --test_env=SA11Y_ENABLE_DOM_MUTATION_OBSERVER=1
    ;调试时,添加
    SA11Y_ENABLE_RENDERED_DOM_SAVE=1
    并使用文档指定的保存路径,以避免EPERM问题。
  • 独立环境(Jest) — 当不存在
    WORKSPACE
    文件时使用。运行
    npm test -- --testMatch="**/*.accessibility.test.js"
    以执行整个测试套件,或运行
    npm test -- <file>
    直接针对提示中给出的文件名称/路径进行测试(若文件“在当前目录”,仅需传入文件名即可)。请勿在独立模式下添加
    SA11Y_*
    环境变量——由于
    @sa11y/jest
    已集成到项目的Jest配置中,Sa11y会自动运行,无需额外环境变量。
仅回答用户提出的问题。仅输出提示要求的命令及退出码含义。除非用户明确要求,否则请勿在方案中添加未请求的变体(如watch、coverage、verbose模式)、快照更新步骤或HTML保存相关内容。

Verification Checklist

验证清单

  • Sa11y Jest run completed with a clear pass/fail signal (exit 0 or 3 for Bazel; exit 0 or 1 for Jest).
  • If snapshots were intentionally updated, the new snapshots are committed alongside the fix.
  • Sa11y Jest测试已完成,且有明确的通过/失败信号(Bazel环境下退出码为0或3;Jest环境下退出码为0或1)。
  • 若有意更新快照,新快照需与修复代码一同提交。

Troubleshooting

故障排除

  • Bazel test "not found" — the target path is off. Remember to drop the
    .test.js
    extension in
    {relativePath}
    .
  • HTML saving fails with EPERM — use the prescribed save path
    sfdc-test/unit/javascript/htdocs/sa11y/jest
    .
  • Bazel测试提示“not found” — 目标路径有误。请记住在
    {relativePath}
    中去掉
    .test.js
    扩展名。
  • HTML保存失败并提示EPERM — 使用指定的保存路径
    sfdc-test/unit/javascript/htdocs/sa11y/jest