Exemplo n.º 1
0
 it('should return a stream with two sprite objects and the appropriate nameing of sprites', function (done) {
   var count = 0;
   opts.dimension = [{ratio: 1, dpi: 72}, {ratio: 2, dpi: 192}];
   mockLayouts.name = 'first';
   var l2 = layout('top-down');
   l2.addItem({height: 50, width: 50, meta: {}});
   var mockLayouts2 = {
     name: 'second',
     layout: mockLayout.export()
   };
   os.fromArray([mockLayouts, mockLayouts2])
     .pipe(sprite(opts))
     .pipe(spy(function (res) {
       res.sprites.length.should.equal(2);
       if (count === 0) {
         res.should.have.deep.property('sprites[0].name', 'sprite-first');
         res.should.have.deep.property('sprites[1].name', 'sprite-first@2x');
       }
       if (count === 1) {
         res.should.have.deep.property('sprites[0].name', 'sprite-second');
         res.should.have.deep.property('sprites[1].name', 'sprite-second@2x');
       }
       count++;
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(2);
       done();
     });
 });
Exemplo n.º 2
0
 it('should process layouts', function (done) {
   var count = 0;
   opts.processor = {
     process: function () {
       count++;
       return Promise.resolve('style');
     },
     isBeautifyable: function () {
       return false;
     },
     extension: function () {
       return 'css';
     }
   };
   os.fromArray([layouts])
     .pipe(style(opts))
     .pipe(spy(function (res) {
       if (res.style) {
         res.style.toString().should.equal('style');
       }
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(1);
       done();
     });
 });
Exemplo n.º 3
0
 it('should return a stream with one layout object', function (done) {
   var count = 0;
   opts.prefix = 'test';
   os.fromArray([{
       base: '/mock/fixtures/',
       height: 100,
       width: 100
     }, {
       base: '/mock/fixtures2/',
       height: 100,
       width: 100
     }])
     .pipe(layout(opts))
     .pipe(spy(function (res) {
       var l = res.layout;
       l.items.length.should.equal(2);
       l.should.have.property('width', 108);
       l.should.have.property('height', 216);
       count++;
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(1);
       done();
     });
 });
Exemplo n.º 4
0
 it('should throw an error when no layouts where created', function (done) {
   os.fromArray([{wrongtile: true}, {wrongtile: true}])
     .pipe(layout(opts))
     .on('error', function (e) {
       e.should.have.property('name', 'LayoutError');
       done();
     });
 });
Exemplo n.º 5
0
 it('should throw an error when processor not found', function (done) {
   opts.engine = 'notpresent';
   try {
     os.fromArray([mockLayouts]).pipe(sprite(opts));
   }
   catch (e) {
     e.name.should.equal('PluggableError');
     done();
   }
 });
Exemplo n.º 6
0
 it('should throw an error when processor not found', function (done) {
   opts.processor = 'notpresent';
   os.fromArray([layouts])
     .pipe(style(opts))
     .on('data', noop)
     .on('error', function (e) {
       e.should.have.property('name', 'PluggableError');
       done();
     });
 });
Exemplo n.º 7
0
 it('should return a stream of vinyl objects', function (done) {
   var count = 0;
   os.fromArray([sprites, style])
     .pipe(toVinyl(opts))
     .pipe(spy(function (res) {
       count++;
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(3);
       done();
     });
 });
Exemplo n.º 8
0
 it('should return a stream with one style object', function (done) {
   var count = 0;
   os.fromArray([layouts])
     .pipe(style(opts))
     .pipe(spy(function (res) {
       if (res.style) {
         res.style.should.match(/.icon.*/);
         count++;
       }
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(1);
       done();
     });
 });
Exemplo n.º 9
0
 it('should return a url with cachebuster', function (done) {
   var count = 0;
   opts.cssPath = 'http://www.example.com/assets/';
   opts.cachebuster = true;
   os.fromArray([mockLayouts])
     .pipe(sprite(opts))
     .pipe(spy(function (res) {
       res.sprites[0].url.should.include('http://www.example.com/assets/sprite.png?');
       count++;
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(1);
       done();
     });
 });
Exemplo n.º 10
0
 it('should return a stream with one sprite object', function (done) {
   var count = 0;
   os.fromArray([mockLayouts])
     .pipe(sprite(opts))
     .pipe(spy(function (res) {
       res.sprites.length.should.equal(1);
       res.should.have.deep.property('sprites[0].name', 'sprite');
       res.sprites[0].url.should.not.match(/data\:image\/png;base64.*/);
       count++;
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(1);
       done();
     });
 });
Exemplo n.º 11
0
 it('should not process layouts', function (done) {
   var count = 0;
   opts.processor = {
     process: function () {
       count++;
       return Promise.resolve('style');
     }
   };
   opts.style = null;
   os.fromArray([layouts])
     .pipe(style(opts))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(0);
       done();
     });
 });
Exemplo n.º 12
0
 it('should load template and return a stream with one style object', function (done) {
   var count = 0;
   opts.template = '/test/template/template.hbs';
   os.fromArray([layouts])
     .pipe(style(opts))
     .pipe(spy(function (res) {
       if (res.style) {
         res.style.should.match(/.testClass.*/);
         count++;
       }
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(1);
       done();
     });
 });
Exemplo n.º 13
0
 it('should return a stream with two sprite objects', function (done) {
   var count = 0;
   opts.dimension = [{ratio: 1, dpi: 72}, {ratio: 2, dpi: 192}];
   os.fromArray([mockLayouts])
     .pipe(sprite(opts))
     .pipe(spy(function (res) {
       res.sprites.length.should.equal(2);
       res.should.have.deep.property('sprites[0].dpi', null);
       res.should.have.deep.property('sprites[1].dpi', 192);
       res.should.have.deep.property('sprites[1].name', 'sprite@2x');
       count++;
     }))
     .on('data', noop)
     .on('finish', function () {
       count.should.equal(1);
       done();
     });
 });
Exemplo n.º 14
0
  it('should return a stream of vinyl objects and append file extension to style if not provided', function (done) {
    var count = 0;
    var cssCount = 0;
    opts.style = 'style';

    os.fromArray([sprites, style])
      .pipe(toVinyl(opts))
      .pipe(spy(function (res) {
        if (res.path === 'test/out/style.css') {
          cssCount++;
        }
        count++;
      }))
      .on('data', noop)
      .on('finish', function () {
        count.should.equal(3);
        cssCount.should.equal(1);
        done();
      });
  });
Exemplo n.º 15
0
 it('should return log an error when processor not found', function (done) {
   var msg = '', error = '';
   opts.engine = 'notpresent';
   opts.logger = {
     error: function (e) {
       error = e;
     },
     debug: function (m) {
       msg = m;
     }
   };
   try {
     os.fromArray([mockLayouts]).pipe(sprite(opts));
   }
   catch (e) {
     error.should.include('notpresent');
     msg.should.include('npm install');
     done();
   }
 });
Exemplo n.º 16
0
 it('should log an error when processor not found', function (done) {
   var msg = '', error = '';
   opts.processor = 'notpresent';
   opts.cli = true;
   opts.logger = {
     error: function (e) {
       error = e;
     },
     debug: function (m) {
       msg = m;
     }
   };
   os.fromArray([layouts])
     .pipe(style(opts))
     .on('data', noop)
     .on('error', function (e) {
       error.should.include('notpresent');
       msg.should.include('npm install');
       done();
     });
 });
Exemplo n.º 17
0
 it('should css escaped sprite urls', function (done) {
   layouts.sprites.push({
     name: 'sprite@3x',
     url: '../images/tes"te/sprite@3x.png',
     type: 'png',
     dpi: 288,
     ratio: 3,
     width: 50,
     height: 300
   });
   os.fromArray([layouts])
     .pipe(style(opts))
     .pipe(spy(function (res) {
       if (res.style) {
         res.style.toString().should.include('tes%22te');
       }
     }))
     .on('data', noop)
     .on('finish', function () {
       done();
     });
 });