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

gaffe

v1.1.0

Published

We, as humans, sometimes accidentally make mistakes in test cases. Such as leave '.only', 'iit', 'ddescribe'

Downloads

9

Readme

Gaffe

We, as humans, sometimes accidentally make mistakes in test cases. Such as leave '.only', 'iit', 'ddescribe'.

Story so far


Most of the time, Developers need to run a single test case or a single block of test cases. To achieve this requirement, test frameworks provide different functionalities.

Eg:

  • Mocha : it.only, describe.only
  • Jasmine: fit/~~iit~~, fdescribe/~~ddescribe~~
  • lab: lab.it.only

So, what is the issue?


Sometimes, developers accidently commit their test cases with these keywords. As the result, when running tests through a CI interface or any other testing environments, all the test cases won't get executed.

And.. we have a big issue :).

So, Can we introduce some kind of Linting ?


I dig around and try to add a new rule to ESLint since, its my favourite. But, the contribution guide states that, Rules must be based solely on JavaScript runtime environments and not on specific libraries or frameworks.

So, I thought of developing this module.

How to define rules


A set of default set of rules are defined in the gaffe.json as follows.

[
    {
        "suite": "mocha",
        "rules": [
            "no_it_only",
            "no_describe_only"
        ]
    },
    {
        "suite": "jasmine",
        "rules": [
            "no_ddescribe",
            "no_fdescribe",
            "no_fit",
            "no_iit"
        ]
    },
    {
        "suite": "custom",
        "rules" : [
            "^[\\s]*lab\\.test\\.only[\\(\\s]"
        ]
    }
]

To override these rules, you have to add your own gaffe.json to your application folder. Then add rules.

Eg:

  • If you only use Mocha then,
[
    {
        "suite": "mocha",
        "rules": [
            "no_it_only",
            "no_describe_only"
        ]
    }
]
  • If you use only Jasmine then,
[

    {
        "suite": "jasmine",
        "rules": [
            "no_ddescribe",
            "no_fdescribe",
            "no_fit",
            "no_iit"
        ]
    }
]
  • if you want to add only the custom rules,
[
    {
        "suite": "custom",
        "rules" : [
            "^[\\s]*lab\\.test\\.only[\\(\\s]"
        ]
    }
]

How to use a rule file in a different location

Its easy. create a rule file by following above samples and save it as a json file. Then follow the below mentioned command.

./gaffe -s <path to your rule file> <your test cases>

eg:

./gaffe -s ../my_app/gaffe.json `find test -name \'*.js\'`

What is a 'Custom' rule

This feature enables you to add your own set of experience to run against the files which contains the test cases.

Add the custom rule as follows.

/*
1. Only one 'custom' object is allowed in the config.
2. All the reqular expressions are must be escaped.
eg: ^[\s]*lab\.test\.only[\(\s] has to used as "^[\\s]*lab\\.test\\.only[\\(\\s]"
*/
[
    {
        "suite": "custom",
        "rules" : [
            "Your regular expression 1"
            "Your regular expression 2"

        ]
    }
]

How to use

After defining the set of rules, use one of following commands to execute the module.

./node_modules/.bin/gaffe <list of .js or .coffee files with test cases>

Eg:

./node_modules/.bin/gaffe `find test -name '*.js'`
Adding to your linting script in package.json

This is how I usually do it.

{
  "name": "myapp",
  "version": "1.0.0",
  "description": "my test app",
  "scripts": {
    "start": "node main",
    "lint-js": "eslint -c eslint.json .",
    "lint-test": "./node_modules/.bin/gaffe `find test -name '*.js'`",
    "lint": "npm run lint-js && npm run lint-test"
  },
  "author": "Ruwan Geeganage",
  "license": "MIT",
}

and run below command,

npm run lint

Contribute


Fork this repository and add your test cases under rules/ folder and add test cases. Follow the existing rule implementation.