1 | 'use strict';
|
2 |
|
3 | var gulp = require('gulp')
|
4 | , assert = require('assert')
|
5 | , es = require('event-stream')
|
6 | , fs = require('fs')
|
7 | , ttf2eot = require(__dirname + '/../src/index.js')
|
8 | , Stream = require('stream')
|
9 | , gutil = require('gulp-util')
|
10 | ;
|
11 |
|
12 |
|
13 |
|
14 | Date = (function(d) {
|
15 | function Date() {
|
16 | d.call(this, 3600);
|
17 | }
|
18 | Date.now = d.now;
|
19 | return Date;
|
20 | })(Date);
|
21 |
|
22 | describe('gulp-ttf2eot conversion', function() {
|
23 | var filename = __dirname + '/fixtures/iconsfont';
|
24 | var eot = fs.readFileSync(filename + '.eot');
|
25 |
|
26 | describe('with null contents', function() {
|
27 |
|
28 | it('should let null files pass through', function(done) {
|
29 |
|
30 | var s = ttf2eot()
|
31 | , n = 0;
|
32 | s.pipe(es.through(function(file) {
|
33 | assert.equal(file.path,'bibabelula.foo');
|
34 | assert.equal(file.contents, null);
|
35 | n++;
|
36 | }, function() {
|
37 | assert.equal(n,1);
|
38 | done();
|
39 | }));
|
40 | s.write(new gutil.File({
|
41 | path: 'bibabelula.foo',
|
42 | contents: null
|
43 | }));
|
44 | s.end();
|
45 |
|
46 | });
|
47 |
|
48 | });
|
49 |
|
50 | describe('in buffer mode', function() {
|
51 | it('should work', function(done) {
|
52 |
|
53 | gulp.src(filename + '.ttf')
|
54 | .pipe(ttf2eot())
|
55 |
|
56 |
|
57 | .pipe(es.through(function(file) {
|
58 | assert.equal(file.contents.length, eot.length);
|
59 | assert.equal(file.contents.toString('utf-8'), eot.toString('utf-8'));
|
60 | }, function() {
|
61 | done();
|
62 | }));
|
63 |
|
64 | });
|
65 |
|
66 | it('should let non-ttf files pass through', function(done) {
|
67 |
|
68 | var s = ttf2eot();
|
69 | s.pipe(es.through(function(file) {
|
70 | assert.equal(file.path,'bibabelula.foo');
|
71 | assert.equal(file.contents.toString('utf-8'), 'ohyeah');
|
72 | }, function() {
|
73 | done();
|
74 | }));
|
75 | s.write(new gutil.File({
|
76 | path: 'bibabelula.foo',
|
77 | contents: new Buffer('ohyeah')
|
78 | }));
|
79 | s.end();
|
80 |
|
81 | });
|
82 |
|
83 | });
|
84 |
|
85 |
|
86 | describe('in stream mode', function() {
|
87 | it('should work', function(done) {
|
88 |
|
89 | gulp.src(filename + '.ttf', {buffer: false})
|
90 | .pipe(ttf2eot())
|
91 | .pipe(es.through(function(file) {
|
92 |
|
93 | file.contents.pipe(es.wait(function(err, data) {
|
94 | assert.equal(data.length, eot.toString('utf-8').length);
|
95 | assert.equal(data, eot.toString('utf-8'));
|
96 | }));
|
97 | }, function() {
|
98 | done();
|
99 | }));
|
100 |
|
101 | });
|
102 |
|
103 | it('should let non-ttf files pass through', function(done) {
|
104 |
|
105 | var s = ttf2eot();
|
106 | s.pipe(es.through(function(file) {
|
107 | assert.equal(file.path,'bibabelula.foo', {buffer: false});
|
108 | assert(file.contents instanceof Stream.PassThrough);
|
109 | }, function() {
|
110 | done();
|
111 | }));
|
112 | s.write(new gutil.File({
|
113 | path: 'bibabelula.foo',
|
114 | contents: new Stream.PassThrough()
|
115 | }));
|
116 | s.end();
|
117 |
|
118 | });
|
119 | });
|
120 |
|
121 | });
|