【问题标题】:Azure Pipeline Node.js run localhost server(express) and client at different port to run jest testsAzure Pipeline Node.js 在不同的端口运行 localhost 服务器(express)和客户端来运行 jest 测试
【发布时间】:2021-08-17 02:50:38
【问题描述】:

我正在使用 Node.js 在端口 8080 上运行客户端应用程序 (JS)。同时,我正在使用 Node.js 在端口 3030 上运行 Express Server。

集成测试是用 Jest 和 Selenium 编写的。为了测试应用程序,在我的本地机器上,我打开三个 Powershell 窗口并运行集成测试。它按预期工作并且测试用例通过。

Server Folder (new Terminal)
 npm install
 npm run start (Express.js)

Client Folder (new Terminal)
 npm install
 npm run start

Client Folder (new Terminal)
 npm run tests

在 Azure Pipeline 中,我为图像“window-latest”创建了 YML,但它卡在了服务器启动处。

powershell:
display name: Server Start
  npm install
  npm run start

powershell:
display name: Client Start
  npm install
  npm run start | npm run test (Combined in package.json)

如果我在 Azure Pipeline 中删除 Server Start,则不需要服务器通过的测试用例。

两个项目都在一个存储库下。我在 Package.json 中使用 cd 命令在服务器位置安装和启动服务器。

start:server: "cd /server/dev/ && npm install && npm run start"
start:client: "npm install && npm run start"
test: "npm run start:server | npm run start:client | jest"

npm 运行测试,在我的本地机器上运行良好,服务器和客户端运行并且测试用例通过(单终端)。在 Azure Pipeline 上,我需要手动取消任务,因为 Azure 管道任务永远不会结束。分离脚本(Powershell)后,我注意到管道卡在 Express.js 服务器启动(通过在 YAML 中运行单个和组合的 npm 命令进行测试)。

问题:如何在启动 Client 之前在 Azure Pipeline 中启动 localhost Express Node.js 服务器?

【问题讨论】:

    标签: node.js azure express azure-devops azure-pipelines


    【解决方案1】:

    您可以查看start-server-and-test:

    启动服务器,等待 URL,然后运行测试命令;当测试 结束,关闭服务器。

    【讨论】:

      【解决方案2】:

      Microsoft 不允许绑定到托管代理上的端口。 您必须拥有一个自托管代理才能执行此操作。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 2017-05-26
      • 2013-12-18
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多