Skip to content

A pre-commit plugin for the angular-cli tester (`ng test`)

License

Notifications You must be signed in to change notification settings

jlcummings/pre-commit-ngtest

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A pre-commit hook for Angular-Cli test

This is the Angular-Cli test (ng test) hook for pre-commit. This hook will prevent git commits if ng test does not pass.

Usage

  • Install pre-commit (see links below).
  • Create a pre-commit config file (.pre-commit-config.yaml).
  • Run pre-commit install from the root of your project.

Finally add this to your .pre-commit-config.yaml:

    -   repo: https://github.com/jlcummings/pre-commit-ngtest
        rev: v.0.0.1-a  # Use the sha or tag (e.g. 'stable') you want to point at
        hooks:
        -   id: ngtest

When making a commit, the hook will run ng test on the staged files and if errors or warnings are raised, the commit will be blocked.

Caveats

If args are provided in the pre-commit configuration, the final element must be '--' in order to distinguish between ng test options and the filenames to be tested.

By default, pre-commit-ngtest makes use of the "--files" argument on ng test so that only files staged for commit are passed through ng test. This keeps the tester runtime to a minimum.

Unfortunately, the combination of Angular-cli's support for multiple 'projects' (e.g. 'src' and 'e2e') and the "--files" argument on ng test can cause errors indicating that a particular file is not part of a given project. This can be worked-around by being more explicit in setting the 'excludes' property on the 'test' project configuration (angular.json). This can be tedious but keeps the commit times to a minimum.

Links

Copyright and License Information

Copyright (c) 2020 Justin Cummings, and individual contributors. All rights reserved.

See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.

About

A pre-commit plugin for the angular-cli tester (`ng test`)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%