Skip to content

Commit

Permalink
Surpress stdout from showing up in the test output, added some basic …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
asciidisco committed Nov 30, 2012
1 parent d689023 commit a96167c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// External libs.
var _ = require('lodash');
var semver = require('semver');
var temp = require('temp');
var fs = require('fs');

exports.init = function(grunt) {
var exports = {};
Expand All @@ -38,13 +40,14 @@
}
}

var mappedConfig = ['--stdout'];
var temporaryLodash = temp.openSync('lodash');
var mappedConfig = ['--silent', '--output', temporaryLodash.path];
// load lodash version
var version = lodashTarget.VERSION;
// check lodash version
if (semver.gte(version, '0.7.0')) {
// check for debug or minified output
if ((options.debug === true || options.minify === true) && semver.gte(version, '0.7.0')) {
if ((options.debug === true || options.minify === false) && semver.gte(version, '0.7.0')) {
mappedConfig.push('--debug');
}

Expand All @@ -53,10 +56,11 @@
// launch lodash builder
lodashBuilder(args, function (output) {
var outputSize = output.length;
fs.unlink(temporaryLodash.path);

// catch lodash errors
if (output.search("Invalid argument passed:") === 1) {
contentCb(new Transport('error', result.stdout), options);
contentCb(new Transport('error', output), options);
return null;
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grunt-lodashbuilder",
"description": "Build your Lo-Dash experience with grunt",
"version": "0.1.3",
"version": "0.1.4",
"homepage": "https://github.com/asciidisco/grunt-lodashbuilder",
"author": {
"name": "asciidisco",
Expand Down Expand Up @@ -31,7 +31,8 @@
"dependencies": {
"grunt": ">=0.3.x",
"lodash": "latest",
"semver": "1.1.x"
"semver": "1.1.x",
"temp": "0.4.x"
},
"keywords": [
"gruntplugin", "lodash", "underscore", "custom", "builder"
Expand Down
20 changes: 20 additions & 0 deletions test/lodashbuilder_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var grunt = require('grunt');
var builder = require('../lib/builder');

// Load local tasks.
grunt.loadTasks('tasks');

Expand All @@ -7,5 +9,23 @@ exports['require'] = {
'use strict';
// setup here
done();
},
testSimpleLodashCustomBuilderOutput: function(test) {
'use strict';
test.expect(2) ;
var options = {
config: {
include: ['each'],
debug: true
}
};

var build = builder.init(grunt).build;
build(options, function (transport) {
test.equal(transport.type, 'content', 'Transport type has been set correctly')
test.ok(transport.content.length >= 1, 'Transport content has been generated')
test.done();
});
}

};

0 comments on commit a96167c

Please sign in to comment.