Skip to content

Commit

Permalink
Added gulp automation and jscs linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Scanferla committed May 1, 2015
1 parent 7f4ed60 commit c371d15
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 90 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,2 +1,3 @@
coverage/
node_modules/
node_modules/*
builds/
.publish/
6 changes: 6 additions & 0 deletions .jscsrc
@@ -0,0 +1,6 @@
{
"preset": "crockford",
"requireMultipleVarDecl": null,
"disallowSpacesInNamedFunctionExpression": null,
"disallowDanglingUnderscores": null
}
12 changes: 7 additions & 5 deletions .travis.yml
@@ -1,13 +1,15 @@
language: node_js

node_js:
- "0.12"
- "iojs"
- iojs

services:
- mongodb

env:
- NODE_PATH=./src/

script:
- ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec test/unit/**/*.js
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
- ./node_modules/.bin/mocha test/integration/*.js
- ./node_modules/.bin/jscs src/
- ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec test/unit/**/*.js test/integration/*.js
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
115 changes: 115 additions & 0 deletions gulpfile.js
@@ -0,0 +1,115 @@
var bs = require("browser-sync");
var sh = require("child_process").execSync;
var fs = require("fs");
var gulp = require("gulp");
var ghPages = require("gulp-gh-pages");
var mocha = require("gulp-spawn-mocha");
var mkdirp = require("mkdirp");

/*
* Task to run unit tests
*/
gulp.task("test", function () {
var stream = gulp.src(["./test/unit/**/*.js", "./test/integration/**/*.js"])
.pipe(mocha({
reporter: "mochawesome",
istanbul: {
dir: "./builds/coverage/"
},
env: {
NODE_PATH: "./src/",
MOCHAWESOME_REPORTDIR: "./builds/tests/",
MOCHAWESOME_REPORTNAME: "index"
}
}))
.on("error", function (ignore) {
/*
* Failing tests are counted as errors and therefore break the
* stream. Catch and ignore them. Also, terminate the stream,
* otherwise we might have problems with gulp.watch
*/
bs.reload();
stream.end();
})
.pipe(bs.reload({stream: true}));
return stream;
});

/*
* Task to lint source code using jscs
*/
gulp.task("jscs", function () {
/*
* Generate the report
*/
mkdirp.sync("./builds/jscs/");
try {
sh("../../node_modules/.bin/jscs ../../src/ --reporter ../../node_modules/jscs-html-reporter/jscs-html-reporter.js", {
cwd: "./builds/jscs/"
});
} catch (ignore) {
// Prevent exiting the process on jscs errors
}
/*
* Copy resources needed by the html reporter over to ./builds/jscs/
*/
sh("cp ./node_modules/jscs-html-reporter/jscs-html-reporter.css ./builds/jscs/");
sh("cp ./node_modules/jscs-html-reporter/toggle.js ./builds/jscs/");
/*
* Replace resources paths, since we copy those resources over to
* ./builds/jscs/
*/
var htmlReport = fs.readFileSync("./builds/jscs/jscs-html-report.html", "utf8");
htmlReport = htmlReport.replace(
new RegExp("../../node_modules/jscs-html-reporter/", "g"),
""
);
fs.writeFileSync("./builds/jscs/index.html", htmlReport, "utf8");
sh("rm ./builds/jscs/jscs-html-report.html");
/*
* BrowserSync reload
*/
bs.reload();
});

/*
* Setup the development server
*/
gulp.task("server", function() {
bs({
server: {
baseDir: "./builds/",
directory: true
},
port: 8080,
ghostMode: false,
injectChanges: false,
notify: false
});
});

/*
* Task to rerun tests and linting on file change
*/
gulp.task("dev", ["server"], function () {
return gulp.watch([
"src/**/*.js",
"test/**/*.js"
], ["jscs", "test"]);
});

/*
* Task to deploy to github pages
*/
gulp.task("gh-pages", ["test", "jscs"], function() {
return gulp.src("./builds/**/*").pipe(ghPages());
});

/*
* Default task
*/
gulp.task("default", [
"jscs",
"test",
"dev"
]);
42 changes: 25 additions & 17 deletions package.json
Expand Up @@ -2,22 +2,19 @@
"name": "meteor-wapi",
"version": "0.3.0",
"description": "Node module to allow CQRS-ing with Meteor",
"repository": {
"type": "git",
"url": "https://github.com/mondora-labs/meteor-wapi"
},
"main": "src/mw.js",
"scripts": {
"unit-tests": "node_modules/.bin/mocha test/unit/**/*.js",
"integration-tests": "node_modules/.bin/mocha test/integration/*.js",
"test": "node_modules/.bin/mocha test/integration/*.js test/unit/**/*.js",
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec test/unit/**/*.js"
"dev": "node_modules/.bin/gulp",
"test": "NODE_PATH=./src/ node_modules/.bin/mocha -R spec test/unit/**/*.js test/integration/*.js",
"unit-tests": "NODE_PATH=./src/ node_modules/.bin/mocha -R spec test/unit/**/*.js",
"integration-tests": "node_modules/.bin/mocha -R spec test/integration/*.js"
},
"repository": {
"type": "git",
"url": "https://github.com/mondora-labs/meteor-wapi.git"
},
"author": "Paolo Scanferla <paolo.scanferla@mondora.com>",
"license": "MIT",
"peerDependencies": {
"express": "^4.12.3"
},
"dependencies": {
"bluebird": "^2.9.15",
"body-parser": "^1.12.2",
Expand All @@ -26,13 +23,24 @@
"tcomb-validation": "^1.0.1"
},
"devDependencies": {
"browser-sync": "^2.6.4",
"coveralls": "^2.11.2",
"express": "^4.12.3",
"istanbul": "^0.3.11",
"mocha": "^2.2.1",
"mongodb": "^2.0.25",
"should": "^5.2.0",
"gulp": "^3.8.11",
"gulp-gh-pages": "^0.5.1",
"gulp-spawn-mocha": "^2.0.1",
"istanbul": "^0.3.13",
"jscs": "^1.12.0",
"jscs-html-reporter": "0.0.4",
"mkdirp": "^0.5.0",
"mocha": "^2.2.4",
"mochawesome": "^1.1.1",
"mongodb": "^2.0.28",
"should": "^6.0.1",
"should-promised": "^0.2.1",
"sinon": "^1.14.1",
"supertest": "^0.15.0"
"supertest-as-promised": "^2.0.0"
},
"peerDependencies": {
"express": "^4.12.3"
}
}
15 changes: 7 additions & 8 deletions test/integration/bad-requests.js
@@ -1,9 +1,8 @@
var BPromise = require("bluebird");
var bodyParser = require("body-parser");
var express = require("express");
var request = require("supertest");
var BPromise = require("bluebird");
var express = require("express");
var request = require("supertest-as-promised");

var MW = require("../../src/mw.js");
var MW = require("../../");
var st = require("../st.js");

describe("Integration suite - Bad requests", function () {
Expand All @@ -18,14 +17,14 @@ describe("Integration suite - Bad requests", function () {
return st.teardown(db);
});

it("the server should reply a 400 on malformed body", function (done) {
it("the server should reply a 400 on malformed body", function () {
var mw = new MW(db);
var app = express().use("/", mw.getRouter());
request(app)
return request(app)
.post("/")
.send({unexpectedProp: "unexpectedValue"})
.expect("Content-Type", /json/)
.expect(400, done);
.expect(400);
});

});

0 comments on commit c371d15

Please sign in to comment.