Last active
March 29, 2022 10:21
-
-
Save glemiere/3282c3ace9417b32c75d93d7f0d3086d to your computer and use it in GitHub Desktop.
NPM Scripts to run Cypress with Angular ng serve command or SSR build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********** | |
package.json - remove this comment before using, as JSON files don't support comments. | |
--------------- | |
Simple package.json file showing how to use Cypress with Angular. | |
npm run cy:prod used to test production build in CI/CD. | |
npm run cy:staging used to test staging build in CI/CD. | |
npm run cy:gui used to develop tests with livereload and angular dev/live server. | |
--------------- | |
Requires wait-on and concurrently NPM packages as dev dependency to work correctly. | |
https://www.npmjs.com/package/wait-on and https://www.npmjs.com/package/concurrently | |
Intial answer related to this code on StackOverflow: | |
https://stackoverflow.com/questions/48823971/how-to-serve-angular-cli-app-before-running-cypress-in-ci/54777134#54777134 | |
**********/ | |
{ | |
"name": "myapp", | |
"version": "0.0.0", | |
"scripts": { | |
"cy:prod": "concurrently \"npm run build-ssr && npm run serve:ssr\" \"wait-on http-get://localhost:4200 && cypress run\" --kill-others", | |
"cy:staging": "concurrently \"npm run build-ssr:dev && npm run serve:ssr\" \"wait-on http-get://localhost:4200 && cypress run\" --kill-others", | |
"cy:gui": "concurrently \"npm run start\" \"wait-on http-get://localhost:4200 && cypress open\" --kill-others", | |
"ssr": "npm run build-ssr && npm run serve:ssr", | |
"ssr:dev": "npm run build-ssr:dev && npm run serve:ssr", | |
"build-ssr": "ng build --prod && ng run myapp:server && npm run build-server", | |
"build-ssr:dev": "ng build --prod --configuration=staging && ng run myapp:server && npm run build-server", | |
"build-server": "tsc -p server.tsconfig.json", | |
"serve:ssr": "node dist/server", | |
}, | |
"dependencies": { | |
"@angular/animations": "^7.2.0", | |
"@angular/cdk": "^7.2.1", | |
"@angular/common": "^7.2.0", | |
"@angular/compiler": "^7.2.0", | |
"@angular/core": "^7.2.0", | |
"@angular/forms": "^7.2.0", | |
"@angular/http": "^7.2.0", | |
"@angular/platform-browser": "^7.2.0", | |
"@angular/platform-browser-dynamic": "^7.2.0", | |
"@angular/platform-server": "^7.2.0", | |
"@angular/router": "^7.2.0", | |
"@nguniversal/common": "^7.0.2", | |
"@nguniversal/express-engine": "^7.0.2", | |
"@nguniversal/module-map-ngfactory-loader": "^7.0.2", | |
"core-js": "^2.6.1", | |
"path": "^0.12.7", | |
"rxjs": "^6.3.3", | |
"ts-loader": "^4.4.2", | |
"zone.js": "^0.8.26" | |
}, | |
"devDependencies": { | |
"@angular-devkit/build-angular": "^0.13.8", | |
"@angular/cli": "^7.2.1", | |
"@angular/compiler-cli": "^7.2.0", | |
"@types/node": "^10.12.18", | |
"concurrently": "^4.1.0", | |
"cypress": "^3.1.5", | |
"rxjs-tslint": "^0.1.6", | |
"ts-node": "~5.0.1", | |
"tslint": "^5.12.0", | |
"typescript": "3.2.2", | |
"wait-on": "^3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment