Skip to content
This repository was archived by the owner on Dec 8, 2018. It is now read-only.

Commit fa7cd38

Browse files
author
Tor Røttum
committed
Do not shrink CSS if the file is empty (see stoyan/cssshrink#16)
1 parent b609781 commit fa7cd38

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ function cssShrink() {
2222
}
2323

2424
if (file.isBuffer()) {
25-
file.contents = cssShrinkIt(file.contents.toString());
25+
if (file.contents.toString().trim() !== '') {
26+
file.contents = cssShrinkIt(file.contents.toString());
27+
}
2628
}
2729

2830
// make sure the file goes through the next gulp plugin

test.js

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ describe('gulp-cssshrink', function() {
2323
});
2424

2525

26+
done();
27+
});
28+
});
29+
30+
describe('with empty file', function() {
31+
it('should not return anything or crash', function(done) {
32+
33+
var fakeFile = new File({
34+
contents: new Buffer('')
35+
});
36+
37+
var myCSSShrink = cssshrink();
38+
myCSSShrink.write(fakeFile);
39+
40+
myCSSShrink.once('data', function(file) {
41+
assert(file.isBuffer());
42+
43+
// check if the CSS was shrunken
44+
assert.equal(file.contents.toString(), '');
45+
});
46+
47+
2648
done();
2749
});
2850
});

0 commit comments

Comments
 (0)