-
Notifications
You must be signed in to change notification settings - Fork 65
/
bin.test.js
103 lines (92 loc) · 3.76 KB
/
bin.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
var test = require('tape');
var queue = require('queue-async');
var mkdirp = require('mkdirp');
var bin_output = path.resolve(__dirname + '/bin_output');
test('setup', function(t) {
mkdirp(bin_output, function(err) {
t.error(err, 'setup');
t.end();
});
});
test('bin/build-glyphs', function(t) {
var script = path.normalize(__dirname + '/../bin/build-glyphs'),
font = path.normalize(__dirname + '/../fonts/open-sans/OpenSans-Regular.ttf'),
dir = path.resolve(__dirname + '/bin_output');
exec([script, font, dir].join(' '), function(err, stdout, stderr) {
t.error(err);
t.error(stderr);
fs.readdir(bin_output, function(err, files) {
t.equal(files.length, 256, 'outputs 256 files');
t.equal(files.indexOf('0-255.pbf'), 0, 'expected .pbf');
t.equal(files.filter(function(f) {
return f.indexOf('.pbf') > -1;
}).length, files.length, 'all .pbfs');
t.end();
})
});
});
test('bin/font-inspect', function(t) {
var script = path.normalize(__dirname + '/../bin/font-inspect'),
opensans = path.normalize(__dirname + '/fixtures/fonts/OpenSans-Regular.ttf'),
firasans = path.normalize(__dirname + '/fixtures/fonts/FiraSans-Medium.ttf'),
registry = path.normalize(__dirname + '/fixtures/fonts');
t.test(' --face', function(q) {
exec([script, '--face=' + opensans].join(' '), function(err, stdout, stderr) {
q.error(err);
q.error(stderr);
q.ok(stdout.length, 'outputs to console');
var output = JSON.parse(stdout);
q.equal(output.length, 1, 'single face');
q.equal(output[0].face, 'Open Sans Regular');
q.ok(Array.isArray(output[0].coverage));
q.equal(output[0].coverage.length, 882);
q.end();
});
});
t.test(' --register', function(q) {
exec([script, '--register=' + registry].join(' '), function(err, stdout, stderr) {
q.error(err);
q.error(stderr);
q.ok(stdout.length, 'outputs to console');
var output = JSON.parse(stdout);
q.equal(output.length, 2, 'both faces in register');
q.equal(output[0].face, 'Fira Sans Medium', 'Fira Sans Medium');
q.ok(Array.isArray(output[0].coverage), 'codepoints array');
q.equal(output[1].face, 'Open Sans Regular', 'Open Sans Regular');
q.ok(Array.isArray(output[1].coverage), 'codepoints array');
q.end();
});
});
t.test(' --register --verbose', function(q) {
exec([script, '--verbose', '--register=' + registry].join(' '), function(err, stdout, stderr) {
q.error(err);
q.ok(stderr.length, 'writes verbose output to stderr');
q.equal(stderr.indexOf('resolved'), 0);
var verboseOutput = JSON.parse(stderr.slice(9).trim().replace(/'/g, '"'));
t.equal(verboseOutput.length, 2);
t.equal(verboseOutput.filter(function(f) { return f.indexOf('.ttf') > -1; }).length, 2);
q.ok(stdout.length, 'writes codepoints output to stdout');
q.ok(JSON.parse(stdout));
q.end();
});
});
t.end();
});
test('teardown', function(t) {
var q = queue();
fs.readdir(bin_output, function(err, files) {
files.forEach(function(f) {
q.defer(fs.unlink, path.join(bin_output, '/', f));
});
q.awaitAll(function(err) {
t.error(err, 'teardown');
fs.rmdir(bin_output, function(err) {
t.error(err, 'teardown');
t.end();
});
});
});
});