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

coffeelint-mocha

v0.1.0

Published

CoffeeLint rules for Mocha test framework

Downloads

788

Readme

coffeelint-mocha

Build Status Coverage Status

CoffeeLint rules for Mocha test framework.

It a port of eslint-plugin-mocha to CoffeeLint.

Installation

To install the package, run:

npm install coffeelint-mocha --save-dev

Example

Add rules to your coffeelint.json:

{
  "handle_done_callback": {
    "module": "coffeelint-mocha/handle_done_callback",
    "level": "error"
  },
  "no_exclusive_tests": {
    "module": "coffeelint-mocha/no_exclusive_tests",
    "level": "error"
  },
  "no_global_tests": {
    "module": "coffeelint-mocha/no_global_tests",
    "level": "error"
  },
  "no_pending_tests": {
    "module": "coffeelint-mocha/no_pending_tests",
    "level": "error"
  },
  "no_skipped_tests": {
    "module": "coffeelint-mocha/no_skipped_tests",
    "level": "error"
  },
  "no_synchronous_tests": {
    "module": "coffeelint-mocha/no_synchronous_tests",
    "level": "error"
  }
}

Rules

handle_done_callback

Mocha allows you to write asynchronous tests by adding a done callback to the parameters of your test function. It is easy to forget calling this callback after the asynchronous operation is done.

Example:

// Bad
it('returns a user', function (done) {
  getUser(42)
    .then(function (user) {
      assert.deepEqual(user, {id: 42, name: 'Sasha'})
      // done callback wasn't called
    })
})

// Good
it('returns a user', function (done) {
  getUser(42)
    .then(function (user) {
      assert.deepEqual(user, {id: 42, name: 'Sasha'})
      done() // Ok
    })
})

// Good
it('returns a user', function (done) {
  getUser(42)
    .then(function (user) {
      assert.deepEqual(user, {id: 42, name: 'Sasha'})
    })
    .then(done) // Ok
})

To start using the rule, add handle_done_callback to your coffeelint.json:

{
  "handle_done_callback": {
    "module": "coffeelint-mocha/handle_done_callback",
    "level": "error"
  }
}

no_exclusive_tests

Mocha has a feature that allows you to run tests exclusively by appending .only to a test-suite or a test-case. This feature is really helpful to debug a failing test, so you don’t have to execute all of your tests. After you have fixed your test and before committing the changes you have to remove .only to ensure all tests are executed on your build system.

This rule reminds you to remove .only from your tests by raising an error whenever you are using the exclusivity feature.

Example:

// Bad
it.only('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

// Good
it('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

To start using the rule, add no_exclusive_tests to your coffeelint.json:

{
  "no_exclusive_tests": {
    "module": "coffeelint-mocha/no_exclusive_tests",
    "level": "error"
  }
}

no_global_tests

Mocha gives you the possibility to structure your tests inside of suites using describe, suite or context.

Example:

// Bad
it('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

// Good
describe('multiply', function () {
  it('multiples numbers', function () {
    assert.equal(multiply(21, 2), 42)
  })
})

To start using the rule, add no_global_tests to your coffeelint.json:

{
  "no_global_tests": {
    "module": "coffeelint-mocha/no_global_tests",
    "level": "error"
  }
}

no_pending_tests

Mocha allows specification of pending tests, which represent tests that aren't yet implemented, but are intended to be implemented eventually. These are designated like a normal mocha test, but with only the first argument provided (no callback for the actual implementation). For example: it('unimplemented test')

This rule allows you to raise errors on pending tests. This can be useful, for example, for reminding developers that pending tests exist in the repository, so they're more likely to get implemented.

Example:

// Bad
it('multiples numbers')

// Good
it('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

To start using the rule, add no_pending_tests to your coffeelint.json:

{
  "no_pending_tests": {
    "module": "coffeelint-mocha/no_pending_tests",
    "level": "error"
  }
}

no_skipped_tests

Mocha has a feature that allows you to skip tests by appending .skip to a test-suite or a test-case, or by prepending it with an x (e.g., xdescribe(...) instead of describe(...)). Sometimes tests are skipped as part of a debugging process, and aren't intended to be committed. This rule reminds you to remove .skip or the x prefix from your tests.

Example:

// Bad
xit('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

// Bad
it.skip('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

// Good
it('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

To start using the rule, add no_skipped_tests to your coffeelint.json:

{
  "no_skipped_tests": {
    "module": "coffeelint-mocha/no_skipped_tests",
    "level": "error"
  }
}

no_synchronous_tests

Mocha automatically determines whether a test is synchronous or asynchronous based on the arity of the function passed into it. When writing tests for a asynchronous function, omitting the done callback or forgetting to return a promise can often lead to false-positive test cases. This rule warns against the implicit synchronous feature, and should be combined with handle_done_callback for best results.

Example:

// Bad
it('multiples numbers', function () {
  assert.equal(multiply(21, 2), 42)
})

// Good
it('multiples numbers', function (done) {
  assert.equal(multiply(21, 2), 42)
  done()
})

To start using the rule, add no_synchronous_tests to your coffeelint.json:

{
  "no_synchronous_tests": {
    "module": "coffeelint-mocha/no_synchronous_tests",
    "level": "error"
  }
}

License

MIT © Sasha Koss