Add Cypress to an Angular CLI project
This schematic will:
- install Cypress, it's dependencies, and new scripts
- add necessary files for Cypress to work with Angular & Typescript
- prompt for removal of Protractor files and configuration
Run as one command in an Angular CLI app directory. Note this will add the schematic as a dependency to your project.
ng add @briebug/cypress-schematic
Option | Description |
---|---|
addCypressTestScripts | This will add Cypress open and run command scripts to your package.json . Include --addCypressTestScripts in your ng add command. |
noBuilder | This will skip the builder addition, leaving the angular.json file unmodified and requiring you to run Cypress from the command line or through your IDE. Include --noBuilder in your ng add command. |
Issues with this schematic can be filed here.
Thanks to Kevin Schuchard for setting up the Schematic Sandbox, and writing the Jest schematic which inspired this schematic.
More info on this sandbox approach is detailed in this blog post kevinschuchard.com/blog/2018-11-20-schematic-sandbox/
Also, thank you to Zahid Mahmood for writing this blog post detailing setting up cypress in an Angular project.
⚙ Yarn is required for the scripts. Make sure it's installed on your machine.
⬇ Install the dependencies for the schematic and the sandbox application
yarn && cd sandbox && yarn && cd ..
🖇 Link the schematic in the sandbox to run locally
yarn link:schematic
🏃 Run the schematic
yarn build:clean:launch
To execute an example schematic, make sure you've ran the Install and Link steps above. Then run the following and inspect the changed files.
git checkout component-license && yarn build:clean:launch
Execute the schematic against the sandbox. Then run linting, unit & e2e tests and a prod build in the sandbox.
yarn test
Run the unit tests using Jasmine as a runner and test framework.
yarn test:unit
Running the schematic locally makes file system changes. The sandbox is version controlled so that viewing a diff of the changes is trivial. After the schematic has run locally, reset the sandbox with the following.
yarn clean