-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
437 lines (318 loc) · 12.2 KB
/
test.js
File metadata and controls
437 lines (318 loc) · 12.2 KB
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
const util = require('util');
const {versions, getFileInfo, AvFormatContext, AvDuration, AvChapter, AvProgram,
AvStreamVideo, AvStreamAudio, AvStreamData, AvStreamSubtitle, AvStreamAttachment} = require('.');
const delay = util.promisify(setTimeout);
describe('versions property', () => {
test('should be an object type', () => {
expect(typeof versions).toBe('object');
});
describe('should has string value on the property', () => {
test('avcodec', () => {
expect(typeof versions.avcodec).toBe('string');
});
test('avutil', () => {
expect(typeof versions.avutil).toBe('string');
});
test('avformat', () => {
expect(typeof versions.avformat).toBe('string');
});
});
});
describe('getFileInfo method', () => {
describe('should throw an error for', () => {
test('invalid type of filePath', async() => {
const msg = 'filePath parameter should be a string value';
await expect(getFileInfo()).rejects.toThrow(msg);
await expect(getFileInfo(234)).rejects.toThrow(msg);
await expect(getFileInfo(null)).rejects.toThrow(msg);
await expect(getFileInfo({filePath:'test-assets/test.mp4'})).rejects.toThrow(msg);
await expect(getFileInfo(['test-assets/test.mp4'])).rejects.toThrow(msg);
});
test('non-exists filePath on filesystem', async() => {
const msg = 'filePath could not be opened';
await expect(getFileInfo('')).rejects.toThrow(msg);
await expect(getFileInfo('test-assets/test')).rejects.toThrow(msg);
});
test('invalid type of options', async() => {
const msg = 'options can only be an object';
await expect(getFileInfo('test-assets/test.mp4', 123)).rejects.toThrow(msg);
await expect(getFileInfo('test-assets/test.mp4', null)).rejects.toThrow(msg);
await expect(getFileInfo('test-assets/test.mp4', 'asdf')).rejects.toThrow(msg);
});
// test('invalid media contents of a file on the filesystem', async() => {
// const msg = 'filePath could not be opened';
// await expect(getFileInfo('test-assets/nonsense.txt')).rejects.toThrow(msg);
// });
});
describe('should return an object', () => {
beforeAll(async() => {
this.result = await Promise.all([
getFileInfo('test-assets/test.mp4'), getFileInfo('test-assets/main.m3u')
]);
});
test('instance of AvFormatContext', () => {
const [first, last] = this.result;
expect(first).toBeInstanceOf(AvFormatContext);
expect(last).toBeInstanceOf(AvFormatContext);
});
test('should have simiar structure of sample objects', () => {
const [first, last] = this.result;
expect(first).toMatchObject({
name: 'mov,mp4,m4a,3gp,3g2,mj2',
url: 'test-assets/test.mp4',
bitrate: 15646,
duration: expect.any(AvDuration),
startTime: expect.any(AvDuration),
flags: 2097152,
metadata: {
compatible_brands: 'isomiso2avc1mp41',
encoder: 'Lavf59.6.100',
major_brand: 'isom',
minor_version: '512'
},
streams: [
expect.any(AvStreamVideo),
expect.any(AvStreamAudio),
expect.any(AvStreamData)
],
chapters: [
expect.any(AvChapter),
expect.any(AvChapter),
expect.any(AvChapter)
],
programs: []
});
expect(last).toMatchObject({
name: 'hls',
url: 'test-assets/main.m3u',
bitrate: 42044,
duration: null,
startTime: null,
flags: 2097152,
metadata: {},
streams: expect.anything(),
chapters: [],
programs: [
expect.any(AvProgram),
expect.any(AvProgram)
]
});
});
});
});
describe('AvProgram class', () => {
describe('throw a TypeError from constructor', () => {
test('when program id parameter is not a number type', () => {
const msg = 'Program ID value should be numeric';
for (const value of [undefined, null, '123', [], {}]) {
expect(() => {
new AvProgram(value);
}).toThrow(msg);
}
});
test('when flags parameter is not a number type', () => {
const msg = 'Flags value should be numeric';
for (const value of [undefined, null, '123', [], {}]) {
expect(() => {
new AvProgram(23, value);
}).toThrow(msg);
}
});
test('when discard parameter is not a number type', () => {
const msg = 'Discard value should be numeric';
for (const value of [undefined, null, '123', [], {}]) {
expect(() => {
new AvProgram(23, 12, value);
}).toThrow(msg);
}
});
test('when streams parameter is not an array type', () => {
const msg = 'Streams value should be an array';
for (const value of [undefined, null, '123', {}]) {
expect(() => {
new AvProgram(23, 12, 45, value);
}).toThrow(msg);
}
});
test('when metadata parameter is not an object type', () => {
const msg = 'Metadata value should be object';
for (const value of [null, '123', []]) {
expect(() => {
new AvProgram(23, 12, 45, [], value);
}).toThrow(msg);
}
});
test('when programNum parameter is not a number type', () => {
const msg = 'ProgramNum value should be numeric';
for (const value of [null, '123', [], {}]) {
expect(() => {
new AvProgram(23, 12, 45, [], {}, value);
}).toThrow(msg);
}
});
test('when pmtPid parameter is not a number type', () => {
const msg = 'PmtPid value should be numeric';
for (const value of [null, '123', [], {}]) {
expect(() => {
new AvProgram(23, 12, 45, [], {}, 1, value);
}).toThrow(msg);
}
});
test('when pcrPid parameter is not a number type', () => {
const msg = 'PcrPid value should be numeric';
for (const value of [null, '123', [], {}]) {
expect(() => {
new AvProgram(23, 12, 45, [], {}, 1, 2, value);
}).toThrow(msg);
}
});
test('when pmtVersion parameter is not a number type', () => {
const msg = 'PmtVersion value should be numeric';
for (const value of [null, '123', [], {}]) {
expect(() => {
new AvProgram(23, 12, 45, [], {}, 1, 2, 3, value);
}).toThrow(msg);
}
});
});
test('constructor parameters population to member properties', () => {
expect(new AvProgram(23, 12, 45, [])).toMatchObject({
id: 23,
flags: 12,
discard: 45,
streams: []
});
expect(new AvProgram(23, 12, 45, [], {foo: 'bar'})).toMatchObject({
id: 23,
flags: 12,
discard: 45,
streams: [],
metadata: {foo: 'bar'}
});
expect(new AvProgram(23, 12, 45, [], {foo: 'bar'}, 11, 22, 33)).toMatchObject({
id: 23,
flags: 12,
discard: 45,
streams: [],
metadata: {foo: 'bar'},
programNum: 11,
pmtPid: 22,
pcrPid: 33
});
});
});
describe('AvChapter class', () => {
describe('throw a TypeError from constructor', () => {
test('when chapter id parameter is not a number type', () => {
const msg = 'Chapter ID value should be numeric';
for (const value of [undefined, null, '123', [], {}]) {
expect(() => {
new AvChapter(value);
}).toThrow(msg);
}
});
test('when chapter start parameter is not a number type', () => {
const msg = 'Chapter start time should be numeric';
for (const value of [undefined, null, '123', [], {}]) {
expect(() => {
new AvChapter(123, value);
}).toThrow(msg);
}
});
test('when chapter end parameter is not a number type', () => {
const msg = 'Chapter end time should be numeric';
for (const value of [undefined, null, '123', [], {}]) {
expect(() => {
new AvChapter(123, 456, value);
}).toThrow(msg);
}
});
test('when metadata parameter is not an object type', () => {
const msg = 'Metadata parameter type is invalid';
for (const value of [null, '123', []]) {
expect(() => {
new AvChapter(123, 456, 789, value);
}).toThrow(msg);
}
});
test('should have simiar structure of sample objects', () => {
const chapter1 = new AvChapter(123, 456, 789, {
bam: 'bim'
});
expect(chapter1).toMatchObject({
id: 123,
start: 456,
end: 789,
metadata: {
bam: 'bim'
}
});
const chapter2 = new AvChapter(222, 444, 666);
expect(chapter2).toMatchObject({
id: 222,
start: 444,
end: 666,
metadata: {}
});
});
});
});
describe('AvDuration class', () => {
test('throw a TypeError from constructor for non-numeric parameter', () => {
const msg = 'A number was expected';
expect(() => {
new AvDuration();
}).toThrow(msg);
for (const value of [undefined, null, '123', [], {}]) {
expect(() => {
new AvDuration(value);
}).toThrow(msg);
}
});
describe('instance members', () => {
const timeSerial = 9876543210;
const duration = new AvDuration(timeSerial);
test('valueOf method', () => {
expect(duration.valueOf()).toBe(timeSerial);
});
test('toString method', () => {
expect(duration.toString()).toBe('02:44:36.54');
});
test('field values', () => {
expect(duration).toMatchObject({
hours: 2,
minutes: 44,
seconds: 36,
microseconds: 54
});
});
});
});
describe('AvStream classes', () => {
test('throw an Error from constructor because it is private', () => {
const msg = 'Direct initialization is not allowed for this wrapper clas';
expect(() => {
new AvStreamVideo();
}).toThrow(msg);
expect(() => {
new AvStreamAudio();
}).toThrow(msg);
expect(() => {
new AvStreamData();
}).toThrow(msg);
expect(() => {
new AvStreamSubtitle();
}).toThrow(msg);
expect(() => {
new AvStreamAttachment();
}).toThrow(msg);
});
});
describe('AvFormatContext class', () => {
test('throw an Error from constructor because it is private', () => {
const msg = 'Direct initialization is not allowed for this wrapper class';
expect(() => {
new AvFormatContext();
}).toThrow(msg);
});
});