Skip to content

Commit

Permalink
Merge pull request #467 from jpbackman/fix-kss-parsing-empty-file
Browse files Browse the repository at this point in the history
Fix KSS parser failing on empty file
  • Loading branch information
Juuso Backman committed Feb 11, 2015
2 parents 50edb7d + 7f08228 commit cd64ff4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/modules/kss-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

'use strict';
var kss = require('kss'),
path = require('path'),
Expand Down Expand Up @@ -94,6 +93,10 @@ function processBlock(block, options) {
}

function processFile(contents, filePath, syntax, options) {
if (!contents || contents.length === 0) {
return Q.resolve([]);
}

return Q.Promise(function(resolve, reject) {
var blockPromises = [],
blocks;
Expand Down
21 changes: 21 additions & 0 deletions test/unit/modules/kss-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ describe('KSS parser', function() {
};
}

it('does not crash on empty .less file', function(done) {
var files = { 'file1.less': '' };
parse(files).then(function(sections) {
expect(sections.length).to.eql(0);
}).then(done).catch(done);
});

it('does not crash on empty .sass file', function(done) {
var files = { 'file1.sass': '' };
parse(files).then(function(sections) {
expect(sections.length).to.eql(0);
}).then(done).catch(done);
});

it('does not crash on empty .scss file', function(done) {
var files = { 'file1.scss': '' };
parse(files).then(function(sections) {
expect(sections.length).to.eql(0);
}).then(done).catch(done);
});

it('parses sections from multiple files', function(done) {
var files = {
'file1.less': multiline(function() {
Expand Down

0 comments on commit cd64ff4

Please sign in to comment.