Skip to content

Commit

Permalink
fix(coverage): Add new GitHub Action for code coverage and update REA…
Browse files Browse the repository at this point in the history
…DME badges

This commit introduces a new GitHub Action that performs code coverage checks on the 'main' and 'beta' branches. It adds several new badges to the README file, including workflow status, issues, and pull request statistics. The README also includes minor formatting and content improvements, making the text clearer and optimizing the layout for better readability.
  • Loading branch information
Theshedman committed Nov 28, 2023
1 parent d6b0d6a commit 2f33cb6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'coverage'
on:
push:
branches:
- main
- beta
jobs:
coverage:
permissions:
checks: write
pull-requests: write
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: jwalton/gh-find-current-pr@v1
id: findPr
- uses: ArtiomTr/jest-coverage-report-action@v2
with:
test-script: npm test
prnumber: ${{ steps.findPr.outputs.number }}
46 changes: 29 additions & 17 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
</a>

<a href="https://github.com/Theshedman/password-validator.js" style="text-decoration:none">
<img src="https://img.shields.io/github/workflow/status/Theshedman/password-validator/build-ci?logo=github" />
<img src="https://img.shields.io/github/actions/workflow/status/Theshedman/password-validator.js/.github%2Fworkflows%2Frelease.yaml
?branch=main" />
</a>

<a href="https://github.com/Theshedman/password-validator.js" style="text-decoration:none">
<img src="https://img.shields.io/github/languages/top/Theshedman/password-validator.js.svg" />
<img src="https://img.shields.io/github/issues/Theshedman/password-validator.js" />
</a>

<a href="https://github.com/Theshedman/password-validator.js" style="text-decoration:none">
<img src="https://img.shields.io/github/issues-pr/Theshedman/password-validator.js" />
</a>

<a href="https://github.com/Theshedman/password-validator.js" style="text-decoration:none">
<img src="https://img.shields.io/npm/l/%40password-validator%2Fcore" />
</a>
</div>

Expand Down Expand Up @@ -52,15 +61,18 @@ const result = pm.validate('MyPassword123'); // { valid: false, messages: ['must

### Validators

A validator is class that can validate a password and return a result. Validators should typically be registered with the `PasswordValidatorManager` (as shown above). The library comes with a number of validators (see table below) that can be used to build a validation suite.
A validator is class that can validate a password and return a result. Validators should typically be registered with the `PasswordValidatorManager` (as shown above). The library
comes with a number of validators (see table below) that can be used to build a validation suite.

Each validator receives a `passwordRule` _(number)_ argument in its constructor which defines the number of expected characters associated with the validator. For example, the `const minLength = new MinLengthValidator(10)` defined above means that the passowrd must be atleast __10 characters__ long to be considered valid.
Each validator receives a `passwordRule` _(number)_ argument in its constructor which defines the number of expected characters associated with the validator. For example,
the `const minLength = new MinLengthValidator(10)` defined above means that the passowrd must be atleast __10 characters__ long to be considered valid.

NB: The only exception to this is the `NoSpaceCharacterValidator` which requires no arguments and simply ensures the password contains no spaces.

### Conflicting Validators

In a case of conflict validations, for example, a password must be __12 characters long minimum__, and also be __8 characters maximum__, we throw a `PasswordValidatorConflictException` error. This is because minimum length cannot be greater than maximum length.
In a case of conflict validations, for example, a password must be __12 characters long minimum__, and also be __8 characters maximum__, we throw
a `PasswordValidatorConflictException` error. This is because minimum length cannot be greater than maximum length.

```ts
import { MinLengthValidator, MaxLengthValidator } from '@password-validator/core';
Expand All @@ -79,17 +91,17 @@ const result = pm.validate('MyPassword123!*') // Throws PasswordValidatorConflic

Supported Validators and Managers as of now are:

| Rules | Descriptions |
|:---------------------|:---------------------------------------------------------------------------------------------------------------------------------|
| **Validations** |
|**DigitValidator(passwordRule: number)** | specifies password must include _passwordRule_ number of digits |
|**LowerCaseValidator(passwordRule: number)** | specifies password must include at least _passwordRule_ number of lowercase character(s) |
|**UpperCaseValidator(passwordRule: number)**| specifies password must include at least _passwordRule_ number of uppercase character(s) |
|**MaxLengthValidator(passwordRule: number)**| specifies password must not exceed _passwordRule_ number of character(s) |
|**MinLengthValidator(passwordRule: number)** | specifies password must not be less than _passwordRule_ number of character(s) |
|**SpecialCharacterValidator(passwordRule: number)** | specifies password must include at least _passwordRule_ number of special character(s) |
|**NoSpaceCharacterValidator()** | specifies password must not include spaces |
| **Managers** |
|**PasswordValidatorManager().register(...validators: PasswordValidator[])** | Register multiple validators at once to build a validation suite. |
| Rules | Descriptions |
|:----------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------|
| **Validations** |
| **DigitValidator(passwordRule: number)** | specifies password must include _passwordRule_ number of digits |
| **LowerCaseValidator(passwordRule: number)** | specifies password must include at least _passwordRule_ number of lowercase character(s) |
| **UpperCaseValidator(passwordRule: number)** | specifies password must include at least _passwordRule_ number of uppercase character(s) |
| **MaxLengthValidator(passwordRule: number)** | specifies password must not exceed _passwordRule_ number of character(s) |
| **MinLengthValidator(passwordRule: number)** | specifies password must not be less than _passwordRule_ number of character(s) |
| **SpecialCharacterValidator(passwordRule: number)** | specifies password must include at least _passwordRule_ number of special character(s) |
| **NoSpaceCharacterValidator()** | specifies password must not include spaces |
| **Managers** |
| **PasswordValidatorManager().register(...validators: PasswordValidator[])** | Register multiple validators at once to build a validation suite. |


1 comment on commit 2f33cb6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/npm' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.89% 136/148
🟢 Branches 92.31% 36/39
🟢 Functions 93.22% 55/59
🟢 Lines 91.72% 133/145

Test suite run failed

Failed tests: 0/62. Failed suites: 0/1.

Report generated by 🧪jest coverage report action from 2f33cb6

Please sign in to comment.