How to serve angular cli app before running cypress in CI?
I wasn't satisfied with any of the answers provided, so I came up with the following:
Step 1: Install dev dependencies
npm install --save-dev concurrently wait-on
Step 2: Write the following scripts in your package.json
:
"scripts": {
"start": "ng serve",
...
"cy:open": "cypress open",
"cy:run": "cypress run",
"e2e": "concurrently \"npm run start\" \"wait-on http-get://localhost:4200 && npm run cy:run\" --kill-others --success first",
"e2e-gui": "concurrently \"npm run start\" \"wait-on http-get://localhost:4200 && npm run cy:open\" --kill-others --success first",
...
}
Then you can run npm run e2e
or npm run e2e-gui
.
Voila!
Latest Cypress updates already include Angular schematics to simplify tests integration into an existing project.
As simple as: ng add @cypress/schematic
and then ng e2e