Skip to content

Commit

Permalink
Rethrow the compilation error after printing the message. (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfisz authored and XhmikosR committed Nov 22, 2016
1 parent 924189e commit a507646
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
1 change: 1 addition & 0 deletions tasks/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ module.exports = function(grunt) {
return less.render(srcCode, options)
.catch(function(err) {
lessError(err, srcFile);
throw err;
});
};

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/invalid.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.invalid {
missing: brace;
17 changes: 17 additions & 0 deletions test/less_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit a507646

Please sign in to comment.