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

eslint-plugin-proper-tests

v2.0.0

Published

ESLint rules for writing more proper tests.

Downloads

18

Readme

Installation

npm install -D eslint-plugin-proper-tests

[!NOTE]
For @typescript-eslint v7 use version ^1.0.0 of this plugin. For @typescript-eslint v8 use version ^2.0.0 of this plugin.

Usage

Use the recommended shared config in your .eslintrc configuration file:

module.exports = {
  "extends": ["plugin:proper-tests/recommended"]
}

and you are good to go. Run ESLint and enjoy the results.

Or, alternatively, add proper-tests to the plugins section of your .eslintrc configuration file:

module.exports = {
  "plugins": ["proper-tests"],
  // ...  
}

and configure the rules one by one:

module.exports = {
  "plugins": ["proper-tests"],
  "rules": {
    "proper-tests/no-useless-matcher-to-be-defined": "error"
  }
}

This plugin uses TypeScript to provide more accurate results. To enable this, you need to configure ESLint to work with TypeScript:

module.exports = {
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": true,
    "tsconfigRootDir": __dirname,
  }
}

Running rules only on test-related files

The rules provided by this plugin assume that the files they are checking are test-related. This means it's generally not suitable to include them in your top-level configuration as that applies to all files being linted which can include source files.

For .eslintrc configs you can use overrides to have ESLint apply additional rules to specific files:

module.exports = {
  "extends": ["eslint:recommended"],
  "overrides": [
    {
      "files": ["test/**"],
      "plugins": ["proper-tests"],
      "extends": ["plugin:proper-tests/recommended"],
      "rules": { "proper-tests/no-useless-matcher-to-be-defined": "off" }
    }
  ],
  "rules": {
    "indent": ["error", 2]
  }
}

Shareable configurations

Recommended

This plugin exports a recommended configuration that enforces good testing practices.

To enable this configuration with .eslintrc, use the extends property:

{
  "extends": ["plugin:proper-tests/recommended"]
}

and you are done, no other configuration is needed.

Rules

💼 Configurations enabled in.
✅ Set in the recommended configuration.

| Name                             | Description | 💼 | | :--------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------- | :- | | no-long-arrays-in-test-each | Disallow using long arrays with objects inside test.each() or it.each(). Force moving them out of the file. | ✅ | | no-mixed-expectation-groups | Disallow mixing expectations for different variables between each other. | ✅ | | no-useless-matcher-to-be-defined | Disallow using .toBeDefined() matcher when it is known that variable is always defined. | ✅ | | no-useless-matcher-to-be-null | Disallow using .toBeNull() when TypeScript types conflict with it. | ✅ |

In order to use the rules powered by TypeScript type-checking, you must be using @typescript-eslint/parser & adjust your eslint config as outlined here.

Related Projects

eslint-plugin-jest

The main plugin to be installed when Jest is used.

https://github.com/jest-community/eslint-plugin-jest

eslint-plugin-jest-formatting

This project aims to provide formatting rules (auto-fixable where possible) to ensure consistency and readability in jest test suites.

https://github.com/dangreenisrael/eslint-plugin-jest-formatting