Skip to content

Commit

Permalink
Added test for images with wrong extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 27, 2014
1 parent 91ce8d6 commit 7c44734
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/spriteBackgroundImages.js
Expand Up @@ -14,7 +14,7 @@ function getCanvasImageFromImageAsset(imageAsset, cb) {
var canvasImage = new Canvas.Image();
canvasImage.onerror = function (err) {
process.nextTick(function () {
err.message += ' (' + imageAsset.toString() + ')';
err.message += ' (' + imageAsset.urlOrDescription + ')';
cb(err);
});
};
Expand Down Expand Up @@ -132,7 +132,7 @@ module.exports = function () {
if (cssRule.type !== 1) { // cssom.CSSRule.STYLE_RULE
return;
}
if (('-sprite-selector-for-group') in cssRule.style) {
if ('-sprite-selector-for-group' in cssRule.style) {
var spriteInfo = extractInfoFromCssRule(cssRule, '-sprite-'),
spriteGroupName = spriteInfo.selectorForGroup;
if ('location' in spriteInfo) {
Expand Down
23 changes: 20 additions & 3 deletions test/spriteBackgroundImages.js
@@ -1,5 +1,4 @@
/*global describe, it*/
var _ = require('underscore'),
/*global describe, it*/var _ = require('underscore'),
expect = require('./unexpected-with-plugins'),
AssetGraph = require('assetgraph'),
spriteBackgroundImages = require('../lib/spriteBackgroundImages');
Expand Down Expand Up @@ -189,9 +188,27 @@ describe('spriteBackgroundImages', function () {
})
.queue(spriteBackgroundImages())
.queue(function (assetGraph) {
expect(assetGraph, 'to contain assets', 'Png');
expect(assetGraph, 'to contain asset', 'Png');
expect(assetGraph, 'to contain relations', 'CssImage');
})
.run(done);
});

it('should handle images with wrong extensions', function (done) {
new AssetGraph({root: __dirname + '/../testdata/spriteBackgroundImages/imagesWithWrongExtensions/'})
.loadAssets('style.css')
.populate()
.queue(function (assetGraph) {
expect(assetGraph, 'to contain asset', 'Png');
expect(assetGraph, 'to contain asset', 'Jpeg');
expect(assetGraph, 'to contain relations', 'CssImage', 2);
})
.queue(spriteBackgroundImages())
.queue(function (assetGraph) {
expect(assetGraph, 'to contain asset', 'Png');
expect(assetGraph, 'to contain no asset', 'Jpeg');
expect(assetGraph, 'to contain relations', 'CssImage', 2);
})
.run(done);
});
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,7 @@
body {
background-image: url(actuallyAJpeg.png?sprite=foo);
}

.quux {
background-image: url(actuallyAPng.jpg?sprite=foo);
}

0 comments on commit 7c44734

Please sign in to comment.