Skip to content

Commit

Permalink
Add test case for syntax error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp committed Aug 16, 2016
1 parent 5a003e0 commit 9343ebb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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'));
});
});

0 comments on commit 9343ebb

Please sign in to comment.