运行 Jasmine 测试(耦合到 DOM/jquery 等)通过 CI 的命令行

Run Jasmine tests (coupled to DOM/jquery etc) via command line for CI

我们有一组 Jasmine 测试 运行 在本地网络服务器中成功。 http-server

我们希望 运行 在 TeamCity 构建过程中从命令行进行这些测试 而无需 启动网络服务器。

使用 --disable-web-security 标志打开带有 chrome 的 html 文件导致

Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.

可能是因为脚本引用 SpecRunner.html 文件中的类型="module"

<script src="../src/js/App/app.js" type="module"></script>

Jasmine 测试与 DOM/jQuery 耦合,因此它们需要在浏览器中 运行。 SpecRunner html 页面包含 type="module".

的脚本引用

我们如何 运行 在 TeamCity 构建期间进行这些测试,并在出现任何测试失败时使构建失败?

谢谢。

这是我的解决方案。我们已经在使用 jest 进行反应测试并且 jest docs

If you are using Jasmine, or a Jasmine like API (for example Mocha), Jest should be mostly compatible, which makes it less complicated to migrate to.

  1. npm install jest puppeteer jest-puppeteer http-server

    • 开玩笑:为了 运行 使用 Jasmine API
    • 的测试
    • puppeteer:运行 在无头 chrome 浏览器中进行测试
    • http-server:用于导航到 jasmine 规范的本地网络服务器 运行ner 页面
    • jest-puppeteer:配置在 运行测试之前启动本地服务器并在之后停止它
  2. 添加jest-puppeteer-config.json 启动服务器像this

Jest Puppeteer integrates a functionality to start a server when running your test suite. It automatically closes the server when tests are done.

  1. 添加一个 jest-puppeteer 测试以导航到 Jasmine SpecRunner 页面并断言没有失败。

  2. 更新你的玩笑配置docs

  3. 为 运行 jest 测试创建 npm 脚本,然后在浏览器中进行 运行s Jasmine 测试。

此时,应该能够 运行 从本地或构建服务器上的命令行浏览器 Jasmine 测试。

这是显示本地和 TeamCity 上的文件和测试 运行 结果的屏幕截图。

How can we run these tests during a TeamCity build and fail the build if there are any test failures?

这个解决方案使我们能够以最小的努力恢复大约一百个遗留的浏览器耦合的 Jasmine 测试作为构建的一部分(不必更新测试)。

随时提出替代方案。