1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var gulp = require('gulp');
|
6 | var gutil = require('gulp-util');
|
7 | var Stream = require('stream');
|
8 | var fs = require('fs');
|
9 | var path = require('path');
|
10 |
|
11 | var assert = require('assert');
|
12 | var StreamTest = require('streamtest');
|
13 |
|
14 | var svg2ttf = require('../src/index.js');
|
15 |
|
16 | describe('gulp-svg2ttf conversion', function() {
|
17 | var filename = path.join(__dirname, 'fixtures', 'iconsfont');
|
18 | var ttf = fs.readFileSync(filename + '.ttf');
|
19 | var ttfCopyfighted = fs.readFileSync(filename + '-copyright.ttf');
|
20 | var generationTimestamp = 3;
|
21 |
|
22 |
|
23 | StreamTest.versions.forEach(function(version) {
|
24 |
|
25 | describe('for ' + version + ' streams', function() {
|
26 |
|
27 | describe('with null contents', function() {
|
28 |
|
29 | it('should let null files pass through', function(done) {
|
30 |
|
31 | StreamTest[version].fromObjects([new gutil.File({
|
32 | path: 'bibabelula.foo',
|
33 | contents: null,
|
34 | })])
|
35 | .pipe(svg2ttf({
|
36 | timestamp: generationTimestamp,
|
37 | }))
|
38 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
39 | if(err) {
|
40 | return done(err);
|
41 | }
|
42 | assert.equal(objs.length, 1);
|
43 | assert.equal(objs[0].path, 'bibabelula.foo');
|
44 | assert.equal(objs[0].contents, null);
|
45 | done();
|
46 | }));
|
47 |
|
48 | });
|
49 |
|
50 | });
|
51 |
|
52 | describe('in buffer mode', function() {
|
53 |
|
54 | it('should work', function(done) {
|
55 |
|
56 | gulp.src(filename + '.svg', { buffer: true })
|
57 | .pipe(svg2ttf({
|
58 | timestamp: generationTimestamp,
|
59 | }))
|
60 |
|
61 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
62 | if(err) {
|
63 | return done(err);
|
64 | }
|
65 | assert.equal(objs.length, 1);
|
66 | assert.equal(objs[0].path, filename + '.ttf');
|
67 | assert.equal(objs[0].contents.toString('utf-8'), ttf.toString('utf-8'));
|
68 | done();
|
69 | }));
|
70 |
|
71 | });
|
72 |
|
73 | it('should work with the copyright option', function(done) {
|
74 |
|
75 | gulp.src(filename + '.svg', { buffer: true })
|
76 | .pipe(svg2ttf({
|
77 | timestamp: generationTimestamp,
|
78 | copyright: 'Brothershood of mens 2015 - Infinity',
|
79 | }))
|
80 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
81 | if(err) {
|
82 | return done(err);
|
83 | }
|
84 | assert.equal(objs.length, 1);
|
85 | assert.equal(objs[0].path, filename + '.ttf');
|
86 | assert.deepEqual(objs[0].contents, ttfCopyfighted);
|
87 | done();
|
88 | }));
|
89 |
|
90 | });
|
91 |
|
92 | it('should work with the clone option', function(done) {
|
93 |
|
94 | gulp.src(filename + '.svg', { buffer: true })
|
95 | .pipe(svg2ttf({
|
96 | clone: true,
|
97 | timestamp: generationTimestamp,
|
98 | }))
|
99 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
100 | if(err) {
|
101 | return done(err);
|
102 | }
|
103 | assert.equal(objs.length, 2);
|
104 | assert.equal(objs[0].path, filename + '.svg');
|
105 | assert.equal(
|
106 | objs[0].contents.toString('utf-8'),
|
107 | fs.readFileSync(filename + '.svg', 'utf-8')
|
108 | );
|
109 | assert.equal(objs[1].path, filename + '.ttf');
|
110 | assert.equal(objs[1].contents.toString('utf-8'), ttf.toString('utf-8'));
|
111 | done();
|
112 | }));
|
113 |
|
114 | });
|
115 |
|
116 | it('should let non-svg files pass through', function(done) {
|
117 |
|
118 | StreamTest[version].fromObjects([new gutil.File({
|
119 | path: 'bibabelula.foo',
|
120 | contents: new Buffer('ohyeah'),
|
121 | })])
|
122 | .pipe(svg2ttf({
|
123 | timestamp: generationTimestamp,
|
124 | }))
|
125 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
126 | if(err) {
|
127 | return done(err);
|
128 | }
|
129 | assert.equal(objs.length, 1);
|
130 | assert.equal(objs[0].path, 'bibabelula.foo');
|
131 | assert.equal(objs[0].contents.toString('utf-8'), 'ohyeah');
|
132 | done();
|
133 | }));
|
134 |
|
135 | });
|
136 | });
|
137 |
|
138 |
|
139 | describe('in stream mode', function() {
|
140 | it('should work', function(done) {
|
141 |
|
142 | gulp.src(filename + '.svg', { buffer: false })
|
143 | .pipe(svg2ttf({
|
144 | timestamp: generationTimestamp,
|
145 | }))
|
146 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
147 | if(err) {
|
148 | return done(err);
|
149 | }
|
150 | assert.equal(objs.length, 1);
|
151 | assert.equal(objs[0].path, filename + '.ttf');
|
152 | objs[0].contents.pipe(StreamTest[version].toChunks(function(err, chunks) {
|
153 | if(err) {
|
154 | return done(err);
|
155 | }
|
156 | assert.deepEqual(Buffer.concat(chunks), ttf);
|
157 | done();
|
158 | }));
|
159 | }));
|
160 |
|
161 | });
|
162 |
|
163 | it('should work with the clone option', function(done) {
|
164 |
|
165 | gulp.src(filename + '.svg', { buffer: false })
|
166 | .pipe(svg2ttf({
|
167 | clone: true,
|
168 | timestamp: generationTimestamp,
|
169 | }))
|
170 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
171 | if(err) {
|
172 | return done(err);
|
173 | }
|
174 | assert.equal(objs.length, 2);
|
175 | assert.equal(objs[0].path, filename + '.svg');
|
176 | assert.equal(objs[1].path, filename + '.ttf');
|
177 | objs[0].contents.pipe(StreamTest[version].toText(function(err, text) {
|
178 | if(err) {
|
179 | return done(err);
|
180 | }
|
181 | assert.equal(text, fs.readFileSync(filename + '.svg', 'utf-8'));
|
182 | objs[1].contents.pipe(StreamTest[version].toChunks(function(err, chunks) {
|
183 | if(err) {
|
184 | return done(err);
|
185 | }
|
186 | assert.deepEqual(Buffer.concat(chunks), ttf);
|
187 | done();
|
188 | }));
|
189 | }));
|
190 | }));
|
191 |
|
192 | });
|
193 |
|
194 | it('should let non-svg files pass through', function(done) {
|
195 |
|
196 | StreamTest[version].fromObjects([new gutil.File({
|
197 | path: 'bibabelula.foo',
|
198 | contents: new Stream.PassThrough(),
|
199 | })])
|
200 | .pipe(svg2ttf({
|
201 | timestamp: generationTimestamp,
|
202 | }))
|
203 | .pipe(StreamTest[version].toObjects(function(err, objs) {
|
204 | if(err) {
|
205 | return done(err);
|
206 | }
|
207 | assert.equal(objs.length, 1);
|
208 | assert.equal(objs[0].path, 'bibabelula.foo');
|
209 | assert(objs[0].contents instanceof Stream.PassThrough);
|
210 | done();
|
211 | }));
|
212 |
|
213 | });
|
214 | });
|
215 |
|
216 | });
|
217 |
|
218 | });
|
219 |
|
220 | });
|