-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
61 lines (46 loc) · 1.81 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
var assert = require('assert'),
gutil = require('gulp-util'),
smushit = require('./'),
path = require('path'),
fs = require('fs'),
JPG = fs.readFileSync(path.join(__dirname, './test_data/fixtures/dp.jpg'), 'binary'),
PNG = fs.readFileSync(path.join(__dirname, './test_data/fixtures/dp.png'), 'binary'),
expectedJPG = fs.readFileSync(path.join(__dirname, './test_data/expected/dp.jpg'), 'binary'),
expectedPNG = fs.readFileSync(path.join(__dirname, './test_data/expected/dp.png'), 'binary');
it('should optimize JPG - verbose mode: false', function (cb) {
var stream = smushit();
stream.on('data', function (file) {
assert.equal(file.contents.toString('binary'), expectedJPG);
});
stream.on('end', cb);
stream.write(new gutil.File({
path: path.join(__dirname, './test_data/fixtures/dp.jpg'),
contents: new Buffer(JPG, 'binary')
}));
stream.end();
});
it('should optimize PNG - verbose mode: true', function (cb) {
var stream = smushit({verbose:true});
stream.on('data', function (file) {
assert.equal(file.contents.toString('binary'), expectedPNG);
});
stream.on('end', cb);
stream.write(new gutil.File({
path: path.join(__dirname, './test_data/fixtures/dp.png'),
contents: new Buffer(PNG, 'binary')
}));
stream.end();
});
it('should not break when bytes are not saved', function (cb) {
var stream = smushit();
stream.on('data', function (file) {
assert.equal(file.contents.toString('binary'), expectedPNG);
});
stream.on('end', cb);
stream.write(new gutil.File({
path: path.join(__dirname, './test_data/expected/dp.png'),
contents: new Buffer(expectedPNG, 'binary')
}));
stream.end();
});