简体   繁体   中英

Azure Pipeline Node.js run localhost server(express) and client at different port to run jest tests

I am running a client application(JS) using Node.js on port 8080. At same time, I am running an Express Server using Node.js at port 3030.

Integration tests are written in Jest and Selenium. To test app, on my local machine, I open three Powershell windows and run Integration tests. It works as expected and test case passes.

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

In Azure Pipeline, I created YML for image 'window-latest', However it stuck at Server Start.

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)

If I remove Server Start in Azure Pipeline, test cases that do not need server pass.

Both projects are under one repository. I use cd command in Package.json to install and start server at server location.

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 run test, works fine on my local machine, server & client runs and test cases pass(single terminal). On Azure Pipeline, I need to Cancel task manually because the Azure pipeline task never ends. After separating scripts(Powershell), I noticed pipeline stuck on Express.js Server Start(Tested by running single and combined npm commands in YAML).

Question: How can I start localhost Express Node.js server in Azure Pipeline before starting Client?

You may check start-server-and-test :

Starts server, waits for URL, then runs test command; when the tests end, shuts down server.

Microsoft does not allow binding to a port on Hosted Agents. You must own a self hosted agent to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM