npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jest-angular-test-verifier

v1.0.4

Published

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.

Downloads

1

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:

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:

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:

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:

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:

    [
      '.component.ts',
      '.service.ts',
      '.guard.ts',
      '.directive.ts',
      '.pipe.ts'
    ]

Example:

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:

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:

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:

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