diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a882442 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..b11c909 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,17 @@ +{ + "curly": true, + "eqnull": true, + "eqeqeq": true, + "undef": true, + "unused": true, + "smarttabs": false, + "quotmark": "single", + "node": true, + "globals": { + "it": false, + "console": false, + "describe": false, + "expect": false, + "beforeEach": false + } +} diff --git a/Gruntfile.js b/Gruntfile.js index 76f0af7..ec7f085 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,38 +2,54 @@ var drakov = require('./lib/drakov'); module.exports = function (grunt) { - var properties = { - drakov: { - sourceFiles: 'test/example/**/*.md', - serverPort: 3000, - staticPaths: 'test/example/static' - } - }; - - grunt.initConfig({ - simplemocha: { - options: { - globals: ['should'], - timeout: 3000, - ignoreLeaks: false, - //grep: '*-test', - ui: 'bdd', - reporter: 'tap' - }, - - all: { src: 'test/*.js' } - } - }); - - // For this to work, you need to have run `npm install grunt-simple-mocha` - grunt.loadNpmTasks('grunt-simple-mocha'); - - grunt.task.registerTask('functional-test', 'Log stuff.', function() { - drakov.run(properties.drakov, this.async()); - grunt.task.run('simplemocha'); - }); - - grunt.task.registerTask('test', ['functional-test']); - - grunt.task.registerTask('default', ['test']); + var properties = { + drakov: { + sourceFiles: 'test/example/**/*.md', + serverPort: 3000, + staticPaths: 'test/example/static', + stealthmode: true + } + }; + + grunt.initConfig({ + + jshint: { + options: { + jshintrc: true, + ignores: [ + 'describe', + 'it' + ] + }, + files: [ + 'lib/**/*.js', + 'test/**/*.js', + 'index.js' + ] + }, + + simplemocha: { + options: { + globals: ['should'], + timeout: 3000, + ignoreLeaks: false, + ui: 'bdd', + reporter: 'tap' + }, + + all: {src: 'test/*.js'} + } + }); + + // For this to work, you need to have run `npm install grunt-simple-mocha` + grunt.loadNpmTasks('grunt-simple-mocha'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + + grunt.task.registerTask('functional-test', 'Log stuff.', function () { + drakov.run(properties.drakov, this.async()); + grunt.task.run('simplemocha'); + }); + + grunt.task.registerTask('test', ['functional-test']); + grunt.task.registerTask('default', ['jshint', 'test']); }; diff --git a/lib/content.js b/lib/content.js index b445df4..c7179a5 100644 --- a/lib/content.js +++ b/lib/content.js @@ -48,7 +48,7 @@ exports.matches = function( httpReq, specReq ) { } } else { - console.warn('Skip. Different content-types ', httpMediaType, " !== ", specMediaType ); + console.warn('Skip. Different content-types ', httpMediaType, ' !== ', specMediaType ); return false; } diff --git a/lib/file.js b/lib/file.js index 04b7293..0b3ed03 100644 --- a/lib/file.js +++ b/lib/file.js @@ -6,7 +6,9 @@ var route = require('./route'); exports.readFile = function (app, path) { return function(cb){ fs.readFile(path, function (err, data) { - if (err) throw err; + if (err) { + throw err; + } protagonist.parse(new Buffer(data).toString('utf8'), function(error, result) { if (error) { diff --git a/lib/request.js b/lib/request.js index dbe6ea5..d980719 100644 --- a/lib/request.js +++ b/lib/request.js @@ -4,7 +4,9 @@ var logger = require('./logger'); exports.getBody = function(req, res, next) { req.body = ''; req.setEncoding('utf8'); - req.on('data', function(chunk) { req.body += chunk }); + req.on('data', function(chunk) { + req.body += chunk; + }); req.on('end', next); }; @@ -16,4 +18,4 @@ exports.logger = function(req, res, next) { exports.headers = function(req, res, next) { res.set('X-Powered-By', 'Drakov API Server'); next(); -} +}; diff --git a/package.json b/package.json index 0593386..3056523 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "protagonist": "0.12.0" }, "devDependencies": { + "grunt-contrib-jshint": "^0.10.0", "grunt-simple-mocha": "^0.4.0", "supertest": "^0.15.0" } diff --git a/test/lib/final-callback.js b/test/lib/final-callback.js index 98297f3..e0edfb7 100644 --- a/test/lib/final-callback.js +++ b/test/lib/final-callback.js @@ -1,5 +1,5 @@ module.exports = function(done) { - return function(err, res){ + return function(err){ if (err) { return done(err); } diff --git a/test/simple-api-test.js b/test/simple-api-test.js index 74c49ae..62a4333 100644 --- a/test/simple-api-test.js +++ b/test/simple-api-test.js @@ -7,11 +7,13 @@ describe('/api/things', function(){ request.get('/api/things') .expect(200) .expect('Content-type', 'application/json; charset=utf-8') - .expect([{"text":"Zip2","id": "1"}, - {"text":"X.com", "id": "2"}, - {"text":"SpaceX", "id": "3"}, - {"text":"Solar City", "id": "4"}, - {"text":"Hyperloop", "id": "5"}]) + .expect([ + {text:'Zip2',id: '1'}, + {text: 'X.com', id: '2'}, + {text: 'SpaceX', id: '3'}, + {text: 'Solar City', id: '4'}, + {text: 'Hyperloop', id: '5'} + ]) .end(endCB(done)); }); }); @@ -23,7 +25,7 @@ describe('/api/things/{thingId}', function(){ request.get('/api/things/1111') .expect(200) .expect('Content-type', 'application/json; charset=utf-8') - .expect([{"text":"Zip2","id": "1"} + .expect([{text: 'Zip2', id: '1'} ]) .end(endCB(done)); }); @@ -33,10 +35,9 @@ describe('/api/things/{thingId}', function(){ it('should respond with json object from contract example', function(done){ request.post('/api/things/1111') .set('Content-type', 'application/json') - .send({"text": "Hyperspeed jet","id": "1"}) + .send({text: 'Hyperspeed jet', id: '1'}) .expect(200) - //.expect('Content-type', 'application/json; charset=utf-8') - .expect({"text": "Hyperspeed jet", "id": "1"}) + .expect({text: 'Hyperspeed jet', id: '1'}) .end(endCB(done)); }); }); diff --git a/test/static-content-test.js b/test/static-content-test.js index c7eb645..884ac6c 100644 --- a/test/static-content-test.js +++ b/test/static-content-test.js @@ -6,7 +6,7 @@ describe('Static content', function(){ request.get('/things.txt') .expect(200) .expect('Content-type', 'text/plain; charset=UTF-8') - .expect("Zip2\nX.com\nSpaceX\nSolar City\nHyperloop\n") + .expect('Zip2\nX.com\nSpaceX\nSolar City\nHyperloop\n') .end(endCB(done)); }); });