-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gleb Mikheev
committed
Dec 12, 2015
1 parent
093ef78
commit 7dfa1a6
Showing
5 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,130 @@ | ||
|
||
var postcss = require('postcss'); | ||
var expect = require('chai').expect; | ||
var plugin = require('../'); | ||
|
||
var assert = function (input, output, opts, done) { | ||
postcss([ plugin(opts) ]).process(input).then(function (result) { | ||
expect(result.css).to.eql(output); | ||
expect(result.warnings()).to.be.empty; | ||
done(); | ||
}).catch(function (error) { | ||
done(error); | ||
}); | ||
function cacheLog() { | ||
console.logback = console.log; | ||
console.log = function(){ | ||
var args = Array.prototype.slice.call(arguments); | ||
console.logback.apply(console, ['cached'].concat(args)); | ||
console.lastMessage = Array.prototype.slice.call(arguments).join(' '); | ||
}; | ||
} | ||
|
||
function uncacheLog() { | ||
console.log = console.logback; | ||
return console.lastMessage; | ||
} | ||
|
||
var assert = function(input, output, opts, done) { | ||
postcss([plugin(opts)]).process(input).then(function(result) { | ||
expect(result.css).to.eql(output); | ||
expect(result.warnings()).to.be.empty; | ||
done(); | ||
}).catch(function(error) { | ||
done(error); | ||
}); | ||
}; | ||
|
||
var assertCached = function(input, output, opts, done) { | ||
cacheLog(); | ||
|
||
postcss([plugin(opts)]).process(input).then(function(result) { | ||
expect(result.css).to.eql(output); | ||
expect(result.warnings()).to.be.empty; | ||
|
||
if (uncacheLog().indexOf('unchanged') === -1) { | ||
return done(new Error('Cache is not working')); | ||
} | ||
|
||
done(); | ||
}).catch(function(error) { | ||
done(error); | ||
}); | ||
}; | ||
|
||
describe('postcss-easysprite', function (done) { | ||
assert('a {}', 'a {}', {}, done); | ||
var assertNotCached = function(input, output, opts, done) { | ||
cacheLog(); | ||
|
||
postcss([plugin(opts)]).process(input).then(function(result) { | ||
expect(result.css).to.eql(output); | ||
expect(result.warnings()).to.be.empty; | ||
if (uncacheLog().indexOf('generated') === -1) { | ||
return done(new Error('Sprite already cached, code red!')); | ||
} | ||
|
||
done(); | ||
}).catch(function(error) { | ||
done(error); | ||
}); | ||
}; | ||
|
||
describe('postcss-easysprites', function() { | ||
|
||
it('Relative images test', function(done) { | ||
assert( | ||
'a { background: url("images/arrow-next.png#elements"); }', | ||
'a { background-image: url(sprites/elements.png); background-position: 0 0; }', | ||
{ | ||
stylesheetPath:'./test/basic', | ||
spritePath: './test/basic/sprites', | ||
}, done); | ||
}); | ||
|
||
it('Absolute images test', function(done) { | ||
assert( | ||
'a { background: url("/images/arrow-next.png#elements"); }', | ||
'a { background-image: url(sprites/elements.png); background-position: 0 0; }', | ||
{ | ||
imagePath:'./test/basic', | ||
stylesheetPath:'./test/basic', // need here cause of inline call | ||
spritePath: './test/basic/sprites', | ||
}, done); | ||
}); | ||
|
||
it('Retina images test', function(done) { | ||
assert( | ||
'a { background: url("/images/[email protected]#elements"); }', | ||
'a { background-image: url(sprites/[email protected]); background-position: 0 0; background-size: 28px 27px; }', | ||
{ | ||
imagePath:'./test/basic', | ||
stylesheetPath:'./test/basic', // need here cause of inline call | ||
spritePath: './test/basic/sprites', | ||
}, done); | ||
}); | ||
|
||
it('Not exists image test', function(done) { | ||
assert( | ||
'a { background: url("/images/image-not-exists.png#elements"); }', | ||
'a { background: url("/images/image-not-exists.png"); }', | ||
{ | ||
imagePath:'./test/basic', | ||
stylesheetPath:'./test/basic', // need here cause of inline call | ||
spritePath: './test/basic/sprites', | ||
}, done); | ||
}); | ||
|
||
it('Assert sprite not cached', function(done) { | ||
assertNotCached( | ||
'a { background: url("images/arrow-next_hover.png#elements"); }', | ||
'a { background-image: url(sprites/elements.png); background-position: 0 0; }', | ||
{ | ||
imagePath:'./test/basic', | ||
stylesheetPath:'./test/basic', // need here cause of inline call | ||
spritePath: './test/basic/sprites', | ||
}, done); | ||
}); | ||
|
||
it('Assert sprite cached', function(done) { | ||
assertCached( | ||
'a { background: url("images/arrow-next_hover.png#elements"); }', | ||
'a { background-image: url(sprites/elements.png); background-position: 0 0; }', | ||
{ | ||
imagePath:'./test/basic', | ||
stylesheetPath:'./test/basic', // need here cause of inline call | ||
spritePath: './test/basic/sprites', | ||
}, done); | ||
}); | ||
|
||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.