Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethrow the compilation error after printing the message. #315

Merged
merged 4 commits into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,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