forked from Turistforeningen/node-im-metadata
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
180 lines (148 loc) · 5.02 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*jshint laxbreak:true */
var assert = require('assert');
var metadata = require('./index');
describe('metadata.cmd()', function () {
it('returns command without exif data', function () {
var cmd = 'identify -format "name=\nsize=%[size]\nformat=%m\n' + 'colorspace=%[colorspace]\nheight=%[height]\nwidth=%[width]\n' + 'orientation=%[orientation]\n" /foo/bar/baz';
assert.equal(metadata.cmd('/foo/bar/baz'), cmd);
});
it('returns command with exif data', function () {
var cmd = 'identify -format "name=\nsize=%[size]\nformat=%m\n' + 'colorspace=%[colorspace]\nheight=%[height]\nwidth=%[width]\n' + 'orientation=%[orientation]\n%[exif:*]" /foo/bar/baz';
assert.equal(metadata.cmd('/foo/bar/baz', {
exif: true
}), cmd);
});
});
describe('metadata.parse()', function () {
var path = '/foo/bar/baz.jpg';
it('returns object for single value', function () {
assert.deepEqual(metadata.parse(path, 'foo=bar'), {
path: path,
foo: 'bar'
});
});
it('returns object for metadata string', function () {
assert.deepEqual(metadata.parse(path, 'foo=bar\nbar=foo'), {
path: path,
foo: 'bar',
bar: 'foo'
});
});
it('skips empty lines', function () {
assert.deepEqual(metadata.parse(path, 'foo=bar\n\nbar=foo\n\n'), {
path: path,
foo: 'bar',
bar: 'foo'
});
});
it('returns correct size for bogus value', function () {
assert.deepEqual(metadata.parse(path, 'size=4.296MBB'), {
path: path,
size: 4504682
});
});
it('returns size in bytes', function () {
assert.deepEqual(metadata.parse(path, 'size=20MB'), {
path: path,
size: 20 * 1024 * 1024
});
});
it('returns RGB for sRGB colorspace', function () {
assert.deepEqual(metadata.parse(path, 'colorspace=sRGB'), {
path: path,
colorspace: 'RGB'
});
});
it('returns "" for Undefined orientation', function () {
assert.deepEqual(metadata.parse(path, 'orientation=Undefined'), {
path: path,
orientation: ''
});
});
it('returns height and widt for auto-orient', function () {
var meta = 'width=100\nheight=150\norientation=';
var opts = {
autoOrient: true
};
var orientation = [
'TopLeft', 'TopRight', 'BottomRight', 'BottomLeft',
'LeftTop', 'RightTop', 'RightBottom', 'LeftBottom'
];
for (var i = 0; i < 4; i++) {
assert.deepEqual(metadata.parse(path, meta + orientation[i], opts), {
height: 150,
width: 100,
path: path,
orientation: orientation[i]
});
}
for (var j = 4; j < 8; j++) {
assert.deepEqual(metadata.parse(path, meta + orientation[j], opts), {
height: 100,
width: 150,
path: path,
orientation: orientation[j]
});
}
});
});
describe('metadata()', function () {
it('returns metadata for image', function (done) {
metadata('./assets/image.jpg', {
exif: false
}, function (err, data) {
assert.ifError(err);
assert.equal(data.path, './assets/image.jpg');
assert.equal(data.name, '');
assert.equal(data.size, 4504682);
assert.equal(data.format, 'JPEG');
assert.equal(data.colorspace, 'RGB');
assert.equal(data.height, 3456);
assert.equal(data.width, 5184);
assert.equal(data.orientation, 'TopLeft');
assert.equal(typeof data.exif, 'undefined');
done();
});
});
it('returns metadata for image with exif data', function (done) {
metadata('./assets/image.jpg', {
exif: true
}, function (err, data) {
assert.ifError(err);
assert.equal(data.path, './assets/image.jpg');
assert.equal(data.name, '');
assert.equal(data.size, 4504682);
assert.equal(data.format, 'JPEG');
assert.equal(data.colorspace, 'RGB');
assert.equal(data.height, 3456);
assert.equal(data.width, 5184);
assert.equal(data.orientation, 'TopLeft');
assert.equal(typeof data.exif, 'object');
assert.equal(Object.keys(data.exif).length, 36);
assert.equal(data.exif.ApertureValue, '37/8');
done();
});
});
it('returns correct height and width for auto-orient', function (done) {
metadata('./assets/orient.jpg', {
autoOrient: true
}, function (err, data) {
assert.ifError(err);
assert.equal(data.height, 3264);
assert.equal(data.width, 2448);
done();
});
});
});
describe('quiet mode', function () {
it('returns command without quiet option', function () {
var cmd = 'identify -format "name=\nsize=%[size]\nformat=%m\n' + 'colorspace=%[colorspace]\nheight=%[height]\nwidth=%[width]\n' + 'orientation=%[orientation]\n" /foo/bar/baz';
assert.equal(metadata.cmd('/foo/bar/baz'), cmd);
});
it('returns command with quiet options', function () {
var cmd = 'identify -quiet -format "name=\nsize=%[size]\nformat=%m\n' + 'colorspace=%[colorspace]\nheight=%[height]\nwidth=%[width]\n' + 'orientation=%[orientation]\n" /foo/bar/baz';
assert.equal(metadata.cmd('/foo/bar/baz', {
quiet: true
}), cmd);
});
});