首页 > 解决方案 > 在 IDE 或命令行中运行 E2E 测试

问题描述

我正在使用 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 测试吗?

标签: jestjsstenciljsjest-puppeteer

解决方案


--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


推荐阅读