Skip to content

Commit 9343ebb

Browse files
committed
Add test case for syntax error formatting
1 parent 5a003e0 commit 9343ebb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

test/helpers.js

+17
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ exports.test = function test(name, input, result, query, modules) {
6969
});
7070
};
7171

72+
exports.testError = function test(name, input, onError) {
73+
it(name, function(done) {
74+
runLoader(cssLoader, input, undefined, {}, function(err, output) {
75+
if (!err) {
76+
done(new Error('Expected error to be thrown'));
77+
} else {
78+
try {
79+
onError(err);
80+
} catch (error) {
81+
return done(error);
82+
}
83+
done();
84+
}
85+
});
86+
});
87+
};
88+
7289
exports.testWithMap = function test(name, input, map, result, query, modules) {
7390
it(name, function(done) {
7491
runLoader(cssLoader, input, map, {

test/simpleTest.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*globals describe */
22

3+
var assert = require('assert');
34
var test = require("./helpers").test;
5+
var testError = require("./helpers").testError;
46
var testMinimize = require("./helpers").testMinimize;
57

68
describe("simple", function() {
@@ -19,4 +21,15 @@ describe("simple", function() {
1921
testMinimize("minimized simple", ".class { a: b c d; }", [
2022
[1, ".class{a:b c d}", ""]
2123
]);
24+
testError("error formatting", ".some {\n invalid css;\n}", function(err) {
25+
assert.equal(err.message, [
26+
'Unknown word (2:2)',
27+
'',
28+
' 1 | .some {',
29+
'> 2 | invalid css;',
30+
' | ^',
31+
' 3 | }',
32+
'',
33+
].join('\n'));
34+
});
2235
});

0 commit comments

Comments
 (0)