Skip to content

Commit

Permalink
Fixes #1 - empty html file bug
Browse files Browse the repository at this point in the history
  • Loading branch information
helmoski committed May 14, 2016
1 parent 4eba8cc commit b6d9703
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function inject(options) {
function transform(file, enc, cb) {
var ext = path.extname(file.path),
relativePath = path.relative(globals.cwd, file.path);
if(file.isNull()) {
if(file.isNull() || file.contents.length === 0) {
this.push(file);
} else if(ext === '.html') {
globals.htmlFiles.push(file);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
"homepage": "https://github.com/rydahhh/gulp-simple-inject#readme",
"dependencies": {
"gulp-util": "^3.0.7",
"if-env": "^1.0.0",
"stream-replace": "^1.0.0",
"through2": "^2.0.0"
},
"devDependencies": {
"coveralls": "^2.11.6",
"if-env": "^1.0.0",
"istanbul": "^0.4.1",
"jasmine-node": "^1.14.5"
}
Expand Down
18 changes: 18 additions & 0 deletions spec/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ describe("The gulp-simple-inject plugin", () => {
}
});
});

it('should not break on an empty html file', done => {
injector.write(getEmptyFile('empty-file'));
injector.end();

injector.on('data', () => {});

injector.on('end', data => {
done();
});
});

describe('with the cwd option specified', () => {
var injector;
Expand Down Expand Up @@ -117,6 +128,13 @@ function getHtmlFile(name) {
});
}

function getEmptyFile(name) {
return new File({
path: `${cwd}/${name}.html`,
contents: new Buffer("", "utf8")
});
}

function getHtmlFileWithoutInjectTags(name) {
return new File({
path: `${cwd}/${name}.html`,
Expand Down

0 comments on commit b6d9703

Please sign in to comment.