This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
scraper.test.js
143 lines (126 loc) · 5.96 KB
/
scraper.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
const ytcm = require('../index')
describe('Standalone Mode: Comment Testing', () => {
console.log('Please be advised that these tests only cover the Standalone mode of the module.\nThe Integration mode with applications like Electron cannot be tested without including such tools.\nUnder normal circumstances Integration mode should work, if comments on FreeTube work.')
test('Scrape top video comments of first page', () => {
const parameters = { videoId: 'oBLQmE-nG60', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments).not.toHaveLength(0)
})
})
test('Scrape newest video comments of first page', () => {
const parameters = { videoId: 'oBLQmE-nG60', mustSetCookie: true, sortByNewest: true }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments).not.toHaveLength(0)
})
})
test('Scrape newest video comments second page', () => {
const parameters = { videoId: 'oBLQmE-nG60', mustSetCookie: true, sortByNewest: true, continuation: null }
return ytcm.getComments(parameters).then((data) => {
parameters.continuation = data.continuation
ytcm.getComments(parameters).then((data) => {
expect(data.comments).not.toHaveLength(0)
})
})
})
test('Scrape top replies of first page', () => {
const parameters = { videoId: 'oBLQmE-nG60', mustSetCookie: true, sortByNewest: false }
// This test first gets comments of the video with above Id
return ytcm.getComments(parameters).then((data) => {
for (let i = 0; i < data.comments.length; i++) {
// The test searches for a comment which does have at least 1 reply and then ask for the replies
if (data.comments[i].numReplies > 0) {
const replyParameters = { videoId: 'oBLQmE-nG60', replyToken: data.comments[i].replyToken, mustSetCookie: true }
return ytcm.getCommentReplies(replyParameters).then((replyData) => {
expect(replyData.comments).not.toHaveLength(0)
})
}
}
})
})
test('Scrape second batch of top replies of first page', () => {
const parameters = { videoId: 'oBLQmE-nG60', mustSetCookie: true, sortByNewest: false }
// This test first gets comments of the video with above Id
return ytcm.getComments(parameters).then((data) => {
for (let i = 0; i < data.comments.length; i++) {
// The test searches for a comment which does have at least 1 reply and then ask for the replies
if (data.comments[i].numReplies > 0) {
const replyParameters = { videoId: 'oBLQmE-nG60', replyToken: data.comments[i].replyToken, mustSetCookie: true }
return ytcm.getCommentReplies(replyParameters).then((replyData) => {
replyParameters.replyToken = replyData.continuation
return ytcm.getCommentReplies(replyParameters).then((replyData) => {
expect(replyData.comments).not.toHaveLength(0)
})
})
}
}
})
})
test('Scrape video without comments', () => {
const parameters = { videoId: 'Bj-3M-KqZsI', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments).toHaveLength(0)
})
})
test('Scrape video with disabled comments', () => {
const parameters = { videoId: '2wuQMP9WuJ8', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments).toHaveLength(0)
})
})
test('Scrape owner replied to non-owner tag', () => {
const parameters = { videoId: 'M9xYCihLCdI', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].hasOwnerReplied).toBeTruthy()
})
})
test('Scrape owner replied to owner tag', () => {
const parameters = { videoId: 'HosbuE5LvIQ', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].hasOwnerReplied).toBeTruthy()
})
})
test('Scrape pinned tag', () => {
const parameters = { videoId: 'IiJAq53knwc', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].isPinned).toBeTruthy()
})
})
test('Scrape owner verified tag', () => {
const parameters = { videoId: 'oBLQmE-nG60', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].isVerified).toBeTruthy()
})
})
test('Scrape owner tag', () => {
const parameters = { videoId: 'oBLQmE-nG60', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].isOwner).toBeTruthy()
})
})
test('Scrape non owner verified tag', () => {
const parameters = { videoId: '2BO83Ig-E8E', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].isVerified).toBeTruthy()
})
})
test('Scrape owner isOfficialArtist tag', () => {
const parameters = { videoId: '5LMuolKKmAM', mustSetCookie: true, sortByNewest: false }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].isOfficialArtist).toBeTruthy()
})
})
test('Scrape customEmojis', () => {
const parameters = { videoId: 'HhuHyQlFz_M', mustSetCookie: true }
return ytcm.getComments(parameters).then((data) => {
expect(data.comments[0].customEmojis[0]).toBeTruthy()
})
})
test('Format text', () => {
const parameters = { videoId: 'OqiXFXlYFi8', mustSetCookie: true }
return ytcm.getComments(parameters).then((data) => {
const comment = data.comments.find(c => c.commentId === 'UgxTgxuBchteOmDLdGl4AaABAg')
expect(comment).not.toBeUndefined()
expect(comment.text).toBe('<b>This text will be bold</b> and <i>this will be italicized</i> and <s>this will will be crossed out</s>')
})
})
})