Skip to content

Commit

Permalink
Merge pull request #200 from assetgraph/fix/spriteLocationGarbage
Browse files Browse the repository at this point in the history
Remove -sprite-location after creating the sprites
  • Loading branch information
papandreou authored May 22, 2020
2 parents 82b50a1 + 79532c6 commit 6d5f0a0
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 6d5f0a0

Please sign in to comment.