Skip to content

Commit 092b66a

Browse files
committed
Done: tests
1 parent 8c79ac9 commit 092b66a

18 files changed

+247
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
/test/build/*.css
3+
/test/build/*.png

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var TEMPLATES = {
3636
* @type {Object}
3737
*/
3838
var defaults = {
39+
baseUrl : './',
3940
externalStyle : false,
4041
spritePath : null,
4142
spriteName : 'sprite.png',
@@ -479,7 +480,7 @@ function updateReferences(images, opts, sprites, css) {
479480

480481
if (image) {
481482
// Fix path to the sprite
482-
image.spriteRef = path.relative(path.dirname(css.source.input.file), image.spritePath);
483+
image.spriteRef = path.relative(path.resolve(opts.baseUrl, '.'), image.spritePath);
483484
image.spriteRef = image.spriteRef.replace(path.sep, '/', 'g');
484485

485486
backgroundImage = postcss.decl({

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,13 @@
2626
"mkdirp": "^0.5.1",
2727
"q": "^1.4.0",
2828
"spritesmith": "^1.3.1"
29+
},
30+
"devDependencies": {
31+
"tape": "^4.0.0",
32+
"tap-spec": "^3.0.0",
33+
"postcss": "^0.9.0"
34+
},
35+
"scripts": {
36+
"test": "node ./test/index.js | ./node_modules/.bin/tap-spec"
2937
}
3038
}

test/build/.gitkeep

Whitespace-only changes.

test/expectations/external.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.circle,
2+
.square { background: no-repeat; background-image: url(sprite.retina.png); }
3+
4+
.circle { background-position: 0 0; width: 25px; height: 25px; }
5+
.square { background-position: -25px 0; width: 25px; height: 25px; }
6+
7+
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
8+
.circle,
9+
.square { background: no-repeat; background-image: url(sprite.retina.@2x.png); background-size: 50px 25px; }
10+
11+
.circle { background-position: 0 0; width: 25px; height: 25px; }
12+
.square { background-position: -25px 0; width: 25px; height: 25px; }
13+
}
14+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.selector-a { background-image: url(sprite.basic-color.png); background-position: 0 0; }
2+
.selector-b { background-image: url(sprite.basic-color.png); background-position: -25px 0; background-color: #000; }

test/expectations/style.basic.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.selector-a { background-image: url(sprite.basic.png); background-position: 0 0; }
2+
.selector-b { background-image: url(sprite.basic.png); background-position: -25px 0; }

test/expectations/style.fg.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.selector-a { background-image: url(sprite.fg.png); background-position: 0 0; }
2+
.selector-b { background-image: url(sprite.fg.png); background-position: -25px 0; }
3+
.selector-c { background: #fff url(not-exist.png) no-repeat 0 0; }
4+
5+
@media (max-width: 767px) {
6+
.selector-a { background-image: url(sprite.fg.retina.png); background-position: 0 0; }
7+
.selector-b { background-image: url(sprite.fg.retina.png); background-position: -50px 0; }
8+
.selector-c { background-image: url(not-exist@2x.png); }
9+
}

test/expectations/style.retina.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.selector-a { background-image: url(sprite.retina.png); background-position: 0 0; }
2+
.selector-b { background-image: url(sprite.retina.png); background-position: -25px 0; }
3+
4+
@media (max-width: 767px) {
5+
.selector-a { background-image: url(sprite.retina.@2x.png); background-position: 0 0; background-size: 50px 25px; }
6+
.selector-b { background-image: url(sprite.retina.@2x.png); background-position: -25px 0; background-size: 50px 25px; }
7+
}

test/fixtures/circle.png

1.27 KB
Loading

0 commit comments

Comments
 (0)