Skip to content

Commit

Permalink
Update jasmine node reporter to clean up log spew in Node >= 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Kinast committed Mar 24, 2015
1 parent c02b88d commit 0ac0c53
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 33 deletions.
20 changes: 15 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,18 @@ module.exports = function(grunt) {
}
}
},
jasmine_node: {
dustc: ['test/jasmine-test/spec/cli/']
jasmine_nodejs: {
dustc: {
specs: ['test/jasmine-test/spec/cli/*'],
options: {
reporters: {
console: {
colors: false,
verbose: false
}
}
}
}
},
watch: {
lib: {
Expand Down Expand Up @@ -247,7 +257,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.loadNpmTasks('grunt-jasmine-nodejs');

//--------------------------------------------------
//------------Grunt task aliases -------------------
Expand All @@ -259,8 +269,8 @@ module.exports = function(grunt) {
grunt.registerTask('testNode', ['shell:oldTests']);
grunt.registerTask('testRhino', ['build', 'shell:testRhino']);
grunt.registerTask('testPhantom', ['build', 'jasmine:testProd']);
grunt.registerTask('testCli', ['build', 'jasmine_node:dustc']);
grunt.registerTask('test', ['build', 'jasmine:testProd', 'jasmine_node:dustc', 'shell:oldTests', 'shell:testRhino', 'jasmine:coverage']);
grunt.registerTask('testCli', ['build', 'jasmine_nodejs:dustc']);
grunt.registerTask('test', ['build', 'jasmine:testProd', 'jasmine_nodejs:dustc', 'shell:oldTests', 'shell:testRhino', 'jasmine:coverage']);

//task for debugging in browser
grunt.registerTask('dev', ['build', 'jasmine:testDev:build', 'connect:testServer','log:testClient', 'watch:lib']);
Expand Down
8 changes: 5 additions & 3 deletions lib/dust.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@
if (body) {
return body(this, context);
}
dust.log('No block for exists check in template `' + context.getTemplateName() + '`', DEBUG);
} else if (skip) {
return skip(this, context);
}
Expand All @@ -688,6 +689,7 @@
if (body) {
return body(this, context);
}
dust.log('No block for not-exists check in template `' + context.getTemplateName() + '`', DEBUG);
} else if (skip) {
return skip(this, context);
}
Expand Down Expand Up @@ -743,9 +745,9 @@
if(dust.helpers[name]) {
try {
return dust.helpers[name](chunk, context, bodies, params);
} catch(e) {
dust.log('Error in helper `' + name + '`: ' + e.message, ERROR);
return chunk.setError(e);
} catch(err) {
dust.log('Error in helper `' + name + '`: ' + err.message, ERROR);
return chunk.setError(err);
}
} else {
dust.log('Helper `' + name + '` does not exist', WARN);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-watch": "~0.5.3",
"grunt-gh-pages": "~0.9.0",
"grunt-jasmine-node": "~0.2.1",
"grunt-jasmine-nodejs": "~1.0.2",
"grunt-shell": "~0.6.1",
"grunt-template-jasmine-istanbul": "~0.2.5",
"pegjs": "0.8.0"
Expand Down
56 changes: 33 additions & 23 deletions test/jasmine-test/spec/cli/lib/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,44 @@ var fs = require('fs'),

var matchers = {};

matchers.toHaveTemplate = function(expected) {
var dustTemplateRegex = /dust\.register\("([A-z0-9\-_\/\\]+)",body_0\)/g,
matches = [];

this.actual.replace(dustTemplateRegex, function(whole, match) {
matches.push(match);
});

return matches.indexOf(dust.escapeJs(expected)) > -1;
matchers.toHaveTemplate = function(util) {
var dustTemplateRegex = /dust\.register\("([A-z0-9\-_\/\\]+)",body_0\)/g;

return {
compare: function(actual, expected) {
var matches = [];
actual.replace(dustTemplateRegex, function(whole, match) {
matches.push(match);
});
return { pass: matches.indexOf(dust.escapeJs(expected)) > -1 };
}
};
};

matchers.toHaveAMDTemplate = function(expected) {
var dustAMDTemplateRegex = /define\("([A-z0-9\-_\/\\]+)",\["dust\.core"\]/g,
matches = [];

this.actual.replace(dustAMDTemplateRegex, function(whole, match) {
matches.push(match);
});

return matches.indexOf(dust.escapeJs(expected)) > -1 &&
matchers.toHaveTemplate.call(this, expected);
matchers.toHaveAMDTemplate = function(util) {
var dustAMDTemplateRegex = /define\("([A-z0-9\-_\/\\]+)",\["dust\.core"\]/g;

return {
compare: function(actual, expected) {
var matches = [];
actual.replace(dustAMDTemplateRegex, function(whole, match) {
matches.push(match);
});
return { pass: matches.indexOf(dust.escapeJs(expected)) > -1 &&
matchers.toHaveTemplate().compare.call(this, actual, expected) };
}
};
};

matchers.toBeFileWithTemplate = function(expected) {
this.actual = fs.readFileSync(this.actual, "utf8");
return matchers.toHaveTemplate.call(this, expected);
matchers.toBeFileWithTemplate = function(util) {
return {
compare: function(actual, expected) {
actual = fs.readFileSync(actual, "utf8");
return { pass: matchers.toHaveTemplate().compare.call(this, actual, expected) };
}
};
};

beforeEach(function() {
this.addMatchers(matchers);
jasmine.addMatchers(matchers);
});
16 changes: 15 additions & 1 deletion test/jasmine-test/spec/coreTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1987,7 +1987,21 @@ var coreTests = [
log: "Section without corresponding key in template `Section not found`",
message: "test the log messages for an unhandled section."
},
{
{
name: "Exists without body",
source: "{?foo/}",
context: {"foo": "foo"},
log: "No block for exists check in template `Exists without body`",
message: "test the log message for an exists block with no body"
},
{
name: "Not exists without body",
source: "{^foo/}",
context: {},
log: "No block for not-exists check in template `Not exists without body`",
message: "test the log message for a not-exists block with no body"
},
{
name: "Errors should be throwable from helpers and consumed in the render callback/stream onerror",
source: "{@error errorMessage=\"helper error\"}{/error}",
context: { },
Expand Down

0 comments on commit 0ac0c53

Please sign in to comment.