Skip to content

Commit

Permalink
Error out properly if an image not supported by canvas is added to a …
Browse files Browse the repository at this point in the history
…sprite.
  • Loading branch information
papandreou committed Nov 26, 2015
1 parent 3b5d743 commit 4135f30
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/spriteBackgroundImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,15 @@ module.exports = function () {

seq(imageInfos)
.parMap(function (imageInfo) {
getCanvasImageFromImageAsset(imageInfo.asset, this);
getCanvasImageFromImageAsset(imageInfo.asset, function (err, canvasImage) {
// For some reason parMap swallows errors!
// Rewrite to use promises or async and get rid of this:
if (err) {
callback(err);
} else {
this(null, canvasImage);
}
}.bind(this));
})
.seqEach(function (canvasImage, i) {
extend(imageInfos[i], {
Expand Down
15 changes: 15 additions & 0 deletions test/spriteBackgroundImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,19 @@ describe('spriteBackgroundImages', function () {
expect(assetGraph, 'to contain relations', 'CssImage', 1);
});
});

it('should error out if an SVG image is added to a sprite', function () {
return expect(new AssetGraph({root: __dirname + '/../testdata/spriteBackgroundImages/svgInSprite/'})
.loadAssets('index.html')
.populate()
.queue(function (assetGraph) {
expect(assetGraph, 'to contain asset', 'Svg');
})
.queue(spriteBackgroundImages())
.queue(function (assetGraph) {
expect(assetGraph, 'to contain asset', 'Png', 1);
expect(assetGraph, 'to contain relations', 'CssImage', 1);
}),
'to be rejected with', /error while reading from input stream/);
});
});
10 changes: 10 additions & 0 deletions testdata/spriteBackgroundImages/svgInSprite/flag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions testdata/spriteBackgroundImages/svgInSprite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.blah {
background-image: url(flag.svg?sprite);
}
</style>
</head>

<body>
<div class="blah"></div>
</body>
</html>

0 comments on commit 4135f30

Please sign in to comment.