问题描述
我正在端口 8080 上使用 Node.js 运行客户端应用程序 (JS)。同时,我正在端口 3030 上使用 Node.js 运行 Express 服务器。
集成测试是用 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 命令进行测试)。
问题:如何在启动客户端之前在 Azure Pipeline 中启动 localhost Express Node.js 服务器?
解决方法
您可以检查start-server-and-test:
启动服务器,等待URL,然后运行测试命令;当测试 结束,关闭服务器。