mocha-jshint
Advanced tools
Comparing version 2.1.1 to 2.2.0
75
index.js
var path = require('path'); | ||
var format = require('util').format; | ||
var jsHintCliPath = path.resolve(path.dirname(require.resolve('jshint')), 'cli.js'); | ||
delete require.cache[jsHintCliPath]; | ||
var jsHint = require(jsHintCliPath); | ||
function runJSHint(files, cb) { | ||
var err = new Error(''); | ||
err.message = ''; | ||
err.stack = ''; | ||
var options = { | ||
args: files, | ||
verbose: true, | ||
reporter: require('./reporter.js')(err) | ||
}; | ||
jsHint.run(options); | ||
if (err.message) { | ||
return cb(err); | ||
} | ||
return cb(); | ||
} | ||
module.exports = function (opt) { | ||
describe('jshint', function () { | ||
it('should pass for working directory', function (done) { | ||
opt = opt || {}; | ||
if (opt && opt.git) { | ||
return require('./git')(opt.git, run); | ||
} | ||
return run(null, ['.']); | ||
function run(err, paths) { | ||
describe(opt.title || 'jshint', function () { | ||
this.timeout && this.timeout(30000); | ||
if (opt && opt.git) { | ||
return require('./git')(opt.git, run); | ||
if (!opt.paths) { | ||
return it('should pass for working directory', function (done) { | ||
if (err) { | ||
return done(err); | ||
} | ||
if (paths.length === 0) { | ||
return done(); | ||
} | ||
runJSHint(paths, done); | ||
}); | ||
} | ||
return run(null, ['.']); | ||
opt.paths.forEach(function (p) { | ||
it(format('should pass for %s', JSON.stringify(p)), function (done) { | ||
runJSHint([p], done); | ||
}); | ||
function run(err, files) { | ||
if (err) { | ||
return done(err); | ||
} | ||
if (files.length === 0) { | ||
return done(); | ||
} | ||
var jsHintCliPath = path.resolve(path.dirname(require.resolve('jshint')), 'cli.js'); | ||
delete require.cache[jsHintCliPath]; | ||
var jsHint = require(jsHintCliPath); | ||
var error = new Error(''); | ||
error.message = ''; | ||
error.stack = ''; | ||
var options = { | ||
args: files, | ||
verbose: true, | ||
reporter: require('./reporter.js')(error) | ||
}; | ||
jsHint.run(options); | ||
if (error.message) { | ||
return done(error); | ||
} | ||
return done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "mocha-jshint", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "run JSHint as mocha tests", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,3 +57,30 @@ mocha-jshint [![npm version](https://badge.fury.io/js/mocha-jshint.svg)](http://badge.fury.io/js/mocha-jshint) [![Build Status](https://travis-ci.org/ebdrup/mocha-jshint.svg?branch=master)](https://travis-ci.org/ebdrup/mocha-jshint) [![Dependency Status](https://david-dm.org/ebdrup/mocha-jshint.svg)](https://david-dm.org/ebdrup/mocha-jshint) [![devDependency Status](https://david-dm.org/ebdrup/mocha-jshint/dev-status.svg)](https://david-dm.org/ebdrup/mocha-jshint#info=devDependencies) | ||
specifying paths | ||
---------------- | ||
Normally I would recommend configuring what to lint with `.jshintingore` described in | ||
[configuring jshint](https://github.com/ebdrup/mocha-jshint#configuring-jshint). | ||
And just lint the working directory. | ||
But if you want to specify specific paths to lint, you can do the following in your test: | ||
```js | ||
require('mocha-jshint')({ | ||
paths: [ | ||
'/some/path/', | ||
'/some/other/path' | ||
] | ||
}); | ||
``` | ||
Each path may be either a file path or a directory path, and should yield a valid file or directory when passed | ||
through `path.resolve()`. Each path listed in the array will be linted on a separate test. | ||
changing test suite name | ||
------------------------ | ||
The default name for the test suite generated by mocha-jshint is **jshint**, but it may be overridden in the following manner: | ||
```js | ||
require('mocha-jshint')({ | ||
title: 'My custom test suite name' | ||
}); | ||
``` | ||
configuring jshint | ||
@@ -82,2 +109,6 @@ ------------------ | ||
--------------- | ||
2.2: Added `paths` and `title` options. | ||
2.1: Added git `masterDiff` option. | ||
2.0: Added git features. Removed old undocumented paths feature. | ||
@@ -84,0 +115,0 @@ |
8117
121
117