|
| 1 | +var fs = require('fs'); |
1 | 2 | var assert = require('assert');
|
2 | 3 | var es = require('event-stream');
|
3 | 4 | var gutil = require('gulp-util');
|
@@ -294,6 +295,67 @@ describe('gulp-css-base64', function () {
|
294 | 295 | });
|
295 | 296 | });
|
296 | 297 |
|
| 298 | + it('should delete local resource source file after encoding', function (done) { |
| 299 | + fs.writeFileSync('test/fixtures/image/very-very-small_copy.png', fs.readFileSync('test/fixtures/image/very-very-small.png')); |
| 300 | + // create the fake file |
| 301 | + var fakeFile = new gutil.File({ |
| 302 | + contents: new Buffer('.button_alert{background:url(test/fixtures/image/very-very-small_copy.png) no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}') |
| 303 | + }); |
| 304 | + |
| 305 | + // Create a css-base64 plugin stream |
| 306 | + var stream = base64({ |
| 307 | + deleteAfterEncoding : true |
| 308 | + }); |
| 309 | + |
| 310 | + // write the fake file to it |
| 311 | + stream.write(fakeFile); |
| 312 | + |
| 313 | + // wait for the file to come back out |
| 314 | + stream.once('data', function (file) { |
| 315 | + // make sure it came out the same way it went in |
| 316 | + assert(file.isBuffer()); |
| 317 | + |
| 318 | + // check the contents |
| 319 | + assert.equal(file.contents.toString('utf8'), '.button_alert{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANAQAAAABakNnRAAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAArSURBVAjXY/j/g2H/C4b5Jxj6OxgaOEBoxgmGDg8GIACyuRoYjkowfKgAACBpDLQ2kvRRAAAAAElFTkSuQmCC) no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}'); |
| 320 | + |
| 321 | + // check if file is removed |
| 322 | + assert(!fs.existsSync('test/fixtures/image/very-very-small_copy.png')); |
| 323 | + |
| 324 | + done(); |
| 325 | + }); |
| 326 | + }); |
| 327 | + |
| 328 | + it('should use cache when css contain duplicate uri resource', function (done) { |
| 329 | + // example case : css contain two url() with same uri and deleteAfterEncoding is enabled |
| 330 | + fs.writeFileSync('test/fixtures/image/very-very-small_copy.png', fs.readFileSync('test/fixtures/image/very-very-small.png')); |
| 331 | + // create the fake file |
| 332 | + var fakeFile = new gutil.File({ |
| 333 | + contents: new Buffer('.button_alert{background:url(test/fixtures/image/very-very-small_copy.png) no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline.button_alert{background:url(test/fixtures/image/very-very-small_copy.png) no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}') |
| 334 | + }); |
| 335 | + |
| 336 | + // Create a css-base64 plugin stream |
| 337 | + var stream = base64({ |
| 338 | + deleteAfterEncoding : true |
| 339 | + }); |
| 340 | + |
| 341 | + // write the fake file to it |
| 342 | + stream.write(fakeFile); |
| 343 | + |
| 344 | + // wait for the file to come back out |
| 345 | + stream.once('data', function (file) { |
| 346 | + // make sure it came out the same way it went in |
| 347 | + assert(file.isBuffer()); |
| 348 | + |
| 349 | + // check the contents |
| 350 | + assert.equal(file.contents.toString('utf8'), '.button_alert{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANAQAAAABakNnRAAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAArSURBVAjXY/j/g2H/C4b5Jxj6OxgaOEBoxgmGDg8GIACyuRoYjkowfKgAACBpDLQ2kvRRAAAAAElFTkSuQmCC) no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline.button_alert{background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANAQAAAABakNnRAAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAAAEgAAABIAEbJaz4AAAArSURBVAjXY/j/g2H/C4b5Jxj6OxgaOEBoxgmGDg8GIACyuRoYjkowfKgAACBpDLQ2kvRRAAAAAElFTkSuQmCC) no-repeat 4px 5px;padding-left:12px;font-size:12px;color:#888;text-decoration:underline}'); |
| 351 | + |
| 352 | + // check if file is removed |
| 353 | + assert(!fs.existsSync('test/fixtures/image/very-very-small_copy.png')); |
| 354 | + |
| 355 | + done(); |
| 356 | + }); |
| 357 | + }); |
| 358 | + |
297 | 359 | it('should convert if remote resource (http://)', function (done) {
|
298 | 360 | // create the fake file
|
299 | 361 | var fakeFile = new gutil.File({
|
|
0 commit comments