After trying to solve this for several hours, I developed a solution using the Cypress API .
Package.json
"cypress:run:ci": "node ng-serve-and-run-cypress.js",
ng served and run cypress
'use strict'; const cypress = require('cypress'); const { spawn } = require('child_process'); const child = spawn('ng', ['serve']); // On error exit, and print child.on('error', (err) => process.exit(1)); child.stderr.on('data', (data) => console.log(data.toString())); // On exit, print exit code child.on('exit', (code, signal) => console.log(`Child exitting with code ${code}`)); child.stdout.on('data', (data) => { const asString = data.toString(); // Log the output to inform CI/User console.log(asString); if (asString.includes('webpack: Compiled successfully.')) { cypress.run({}) .then((results) => { const errorCode = (results.failures >= 1) ? 1 : 0; child.kill(); // When cypress is done running the tests, exit with errorCode from above. process.exit(errorCode); }) .catch((err) => { child.kill(); // If cypress hit an error, exit with code 1 process.exit(1); }) } });
Just send here if you are interested in more detailed information.
source share