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