2

我正在使用 Stencil.js 创建一个 Web 组件库,并且我非常依赖 E2E 测试。由于它们相当慢,因此在开发新组件时运行整个测试套件(使用 Stencil.js CLI)变得越来越麻烦。

但是,我无法在我的 IDE (IntelliJ IDEA) 中或通过命令行运行单个测试。不过,它对于单元测试非常有效。

我的 Jest 配置如下所示:

module.exports = {
  "roots": [
    "<rootDir>/src"
  ],
  "preset": "@stencil/core/testing"
}

当我尝试在单个文件中运行测试时 ( jest --config jest.config.js --testPathPattern src/components/button/button.e2e.ts$)

它失败了,因为

newE2EPage() 仅在 E2E 测试中可用,并使用 --e2e cmd 行标志运行。

newE2EPage() 带有 Stencil.js,我不知道 Stencil.js 的 CLI 在后台做了什么。此外,我克隆了 Stencil.js 存储库,只是为了查看它是否与他们的 E2E 测试(https://github.com/ionic-team/stencil/tree/master/test/end-to-end)一起工作,但它也不行。

知道如何配置 Jest 以便它能够从命令行运行 Stencil.js-E2E 测试吗?

4

3 回答 3

2

--e2e标志用于 package.json 中的 npm 脚本。要开始 e2e 测试,您可以在 package.json 中添加:

"scripts": {
  "test:e2e": "stencil test --e2e"
}

并运行npm run test:e2e。对于特定文件,您可以在末尾添加它,如下所示:

npm run test:e2e src/components/button/button.e2e.ts

有关更多信息,请参阅 StencilJS 文档:https ://stenciljs.com/docs/end-to-end-testing

于 2019-08-26T17:37:31.220 回答
1

我也有同样的问题。IntelliJ 和“运行”单个“它”不起作用。

newE2EPage() is only available from E2E tests, and ran with the --e2e cmd line flag.

当我运行“npm run test”时,一切都会正常。不同之处在于 npm run stencil 之前只有 jest 不起作用。

这是模板笑话目录https://github.com/ionic-team/stencil/tree/master/src/testing/jest以及配置。

我在这里https://stenciljs.com/docs/testing-overview找到了一个 VS-CODE 运行笑话代码,但没有 Intellij 设置。

我正在运行以获取当前文件的路径以通过 npm 运行 stencil 和 e2e 文件的路径。但我找不到运行配置的正确变量。

我希望我们能尽快解决这个问题。

干杯

于 2019-08-27T08:00:22.853 回答
1

我不是 VS Code 用户,但与 IntelliJ 相比launch.json,VSC 可以运行单个测试:https ://github.com/ionic-team/stencil-site/pull/480

于 2019-08-28T06:45:40.837 回答