-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
executable file
·255 lines (234 loc) · 9.96 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
'use strict'
var test = require('tape')
var splash = require('./')
var exec = require('child_process').exec
test('returns all splash images in array', function (t) {
t.plan(2)
var images = splash()
t.ok(Array.isArray(images), 'returned an array')
t.equal(images.length, 11, '11 images returned')
})
test('returns splash image for size 320 as Number', function (t) {
t.plan(3)
var image = splash({size: 320})
t.equal(image.name, 'Default~iphone.png', 'image has correct name')
t.equal(image.width, 320, 'image has correct width')
t.equal(image.height, 480, 'image has correct height')
})
test('returns splash image for width 640 as Number', function (t) {
t.plan(3)
var image = splash({width: '640'})
t.equal(image.name, 'Default@2x~iphone.png', 'image has correct name')
t.equal(image.width, 640, 'image has correct width')
t.equal(image.height, 960, 'image has correct height')
})
test('returns splash image for height 1024 as Number', function (t) {
t.plan(3)
var image = splash({height: 1024})
t.equal(image.name, 'Default-Portrait~ipad.png', 'image has correct name')
t.equal(image.width, 768, 'image has correct width')
t.equal(image.height, 1024, 'image has correct height')
})
test('returns splash image for size 1024 as String', function (t) {
t.plan(3)
var image = splash({size: '1024'})
t.equal(image.name, 'Default-Landscape~ipad.png', 'image has correct name')
t.equal(image.width, 1024, 'image has correct width')
t.equal(image.height, 768, 'image has correct height')
})
test('returns splash image for width 2048 as String', function (t) {
t.plan(3)
var image = splash({width: '2048'})
t.equal(image.name, 'Default-Landscape@2x~ipad.png', 'image has correct name')
t.equal(image.width, 2048, 'image has correct width')
t.equal(image.height, 1536, 'image has correct height')
})
test('returns splash image for height 1136 as String', function (t) {
t.plan(3)
var image = splash({height: '1136'})
t.equal(image.name, 'Default-568h@2x~iphone.png', 'image has correct name')
t.equal(image.width, 640, 'image has correct width')
t.equal(image.height, 1136, 'image has correct height')
})
test('returns splash image for size 667h', function (t) {
t.plan(3)
var image = splash({size: '667h'})
t.equal(image.name, 'Default-667h.png', 'image has correct name')
t.equal(image.width, 750, 'image has correct width')
t.equal(image.height, 1334, 'image has correct height')
})
test('returns splash image for size Landscape-736h', function (t) {
t.plan(3)
var image = splash({size: 'Landscape-736h'})
t.equal(image.name, 'Default-Landscape-736h.png', 'image has correct name')
t.equal(image.width, 2208, 'image has correct width')
t.equal(image.height, 1242, 'image has correct height')
})
test('returns splash image for size @2x~iphone', function (t) {
t.plan(3)
var image = splash({size: '@2x~iphone'})
t.equal(image.name, 'Default@2x~iphone.png', 'image has correct name')
t.equal(image.width, 640, 'image has correct width')
t.equal(image.height, 960, 'image has correct height')
})
test('returns splash image for width 320, prioritizing over size', function (t) {
t.plan(3)
var image = splash({size: '@2x~iphone.png', width: 320})
t.equal(image.name, 'Default~iphone.png', 'image has correct name')
t.equal(image.width, 320, 'image has correct width')
t.equal(image.height, 480, 'image has correct height')
})
test('returns storyboard image for width 2732, prioritizing over size', function (t) {
t.plan(3)
var image = splash({size: 'Default@2x~universal~anyany', width: 2732})
t.equal(image.name, 'Default@2x~universal~anyany.png', 'image has correct name')
t.equal(image.width, 2732, 'image has correct width')
t.equal(image.height, 2732, 'image has correct height')
})
test('returns null for width 1234', function (t) {
t.plan(1)
var image = splash({width: 1234})
t.ok(image === null)
})
test('returns null for size @3x-foo', function (t) {
t.plan(1)
var image = splash({size: '@3x-foo'})
t.ok(image === null)
})
test('cli returns all splash images as csv', function (t) {
t.plan(1)
var expected = 'Default~iphone.png,320,480\nDefault@2x~iphone.png,640,960\nDefault-Portrait~ipad.png,768,1024\nDefault-Portrait@2x~ipad.png,1536,2048\nDefault-Landscape~ipad.png,1024,768\nDefault-Landscape@2x~ipad.png,2048,1536\nDefault-568h@2x~iphone.png,640,1136\nDefault-667h.png,750,1334\nDefault-736h.png,1242,2208\nDefault-Landscape-736h.png,2208,1242\nDefault@2x~universal~anyany.png,2732,2732\n'
exec('./bin/ios-splash.js', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
})
test('cli returns correct image for width 320 as csv', function (t) {
t.plan(1)
var expected = 'Default~iphone.png,320,480\n'
exec('./bin/ios-splash.js --width 320', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
})
test('cli returns correct image for size "~iphone" as json', function (t) {
t.plan(1)
var expected = '{"name":"Default~iphone.png","width":320,"height":480}\n'
exec('./bin/ios-splash.js --size ~iphone --format json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
})
// abbrev
test('cli returns all splash images as json w/ & w/o abbreviated flags', function (t) {
t.plan(6)
var expected = '[{"name":"Default~iphone.png","width":320,"height":480},{"name":"Default@2x~iphone.png","width":640,"height":960},{"name":"Default-Portrait~ipad.png","width":768,"height":1024},{"name":"Default-Portrait@2x~ipad.png","width":1536,"height":2048},{"name":"Default-Landscape~ipad.png","width":1024,"height":768},{"name":"Default-Landscape@2x~ipad.png","width":2048,"height":1536},{"name":"Default-568h@2x~iphone.png","width":640,"height":1136},{"name":"Default-667h.png","width":750,"height":1334},{"name":"Default-736h.png","width":1242,"height":2208},{"name":"Default-Landscape-736h.png","width":2208,"height":1242},{"name":"Default@2x~universal~anyany.png","width":2732,"height":2732}]\n'
exec('./bin/ios-splash.js --format json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --forma json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --form json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --for json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --fo json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --f json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
})
test('cli returns correct image for width 320 w/ abbreviated flags', function (t) {
t.plan(4)
var expected = 'Default~iphone.png,320,480\n'
exec('./bin/ios-splash.js --widt 320', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --wid 320', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --wi 320', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --w 320', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
})
test('cli returns correct image for size "~iphone" as json w/ abbreviated flags', function (t) {
t.plan(3)
var expected = '{"name":"Default~iphone.png","width":320,"height":480}\n'
exec('./bin/ios-splash.js --siz ~iphone --format json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --si ~iphone --format json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
exec('./bin/ios-splash.js --s ~iphone --format json', function (error, stdout, stderr) {
var err = error || stderr
if (err) {
return t.fail('calling cli produced an error: ' + err)
}
t.equal(stdout, expected, 'cli returned the expected output')
})
})