Skip to content

Commit

Permalink
Added unit testing in node, updated gulp file to test node, merged lc…
Browse files Browse the repository at this point in the history
…ov results using gulp task + added some dev dependencies
  • Loading branch information
mdvorscak committed Apr 8, 2015
1 parent c60a634 commit 1e97e9b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
42 changes: 40 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,53 @@
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var header = require('gulp-header');
//Test libs
var karma = require('karma').server;
var jasmine = require('gulp-jasmine');
var istanbul = require('gulp-istanbul');
var lcovMerger = require('lcov-result-merger');

gulp.task('test', function (done) {
gulp.task('browser-test', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun : true
}, done);
});

gulp.task('build-node-test', function () {
return gulp.src('test/main.js')
.pipe(header("var cloak = require('../cloak.js');"))
.pipe(rename({
extname: '-node.js'
}))
.pipe(gulp.dest('test/'));
;
});

gulp.task('node-test', ['build-node-test'], function (done) {
gulp.src('cloak.js')
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
gulp.src('test/*-node.js')
.pipe(jasmine())
.pipe(istanbul.writeReports({
dir: './coverage/node'
}))
.on('end', done);
});
});

gulp.task('test', ['browser-test', 'node-test'], function(){
return gulp.src('coverage/**/lcov.info')
.pipe(lcovMerger())
.pipe(rename({
extname: '-merged.info'
}))
.pipe(gulp.dest('coverage'));
});

gulp.task('tdd', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js'
Expand All @@ -29,7 +67,7 @@ gulp.task('scripts', function () {
.pipe(gulp.dest(''));
});

gulp.task('dev', ['tdd'], function(){
gulp.task('dev', ['tdd'], function () {
gulp.watch('cloak.js', ['scripts']);
});

Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function (config) {


// list of files to exclude
exclude: [],
exclude: ['test/*-node.js'],


// preprocess matching files before serving them to the browser
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@
"directories": {
"test": "test"
},
"repository" : {
"type" : "git",
"url" : "http://github.com/mdvorscak/cloakjs"
"repository": {
"type": "git",
"url": "http://github.com/mdvorscak/cloakjs"
},
"dependencies": {},
"devDependencies": {
"coveralls": "^2.11.2",
"gulp": "^3.8.11",
"gulp-header": "^1.2.2",
"gulp-istanbul": "^0.8.1",
"gulp-jasmine": "^2.0.1",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.1.0",
"jasmine-core": "^2.2.0",
"karma": "^0.12.31",
"karma-chrome-launcher": "^0.1.7",
"karma-coverage": "^0.2.7",
"karma-jasmine": "^0.3.5"
"karma-jasmine": "^0.3.5",
"lcov-result-merger": "^1.0.2"
},
"scripts": {
"test": "gulp test",
"coveralls": "cat ./coverage/**/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
"coveralls": "cat ./coverage/lcov-merged.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"keywords": [
"AOP",
Expand Down
10 changes: 5 additions & 5 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ describe('cloak.js suite', function () {

it('should allow the next cloakWith call to be applied when the condition passed is true', function () {
function logFn() {
console.log('No alerts allowed');
console.log('No warnings allowed');
}

cloak(window, 'alert').when(true).cloakWith(logFn);
cloak(console, 'warn').when(true).cloakWith(logFn);
spyOn(console, 'log');

alert('Hi');
expect(console.log).toHaveBeenCalledWith('No alerts allowed');
console.warn('Hi');
expect(console.log).toHaveBeenCalledWith('No warnings allowed');
});
});

Expand Down Expand Up @@ -355,7 +355,7 @@ describe('cloak.js suite', function () {
describe('and', function(){
it('should chain together two functions with no effect', function(){
expect(function(){
cloak(window, 'alert').cloakWith(console.log).and.when(false).cloakWith(nop);
cloak(console, 'warn').cloakWith(console.log).and.when(false).cloakWith(nop);
});
});
});
Expand Down

0 comments on commit 1e97e9b

Please sign in to comment.