-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawl.test.js
68 lines (56 loc) · 2.18 KB
/
crawl.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
const {NormalizeURL,getHTMLURLs}=require('./crawl.js')
const {test,expect}=require('@jest/globals')
//NormalizeURL
test('check protocol' ,()=>{
const inputurl='https://learnweb3.io'
const processing=NormalizeURL(inputurl)
const actualurl= 'learnweb3.io'
expect(processing).toEqual(actualurl)
})
test( 'check slash' ,()=>{
const inputurl='https://learnweb3.io/'
const processing=NormalizeURL(inputurl)
const actualurl= 'learnweb3.io'
expect(processing).toEqual(actualurl)
})
test('Check http',()=>{
const inputurl='http://learnweb3.io'
const processing=NormalizeURL(inputurl)
const actualurl= 'learnweb3.io'
expect(processing).toEqual(actualurl)
})
test('check case',()=>{
const inputurl='https://leaRnwEb3.io'
const processing=NormalizeURL(inputurl)
const actualurl= 'learnweb3.io'
expect(processing).toEqual(actualurl)
})
//getHTMLURLs
test('relative path check',()=>{
const baseurl='https://learnweb3.io'
const inputurl='<body><a href="/courses"><span>Learnweb3</span></a></body>'
const processing=getHTMLURLs(inputurl,baseurl)
const actualurl=['https://learnweb3.io/courses']
expect(processing).toEqual(actualurl)
})
test('absolute path check',()=>{
const baseurl='https://learnweb3.io'
const inputurl='<body><a href="https://learnweb3.io/courses"><span>Learnweb3 courses"</span></a></body>'
const processing=getHTMLURLs(inputurl,baseurl)
const actualurl=['https://learnweb3.io/courses']
expect(processing).toEqual(actualurl)
})
test('check broken links',()=>{
const baseurl='https://learnweb3.io'
const inputurl='<body><a href="courses"><span>Learnweb3</span></a></body>'
const processing=getHTMLURLs(inputurl,baseurl)
const actualurl=[]
expect(processing).toEqual(actualurl)
})
test('check both ',()=>{
const baseurl='https://learnweb3.io'
const inputurl='<body><a href="https://learnweb3.io/courses"><span>Learnweb3 courses"</span></a><a href=/community><span>Learnweb3 courses</span></a></body>'
const processing=getHTMLURLs(inputurl,baseurl)
const actualurl=['https://learnweb3.io/courses','https://learnweb3.io/community']
expect(processing).toEqual(actualurl)
})