-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest.js
76 lines (57 loc) · 1.59 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @file gulp fontmin test
* @author junmer
*/
/* eslint-env node */
'use strict';
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var gutil = require('gulp-util');
var fontmin = require('./');
function isExt(file, ext) {
return ext.split(',').indexOf(path.extname(file.path).substr(1)) > -1;
}
it('should minify ttf, css should have path', function (cb) {
this.timeout(40000);
var stream = fontmin({
text: '你好世界',
fontPath: 'path/foo'
});
stream.on('data', function (file) {
if (isExt(file, 'ttf')) {
assert(file.contents.length < fs.statSync('fixture.ttf').size);
}
if (isExt(file, 'css')) {
assert(
/path\/foo/.test(
file.contents.toString('utf-8')
)
);
}
fs.writeFileSync(
file.path.replace('fixture', 'output/fixture'),
file.contents,
{
encoding: isExt(file, 'svg,css') ? 'utf-8' : 'binary'
}
);
});
stream.on('end', cb);
stream.write(new gutil.File({
path: path.join(__dirname, '/fixture.ttf'),
contents: fs.readFileSync('fixture.ttf')
}));
stream.end();
});
it('should skip unsupported fonts', function (cb) {
var stream = fontmin();
stream.once('data', function (file) {
assert.strictEqual(file.contents, null);
});
stream.on('end', cb);
stream.write(new gutil.File({
path: path.join(__dirname, '/fixture.bmp')
}));
stream.end();
});