Skip to content

Commit

Permalink
Add JSHint and Editorconfig.
Browse files Browse the repository at this point in the history
Include JSHint in Grunt default task.
  • Loading branch information
Yakov Khalinsky committed Jan 19, 2015
1 parent 992deb6 commit 3f5af87
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 49 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
17 changes: 17 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -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
}
}
84 changes: 50 additions & 34 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
};
2 changes: 1 addition & 1 deletion lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -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();
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion test/lib/final-callback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function(done) {
return function(err, res){
return function(err){
if (err) {
return done(err);
}
Expand Down
19 changes: 10 additions & 9 deletions test/simple-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
Expand All @@ -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));
});
Expand All @@ -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));
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/static-content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});

0 comments on commit 3f5af87

Please sign in to comment.