未捕获的错误:WCT 需要在 web-components-tester 中出现 Mocha 错误

Cen*_*asa 5 javascript web-component npm web-component-tester

我想设置web-component-tester来测试我的 web 组件。我通过 npm (devDependency) 安装了它并创建了以下脚本:

包.json:

  "scripts": {
    "wcttest": "./node_modules/.bin/wct --npm src/app/modules/essen/components/essen-list/test/wct-test.html"
  },
Run Code Online (Sandbox Code Playgroud)

正如脚本所述,我在那里有 .html 文件。但是现在,如果我运行脚本npm run wcttest,则会打开以下路线:

http://localhost:8081/components/wc-frontend/generated-index.html?cli_browser_id=0wc-frontend项目文件夹的根名称在哪里。但我不明白,为什么它components首先打开了路径。

测试打开了我安装的所有浏览器,但只有一个白页。如果我打开控制台有以下脚本:

<script>
WCT.loadSuites(["src/app/modules/essen/components/essen-list/test/wct-test.html"]);
<script>
Run Code Online (Sandbox Code Playgroud)

这里的路径看起来是正确的。

wct-test.html

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <script src="../../../../../../../node_modules/mocha/mocha.js</script>
    <script src="../../../../../../../node_modules/wct-mocha/wct- 
    mocha.js"></script>
    <script src="../../../../../../../node_modules/web-component-tester/browser.js"></script>
    <script type="module" src="../essen-list.component.js"></script>
</head>
<body>
<mp-essen-list></mp-essen-list>

<script>

    suite('suite', function () {
        const list = document.body.querySelector('mp-essen-list');

        test('test', function () {
            list.setAttribute('value', 100);
            assert.equal(list.value, 100);
            //console.log('test');
            //assert.equal(list.shadowRoot.querySelector('#speisekarte').style.left, 50);
        });
    });

</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:我注意到这不是错误的路径。我查看了控制台错误,发现以下错误:

wct-mocha.js:2446 Uncaught Error: WCT requires Mocha. Please ensure that it is present in WCT.environmentScripts, or that you load it before loading web-component-tester/browser.js
    at _ensureMocha (wct-mocha.js:2446)
    at Object.ensureDependenciesPresent (wct-mocha.js:2435)
    at HTMLDocument.<anonymous> (wct-mocha.js:2781)
Run Code Online (Sandbox Code Playgroud)