Polymer 3.0 a11ySuite 测试报错

Polymer 3.0 a11ySuite testing error

我正在尝试让 a11ySuite 在 Polymer 3.0 测试中正常工作。

当我 运行 使用 polymer test 进行测试时,测试超时,我可以在自动浏览器的控制台中看到以下错误:

Uncaught ReferenceError: Polymer is not defined
at Suite.a11ySuite.eachTest (a11ySuite.js:51)
at mocha.js:1550
at Object.exports.forEach (mocha.js:1595)
at Suite.eachTest (mocha.js:1550)
at Runner.grepTotal (mocha.js:1224)
at Runner.grep (mocha.js:1215)
at new Runner (mocha.js:1197)
at Mocha.run (mocha.js:592)
at _runMocha (extend.js:41)
at done (util.js:34)

如果我 运行 处于调试模式,从 polymer serve url,我收到此错误:

a11ySuite.js:49 Uncaught TypeError: fixtureElement.create is not a function
at Suite.a11ySuite.eachTest (a11ySuite.js:49)
at mocha.js:1550
at Object.exports.forEach (mocha.js:1595)
at Suite.eachTest (mocha.js:1550)
at Runner.grepTotal (mocha.js:1224)
at Runner.grep (mocha.js:1215)
at new Runner (mocha.js:1197)
at Mocha.run (mocha.js:592)
at _runMocha (extend.js:41)
at done (util.js:34)

这之前还有一堆来自mocha的404,关于lodash,sinonjs和test-fixture,假设这是因为它是运行 in serve模式。

这是我的测试代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Verifier - a11y test</title>

    <script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
    <script src="../node_modules/web-component-tester/browser.js"></script>
    <script type="module" src="../src/verifier.js"></script>
</head>
<body>
    <test-fixture id="BUVA11y">
        <template>
            <verifier id="verifier"></verifier>
        </template>
    </test-fixture>

    <script>
      suite('A11y testing', function() {
        a11ySuite('BUVA11y');
      });
    </script>
</body>
</html>

我无法在网上找到更多信息,而且关于这个主题的文档非常有限(实际上确实不准确)。

web-component-tester 版本 6.4.3 开始,

a11ySuite 已移至 wct-browser-legacy。鉴于 "legacy" 命名,我猜它已被弃用。我假设它是这样使用的:

<script type="module">
  import {a11ySuite} from 'wct-browser-legacy/a11ySuite.js';
  a11ySuite('view1'); // "view1" == template name
</script>

但我无法让它在一个干净的 polymer-3-starter-kit 项目中工作(即 a11ySuite 属性 存在于模块中但始终是 undefined) .设置断点 where that variable is defined,我可以看到该变量实际上从未设置,因为无论出于何种原因从未调用 Mocha pre-require 事件处理程序。

但是,似乎 axe-core (via pwa-helpers) is the newest a11y testing tool to use in Polymer 3, based on the test code in pwa-starter-kit:

<script type="module">
  import 'axe-core/axe.min.js';
  import {axeReport} from 'pwa-helpers/axe-report.js';

  suite('views a11y tests', function() {
    test('my-view1', function() {
      const el = fixture('view1');
      return axeReport(el);
    });
    ...
  });
</script>