diff --git a/Gruntfile.js b/Gruntfile.js index 5bf6543..ab36e7f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -233,12 +233,24 @@ module.exports = function(grunt) { } }, + less_error: { + error: { + files: { + 'tmp/invalid.css': ['test/fixtures/invalid.less'] + } + }, + }, + // Unit tests. nodeunit: { tests: ['test/*_test.js'] } }); + // First load this plugin's task(s) and rename for testing errors. + grunt.loadTasks('tasks'); + grunt.renameTask('less', 'less_error'); + // Actually load this plugin's task(s). grunt.loadTasks('tasks'); diff --git a/tasks/less.js b/tasks/less.js index 35442e6..a6d68c5 100644 --- a/tasks/less.js +++ b/tasks/less.js @@ -164,6 +164,7 @@ module.exports = function(grunt) { return less.render(srcCode, options) .catch(function(err) { lessError(err, srcFile); + throw err; }); }; diff --git a/test/fixtures/invalid.less b/test/fixtures/invalid.less new file mode 100644 index 0000000..cbf00da --- /dev/null +++ b/test/fixtures/invalid.less @@ -0,0 +1,2 @@ +.invalid { + missing: brace; diff --git a/test/less_test.js b/test/less_test.js index d598b8b..b9d7810 100644 --- a/test/less_test.js +++ b/test/less_test.js @@ -34,6 +34,23 @@ exports.less = { test.done(); }, + invalid: function(test) { + test.expect(4); + + grunt.util.spawn({ + grunt: true, + args: ['--force', 'less_error:error'] + }, function doneFunction(error, result, code) { + test.equal(error, null, 'Error should be null'); + test.equal(code, 0, 'the code should be 0'); + test.ok( + /ParseError: Unrecognised input\./.test(result.stdout), + 'The result should contain error info.'); + test.ok(/\bDone\b/.test(result.stdout), 'The result should contain the "Done" word'); + + test.done(); + }); + }, nopaths: function(test) { test.expect(1);