Skip to content

Consistent format for syntax errors. #319

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

Merged
merged 2 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add test case for syntax error formatting
  • Loading branch information
andreypopp committed Aug 16, 2016
commit 9343ebbd320bba6a52d1adaa476e536d9a578f3f
17 changes: 17 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ exports.test = function test(name, input, result, query, modules) {
});
};

exports.testError = function test(name, input, onError) {
it(name, function(done) {
runLoader(cssLoader, input, undefined, {}, function(err, output) {
if (!err) {
done(new Error('Expected error to be thrown'));
} else {
try {
onError(err);
} catch (error) {
return done(error);
}
done();
}
});
});
};

exports.testWithMap = function test(name, input, map, result, query, modules) {
it(name, function(done) {
runLoader(cssLoader, input, map, {
Expand Down
13 changes: 13 additions & 0 deletions test/simpleTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*globals describe */

var assert = require('assert');
var test = require("./helpers").test;
var testError = require("./helpers").testError;
var testMinimize = require("./helpers").testMinimize;

describe("simple", function() {
Expand All @@ -19,4 +21,15 @@ describe("simple", function() {
testMinimize("minimized simple", ".class { a: b c d; }", [
[1, ".class{a:b c d}", ""]
]);
testError("error formatting", ".some {\n invalid css;\n}", function(err) {
assert.equal(err.message, [
'Unknown word (2:2)',
'',
' 1 | .some {',
'> 2 | invalid css;',
' | ^',
' 3 | }',
'',
].join('\n'));
});
});