How to test your schematic library?
Introduction
After creating your first schematics, you’ll want to test them to ensure they work as expected. There are three main ways to do this:
Watching mode
In your package.json
, you’ll notice not just a build script but also a build:watch
script. This command compiles your project automatically every time files in the src directory change.
To activate watching mode, execute:
Then, you can test your schematics using the CLI
with the command: builder exec [collection-location] [schematic-name]
. For example, to test it at the root of your project:
Npm Link
If you want to test your schematics as if they were a package, you can use npm link
. This approach allows you to simulate the installation and use of your package locally without publishing it. Execute the following:
Verdaccio
Verdaccio offers a more comprehensive testing setup with a few extra steps:
- Install Verdaccio globally:
- Start the Verdaccio server:
- Publish your package locally:
Verdaccio vs npm link
Here’s a comparison to help you decide between Verdaccio and npm link for testing your schematics:
Feature | Verdaccio | npm link |
---|---|---|
Primary Use | Acts as a private npm proxy registry for package management | Creates a symbolic link for local package development |
Use Case | Ideal for managing private packages within teams or organizations | Useful for testing local changes in packages without needing to publish them |
Advantages | - Private hosting of packages - Caching of npm packages - Version control - Integration with npm registry | - Quick feedback on changes - Simplifies the development process - Avoids premature package publication |
Ideal For | Teams and organizations requiring shared access to private packages | Developers testing local package dependencies |
Installation Process | Involves setting up a Verdaccio server | A straightforward command line operation |
Security | Enhances package management security | Primarily for local development, minimal security impact |
Network Dependency | Reduces reliance on the public npm registry by caching packages | No network dependency, as it links local packages directly |
This documentation aims to make the process of testing your schematic library as straightforward as possible, providing you with multiple approaches to suit your development workflow.