Skip to content

Commit

Permalink
Add test coverage for gzip, fix hanging compilation on error.
Browse files Browse the repository at this point in the history
  • Loading branch information
schneidmaster committed Jul 17, 2017
1 parent 3b0f196 commit 880d246
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.5.1

* Fix bug where [gzip error would hang compilation](https://github.com/schneidmaster/sitemap-webpack-plugin/pull/8) rather than reporting and continuing

## 0.5.0

* Add optional [formatter configuration](https://github.com/schneidmaster/sitemap-webpack-plugin/pull/7)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sitemap-webpack-plugin",
"version": "0.5.0",
"version": "0.5.1",
"description": "Webpack plugin to generate a sitemap.",
"main": "lib/index.js",
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export default class SitemapWebpackPlugin {

if(sitemap !== null && this.skipGzip !== true) {
zlib.gzip(sitemap, (err, compressed) => {
/* istanbul ignore if */
if(err) {
compilation.errors.push(err.stack);
} else {
Expand All @@ -124,8 +123,8 @@ export default class SitemapWebpackPlugin {
return Buffer.byteLength(compressed);
}
};
callback();
}
callback();
});
} else {
callback();
Expand Down
24 changes: 24 additions & 0 deletions test/gzip.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* global jest describe it expect */

import webpack from 'webpack';

jest.mock('zlib', () => {
return {
gzip: (input, callback) => {
callback({
stack: 'a gzip error happened'
});
}
};
});

describe('Gzip error', () => {
it('reports error', (done) => {
const webpackConfig = require('./success-cases/basic/webpack.config.js').default;

webpack(webpackConfig, (_err, output) => {
expect(output.compilation.errors[0]).toEqual('a gzip error happened');
done();
});
});
});

0 comments on commit 880d246

Please sign in to comment.