Most of the times, when an Angular code change is made by a developer, all unit tests are run in CI. This project is a proof of concept on how only run impacted unit tests based on a commit change.
npm i angular-incremental-tests -D
- In your
package.json
file add the following configuration
"incrementalTests": {
"ignoredFilesPatterns": [
".md",
".eslint*",
"*.json",
"!package.json",
"!package-lock.json",
".mustache",
"*.js"
],
"rootDir": "src/app",
"testCommand": "npm run test"
}
Option | Description |
---|---|
ignoredFilesPatterns | List of files patterns to ignore |
rootDir | your application root directory |
testCommand | The test command to run |
- In your
package.json
file, add the following script:"test:incremental": "node node_modules/angular-incremental-tests/index.js"
- You can then run:
npm run test:incremental
in your ci script.
- The following command is run to list all files names changed in CI between two commits:
git diff --name-only CI_COMMIT_BEFORE_SHA CI_COMMIT_SHA
- So you need to set both environment variables:
CI_COMMIT_BEFORE_SHA
andCI_COMMIT_SHA