-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawl.test.js
59 lines (49 loc) · 1.82 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
import {test, expect} from "@jest/globals"
import {normalizeURL, getURLsFromHTML} from "./crawl.js"
const test_string = "https://blog.boot.dev/path/"
const test_string_r = "blog.boot.dev/path"
const test_string_2 = "https://blog.boot.dev/path"
const test_string_3 = "http://blog.boot.dev/path/"
const test_string_4 = "http://blog.boot.dev/path"
test('Any Result at All', () => {
expect(normalizeURL(test_string)).not.toBe("")
})
test('test_string normalized', () => {
expect(normalizeURL(test_string)).toBe(test_string_r)
})
test('test_string_2 normalized', () => {
expect(normalizeURL(test_string_2)).toBe(test_string_r)
})
test('test_string_3 normalized', () => {
expect(normalizeURL(test_string_3)).toBe(test_string_r)
})
test('test_string_4 normalized', () => {
expect(normalizeURL(test_string_4)).toBe(test_string_r)
})
// Testing getURLsFromHTML
const base_URL = 'https://blog.boot.dev';
const html_1 =
'<html>' +
' <body>'+
' <a href="https://blog.boot.dev"><span>Go to Boot.dev</span></a>'+
' <a href="https://blog.boot.dev"><span>Go to Boot.dev</span></a>'+
' <a href="https://blog.boot.dev/some/random/path"><span>Go to Boot.dev</span></a>'+
' <a href="/another/random/path"><span>Go to Boot.dev</span></a>'+
' </body>'+
'</html>';
const html_1_r = "https://blog.boot.dev/";
test('Basic URL from HTML', () => {
const result = getURLsFromHTML(html_1, base_URL);
const text = result[0];
expect(text).toBe(html_1_r);
})
test('Proper Link Count', ()=> {
const result = getURLsFromHTML(html_1, base_URL);
expect(result.length).toBe(4);
})
test('Relative Paths are converted to Absolute path', () => {
const result = getURLsFromHTML(html_1, base_URL);
for (let i=0; i<result.length; i++) {
expect(result[i]).toContain(html_1_r);
}
})