Skip to content

Commit 30d4c11

Browse files
authored
test(utils): Add comprehensive unit tests for format-utils module (#86)
- Added tests for `DateFormatter` methods: - `constructor` with valid and invalid inputs - `fromMicroseconds` with valid and invalid inputs - `toMicroseconds` and `micros` methods - `toMilliseconds` and `millis` methods - `toISOString` and `toISO` methods - `toDateObject` method - `toString` method - `toLocaleString` method with various locales - Added tests for `FormatUtils` methods: - `parseFormatObject` with valid and invalid inputs - `sortThumbnailsByResolution` with valid and invalid inputs - `getAuthorThumbnails` with various scenarios - `getVideoThumbnails` with various scenarios - `getAllThumbnails` with various scenarios - `getThumbnailByResolution` with various scenarios - `getThumbnail` with various scenarios - `hasVideo` with formats containing and not containing video - `hasAudio` with formats containing and not containing audio - Added several assets for these unit tests to test various scenarios: - `test/assets/json/formats.json` - `test/assets/json/videoThumbnails.json` - `test/assets/json/authorThumbnails.json` Authored-by: Ryuu Mitsuki <[email protected]>
1 parent 2344336 commit 30d4c11

File tree

4 files changed

+597
-0
lines changed

4 files changed

+597
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"url": "https://yt3.ggpht.com/EXAMPLE=s48-c-k-c0x00ffffff-no-rj",
4+
"width": 48,
5+
"height": 48
6+
},
7+
{
8+
"url": "https://yt3.ggpht.com/EXAMPLE=s88-c-k-c0x00ffffff-no-rj",
9+
"width": 88,
10+
"height": 88
11+
},
12+
{
13+
"url": "https://yt3.ggpht.com/EXAMPLE=s176-c-k-c0x00ffffff-no-rj",
14+
"width": 176,
15+
"height": 176
16+
}
17+
]

test/assets/json/formats.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"audioonly": {
3+
"mimeType": "audio/mp4; codecs=\"mp4a.40.2\"",
4+
"qualityLabel": null,
5+
"bitrate": 131110,
6+
"audioBitrate": 128,
7+
"itag": 140,
8+
"url": "https://example.com/videoplayback?audio-only",
9+
"initRange": {
10+
"start": "0",
11+
"end": "667"
12+
},
13+
"indexRange": {
14+
"start": "668",
15+
"end": "1023"
16+
},
17+
"lastModified": "1649941229498837",
18+
"contentLength": "4317886",
19+
"quality": "tiny",
20+
"projectionType": "RECTANGULAR",
21+
"averageBitrate": 129556,
22+
"highReplication": true,
23+
"audioQuality": "AUDIO_QUALITY_MEDIUM",
24+
"approxDurationMs": "266626",
25+
"audioSampleRate": "44100",
26+
"audioChannels": 2,
27+
"loudnessDb": 7.81,
28+
"hasVideo": false,
29+
"hasAudio": true,
30+
"container": "mp4",
31+
"codecs": "mp4a.40.2",
32+
"videoCodec": null,
33+
"audioCodec": "mp4a.40.2",
34+
"isLive": false,
35+
"isHLS": false,
36+
"isDashMPD": false
37+
},
38+
"videoonly": {
39+
"mimeType": "video/webm; codecs=\"vp9\"",
40+
"qualityLabel": "1080p",
41+
"bitrate": 2764193,
42+
"itag": 137,
43+
"url": "https://example.com/videoplayback?video-only",
44+
"initRange": {
45+
"start": "0",
46+
"end": "239"
47+
},
48+
"indexRange": {
49+
"start": "240",
50+
"end": "500"
51+
},
52+
"lastModified": "1649941229498837",
53+
"contentLength": "108642789",
54+
"quality": "hd1080",
55+
"projectionType": "RECTANGULAR",
56+
"averageBitrate": 2764173,
57+
"highReplication": false,
58+
"approxDurationMs": "266626",
59+
"hasVideo": true,
60+
"hasAudio": false,
61+
"container": "webm",
62+
"codecs": "vp9",
63+
"videoCodec": "vp9",
64+
"audioCodec": null,
65+
"isLive": false,
66+
"isHLS": false,
67+
"isDashMPD": false
68+
},
69+
"combined": {
70+
"mimeType": "video/mp4; codecs=\"avc1.640028, mp4a.40.2\"",
71+
"qualityLabel": "720p",
72+
"bitrate": 1581508,
73+
"itag": 22,
74+
"url": "https://example.com/videoplayback?combined",
75+
"lastModified": "1649941229498837",
76+
"contentLength": "5400000",
77+
"quality": "hd720",
78+
"projectionType": "RECTANGULAR",
79+
"averageBitrate": 1575000,
80+
"audioQuality": "AUDIO_QUALITY_MEDIUM",
81+
"approxDurationMs": "266626",
82+
"audioSampleRate": "44100",
83+
"audioChannels": 2,
84+
"loudnessDb": 5.43,
85+
"hasVideo": true,
86+
"hasAudio": true,
87+
"container": "mp4",
88+
"codecs": "avc1.640028, mp4a.40.2",
89+
"videoCodec": "avc1.640028",
90+
"audioCodec": "mp4a.40.2",
91+
"isLive": false,
92+
"isHLS": false,
93+
"isDashMPD": false
94+
}
95+
}

test/assets/json/videoThumbnails.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"url": "https://i.ytimg.com/vi/VIDEO_ID/hqdefault.jpg",
4+
"width": 168,
5+
"height": 94
6+
},
7+
{
8+
"url": "https://i.ytimg.com/vi/VIDEO_ID/mqdefault.jpg",
9+
"width": 320,
10+
"height": 180
11+
},
12+
{
13+
"url": "https://i.ytimg.com/vi/VIDEO_ID/sddefault.jpg",
14+
"width": 640,
15+
"height": 480
16+
},
17+
{
18+
"url": "https://i.ytimg.com/vi/VIDEO_ID/maxresdefault.jpg",
19+
"width": 1280,
20+
"height": 720
21+
}
22+
]

0 commit comments

Comments
 (0)