Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Neizan93/jest-angular-test-verifier
Jest reporter to verify all essential Angular files have associated test files, ensuring comprehensive test coverage.
https://github.com/Neizan93/jest-angular-test-verifier
Last synced: 26 days ago
JSON representation
Jest reporter to verify all essential Angular files have associated test files, ensuring comprehensive test coverage.
- Host: GitHub
- URL: https://github.com/Neizan93/jest-angular-test-verifier
- Owner: Neizan93
- License: mit
- Created: 2023-08-06T15:27:08.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-06T19:24:31.000Z (over 1 year ago)
- Last Synced: 2024-11-13T10:08:00.562Z (about 1 month ago)
- Language: JavaScript
- Size: 84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-jest - jest-angular-test-verifier
README
# jest-angular-test-verifier
A custom Jest reporter specifically designed for Angular projects. This reporter checks and ensures that specific types of files (components, services, directives, etc.) have their corresponding test file.
## Installation
Install the package using npm:
```bash
npm install jest-angular-test-verifier --save-dev
```## Usage
In your Jest configuration file (e.g., `jest.config.js`), add `jest-angular-test-verifier` to your list of reporters:
```javascript
module.exports = {
// ... other Jest configuration options
reporters: ["default", "jest-angular-test-verifier"]
};
```## Simple Configuration
If you just want to get started quickly without too much configuration, you can use the following simple setup in your Jest configuration file:
```javascript
module.exports = {
// ... other Jest configuration options
reporters: [
"default",
["jest-angular-test-verifier", {
failOnMissingTests: true
}]
]
};
```With this simple configuration, the reporter will start checking for test files in the default directory `'src/app'` and it will display an error and fail the tests if any of the specified file types (components, services, guards, directives, and pipes) are missing their corresponding test files.
Feel free to customize the configuration further by adding more options as needed, but this simple setup should get you started quickly.
## Configuration Options
You can configure the reporter by providing a second argument with options in your configuration file:
```javascript
module.exports = {
// ... other Jest configuration options
reporters: [
"default",
["jest-angular-test-verifier", {
directory: "src/app",
showTestedFiles: false,
failOnMissingTests: true,
exclusions: ['**/*.module.ts', 'src/app/somefolder/**'],
exclusionRules: [/DEPRECATED/, "TO_BE_REMOVED"],
}]
]
};
```### Directory
Specifies the directory from where the reporter should start checking for test files.
* Default: `'src/app'`
### Extensions
Define which types of files you want to ensure have tests. By default, the reporter checks for components, services, guards, directives, and pipes.
* Default:
```javascript
[
'.component.ts',
'.service.ts',
'.guard.ts',
'.directive.ts',
'.pipe.ts'
]
```
Example:
```javascript
module.exports = {
// ... other Jest configuration options
reporters: [
"default",
["jest-angular-test-verifier", {
...
extensions: ['.component.ts', '.service.ts']
}]
]
};
```### ShowTestedFiles
Determines whether the reporter should display files that already have associated test files.
* Default: `false`
### FailOnMissingTests
Indicates whether Jest should terminate with a failure if it finds files that are missing test files.
* Default: `true`
### ShowStatistics
Determines whether the reporter should display statistics about the total files checked, how many have tests, and how many are missing tests.
* Default: `false`
Example:
```javascript
module.exports = {
// ... other Jest configuration options
reporters: [
"default",
["jest-angular-test-verifier", {
...
showStatistics: true
}]
]
};
```### Exclusions
Using the `exclusions` option, you can define specific files or directories that you want the reporter to skip. This is particularly useful when you have certain files or folders in your project that you know shouldn't have tests.
The exclusions accept glob patterns, allowing for flexible configurations:
* `'**/*.module.ts'` - will exclude all module files in your project.
* `'src/app/somefolder/**'` - will exclude everything within `src/app/somefolder/`.### ExclusionRules
Allows you to exclude files based on content using strings or regular expressions. For example, if you have deprecated files containing the "DEPRECATED" string, you can easily exclude them without needing to rely on filenames or paths.
Examples:
* Using a string: `"TO_BE_REMOVED"` would exclude any file containing that exact string.
* Using a regular expression: `/DEPRECATED/` would exclude any file containing the word "DEPRECATED".### DepthLevel
Allows you to specify how many levels of subdirectories you want to check for test files. A value of `1` will check only the files and directories directly inside the specified directory. A value of `2` will check those and their immediate subdirectories, and so on.
* Default: `Infinity` (All subdirectories will be checked)
Example:
```javascript
module.exports = {
// ... other Jest configuration options
reporters: [
"default",
["jest-angular-test-verifier", {
...
depthLevel: 2
}]
]
};
```### MockIdentifier
Determines the string used to identify mock files in your project. This is useful if you have a different naming convention for mock files than the standard 'mock'.
* Default: `'mock'`
### Congratulations Messages
You can customize the congratulatory messages displayed when all necessary files have tests. Provide an array of messages, and a random one will be chosen when all files are covered:
```javascript
module.exports = {
// ... other Jest configuration options
reporters: [
"default",
["jest-angular-test-verifier", {
directory: "src/app",
extensions: ['.component.ts', '.service.ts'],
showTestedFiles: false,
failOnMissingTests: true,
showStatistics: true,
exclusions: ['**/*.module.ts', 'src/app/somefolder/**'],
exclusionRules: [/DEPRECATED/, "TO_BE_REMOVED"],
depthLevel: 2,
mockIdentifier: 'mock',
congratulations: [
"🚀 Awesome! All files are covered.",
"💡 Brilliance! Every file has a test.",
"🔥 Blazing! 100% of files have tests."
]
}]
]
};
```## License
[MIT](./LICENSE)