Skip to content

Commit

Permalink
Remove -sprite-location after creating the sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed May 22, 2020
1 parent 82b50a1 commit 79532c6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
1 change: 1 addition & 0 deletions lib/spriteBackgroundImages.js
Expand Up @@ -360,6 +360,7 @@ module.exports = () =>
[
'-sprite-selector-for-group',
'-sprite-packer',
'-sprite-location',
'-sprite-image-format',
'-sprite-background-color',
'-sprite-important',
Expand Down
72 changes: 48 additions & 24 deletions test/spriteBackgroundImages.js
Expand Up @@ -139,32 +139,56 @@ describe('spriteBackgroundImages', () => {
);
});

it('should process two sprites with -sprite-location properties in the group selector', async () => {
const assetGraph = new AssetGraph({
root: pathModule.resolve(
__dirname,
'..',
'testdata',
'spriteBackgroundImages',
'spriteLocation'
),
describe('with -sprite-location', function () {
it('should process two sprites with -sprite-location properties in the group selector', async () => {
const assetGraph = new AssetGraph({
root: pathModule.resolve(
__dirname,
'..',
'testdata',
'spriteBackgroundImages',
'spriteLocation'
),
});
await assetGraph.loadAssets('style.css');
await assetGraph.populate();

expect(assetGraph, 'to contain assets', 'Png', 4);

await assetGraph.queue(spriteBackgroundImages());

expect(assetGraph, 'to contain assets', 'Png', 2);
expect(assetGraph, 'to contain relations', 'CssImage', 2);

const cssImageHrefs = pluck(
assetGraph.findRelations({ type: 'CssImage' }),
'href'
).sort();
expect(cssImageHrefs[0], 'to equal', 'myImage.png?pngquant=128');
expect(
cssImageHrefs[1],
'to match',
/^sprite-.*?-\d+\.png\?pngquant=128$/
);
});
await assetGraph.loadAssets('style.css');
await assetGraph.populate();

expect(assetGraph, 'to contain assets', 'Png', 4);

await assetGraph.queue(spriteBackgroundImages());

expect(assetGraph, 'to contain assets', 'Png', 2);
expect(assetGraph, 'to contain relations', 'CssImage', 2);

const cssImageHrefs = pluck(
assetGraph.findRelations({ type: 'CssImage' }),
'href'
).sort();
expect(cssImageHrefs[0], 'to equal', 'myImage.png?pngquant=128');
expect(cssImageHrefs[1], 'to match', /^sprite-.*?-\d+\.png\?pngquant=128$/);
it('should remove the -sprite-location properties', async () => {
const assetGraph = new AssetGraph({
root: pathModule.resolve(
__dirname,
'..',
'testdata',
'spriteBackgroundImages',
'spriteLocation'
),
});
const [cssAsset] = await assetGraph.loadAssets('style.css');
await assetGraph.populate();

await assetGraph.queue(spriteBackgroundImages());

expect(cssAsset.text, 'not to contain', '-sprite-location');
});
});

it('should handle an existing background-image property in the group selector', async () => {
Expand Down

0 comments on commit 79532c6

Please sign in to comment.