Skip to content

Commit

Permalink
Merge pull request #358 from xzyfer/fix/empty-file
Browse files Browse the repository at this point in the history
An empty Sass file should produce an empty CSS file
  • Loading branch information
xzyfer committed Oct 25, 2015
2 parents 623eebc + f8a75e6 commit 33a8a4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var gulpSass = function gulpSass(options, sync) {
return cb();
}
if (!file.contents.length) {
file.path = gutil.replaceExtension(file.path, '.css');
return cb(null, file);
}

Expand Down
25 changes: 25 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ describe('gulp-sass -- async compile', function() {
stream.write(streamFile);
});

it('should compile an empty sass file', function(done) {
var sassFile = createVinyl('empty.scss');
var stream = sass();
stream.on('data', function(cssFile) {
should.exist(cssFile);
should.exist(cssFile.path);
should.exist(cssFile.relative);
should.exist(cssFile.contents);
should.equal(path.basename(cssFile.path), 'empty.css');
String(cssFile.contents).should.equal(
fs.readFileSync(path.join(__dirname, 'expected/empty.css'), 'utf8')
);
done();
});
stream.write(sassFile);
});

it('should compile a single sass file', function(done) {
var sassFile = createVinyl('mixins.scss');
var stream = sass();
Expand Down Expand Up @@ -467,6 +484,14 @@ describe('gulp-sass -- sync compile', function() {
gulp.src(path.join(__dirname, '/scss/empty.scss'))
.pipe(sass.sync())
.pipe(gulp.dest(path.join(__dirname, '/results/')))
.pipe(tap(function() {
try {
fs.statSync(path.join(__dirname, '/results/empty.css'));
}
catch (e) {
should.fail(false, true, 'Empty file was produced');
}
}))
.on('end', done);
});
});

0 comments on commit 33a8a4f

Please sign in to comment.