如何在 GitHub 操作上 运行 和使用 Cypress CI 连接到仿真器?

How to Run & Connect to Emulators with Cypress CI on GitHub Actions?

我正在尝试 运行 e2e Cypress 测试 Github 操作。我构建函数,运行 一个模拟器并启动 cypress 喜欢: npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch

这在本地主机上运行良好,但在 GitHub 操作上失败,当代码的第一部分尝试连接到模拟器时。

  cy.request(
    "DELETE",
    "http://localhost:9099/emulator/v1/projects/****/accounts"
  );

它无法访问端口 localhost:9099 上的模拟器,就像我通常在本地主机上所做的那样。

  1) Login
       runs setup:
     CypressError: `cy.request()` failed trying to load:

http://localhost:9099/emulator/v1/projects/****/accounts

We attempted to make an http request to this URL but the request failed without a response.

关于 连接到 GitHub 操作 上的本地主机端口,我需要做些什么吗?

已解决! Firebase 模拟器抛出一个错误,但我没有看到它,因为我 运行 它与其他命令在同一行:npx nx build functions | firebase emulators:start | nx e2e frontend-e2e --watch

我重写了工作流程中的作业:

      - name: Cypress run
        uses: cypress-io/github-action@v2
        with:
          browser: chrome
          build: npm run integration:build
          start: |
            npm run integration:emulate
            npm run integration:test

像这样从 package.json 调用自定义脚本:

    "integration:build": "nx build functions && nx run frontend:build",
    "integration:emulate": "firebase use default && firebase emulators:start",
    "integration:test": "nx e2e frontend-e2e --watch",

然后我可以在日志中看到 Firebase 错误并修复它们。有两个问题:

  1. 选择 运行 模拟器之前的项目(添加 firebase use default
  2. Firebase 登录(

在那之后,模拟器就像在本地主机上一样工作