All Projects → rstacruz → Mocha Standard

rstacruz / Mocha Standard

Licence: mit
Integrate JS standard tests into your Mocha suite

Programming Languages

javascript
184084 projects - #8 most used programming language

mocha-standard

Integrates standard into your mocha tests. This allows you to enforce a "one true" JavaScript coding style in your project via Mocha tests.



Status


Features

This offers a finer alternative to adding standard into package.json's scripts.test block.

  • Runs in the same node process as mocha, removing maybe 500ms of startup time.
  • Use mocha --watch to recheck for style failures. standard is used programatically, removing a huge overhead (around 1500ms) in re-running it repeatedly with --watch.
  • Painlessly integrate standard into your travisci.org tests.

(Your speed gains may be a bit different from my Pentium II, of course.)


Usage

Install it:

npm install --save-dev mocha-standard standard

Then add this test file to your Mocha suite:

/* test/standard_test.js */
it('conforms to standard', require('mocha-standard'))

To configure what files to consume:

var standard = require('mocha-standard')

it('conforms to standard', standard.files([
  'index.js', 'test/*.js'
]))

Timeouts

Since the first run of a standard test takes a while to execute (sometimes more than Mocha's default 2 second timeout), it'd be wise to change the timeout for your mocha-standard tests. You can do this using this.timeout inside a describe() block, or with --timeout in mocha.opts.

describe('coding style', function () {
  this.timeout(5000)

  it('conforms to standard', require('mocha-standard'))
})

Globals

To specify global variables, pass { global: [...] } into .files(). This is especially useful for Mocha test files. (Be sure you're using standard 5.0.0 or above.)

var standard = require('mocha-standard')

describe('coding style', function () {
  this.timeout(5000)

  it('lib conforms to standard', standard.files([
    '*.js',
    'lib/**/*.js'
  ]))

  it('tests conform to standard', standard.files([
    'test/**/*.js'
  ], {
    global: ['describe', 'it', 'before', 'beforeEach', 'after', 'afterEach', 'xdescribe', 'xit']
  }))
  })

Semicolons

To use semistandard instead, use:

npm install --save-dev mocha-standard semistandard
/* test/standard_test.js */
it('conforms to standard', require('mocha-standard/semistandard'))

Thanks

mocha-standard © 2015+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].