css-b64-images-test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var Path = require('path'),
  2. fs = require('fs'),
  3. b64 = require('..');
  4. require('should');
  5. describe('A complex CSS', function(){
  6. var cssFile = Path.join(__dirname, 'fixture', 'css', 'style.css'),
  7. relative = Path.join(__dirname, 'fixture', 'css');
  8. root = Path.join(__dirname, 'fixture');
  9. it('a file should be optimized with base64', function(done){
  10. b64.fromFile(cssFile, root, function(err, css){
  11. cssShouldBeCorrect(css);
  12. done();
  13. });
  14. });
  15. it('a string should be optimized with base64', function(done){
  16. var css = fs.readFileSync(cssFile);
  17. b64.fromString(css, relative, root, function(err, css){
  18. cssShouldBeCorrect(css);
  19. done();
  20. });
  21. });
  22. });
  23. function cssShouldBeCorrect(css){
  24. css.should.include(".single-quote {\n background: url('data:image/gif;base64,");
  25. css.should.include(".double-quote {\n background: url(\"data:image/gif;base64,");
  26. css.should.include(".absolute {\n background: url('data:image/gif;base64,");
  27. css.should.include(".external {\n background: url('http");
  28. css.should.include(".tooBig {\n background: url('../img");
  29. css.should.include(".not-found {\n background: url('../img");
  30. css.should.include(".mediatype {\n background: url('data:image/svg+xml;base64,");
  31. }