-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawl.test.js
More file actions
81 lines (72 loc) · 2.68 KB
/
crawl.test.js
File metadata and controls
81 lines (72 loc) · 2.68 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
const { test, expect } = require("@jest/globals");
const { normalizeURL } = require("./crawl.js");
const { getURLsFromHTML } = require("./crawl.js");
test("normalizeURL", () => {
expect(normalizeURL("https://www.google.com/search")).toBe(
"www.google.com/search"
);
});
test("normalizeURL slash", () => {
const input = "https://blog.boot.dev/path/";
const actual = normalizeURL(input);
const expected = "blog.boot.dev/path";
expect(actual).toEqual(expected);
});
test("normalizeURL capitals", () => {
const input = "https://BLOG.boot.dev/path";
const actual = normalizeURL(input);
const expected = "blog.boot.dev/path";
expect(actual).toEqual(expected);
});
test("normalizeURL http", () => {
const input = "http://BLOG.boot.dev/path";
const actual = normalizeURL(input);
const expected = "blog.boot.dev/path";
expect(actual).toEqual(expected);
});
test("getting all URLs from HTMl ", () => {
const input =
'<a href="https://www.google.com/search">Google</a> <a href="/search/bitch">Bing</a> <a href="/search/ded">Yahoo</a>';
const actual = getURLsFromHTML(input, "https://www.google.com");
const expected = [
"https://www.google.com/search",
"https://www.google.com/search/bitch",
"https://www.google.com/search/ded",
];
expect(actual).toEqual(expected);
});
test("getURLsFromHTML absolute", () => {
const inputURL = "https://blog.boot.dev";
const inputBody =
'<html><body><a href="https://blog.boot.dev"><span>Boot.dev></span></a></body></html>';
const actual = getURLsFromHTML(inputBody, inputURL);
const expected = ["https://blog.boot.dev/"];
expect(actual).toEqual(expected);
});
test("getURLsFromHTML relative", () => {
const inputURL = "https://blog.boot.dev";
const inputBody =
'<html><body><a href="/path/one"><span>Boot.dev></span></a></body></html>';
const actual = getURLsFromHTML(inputBody, inputURL);
const expected = ["https://blog.boot.dev/path/one"];
expect(actual).toEqual(expected);
});
test("getURLsFromHTML both", () => {
const inputURL = "https://blog.boot.dev";
const inputBody =
'<html><body><a href="/path/one"><span>Boot.dev></span></a><a href="https://other.com/path/one"><span>Boot.dev></span></a></body></html>';
const actual = getURLsFromHTML(inputBody, inputURL);
const expected = [
"https://blog.boot.dev/path/one",
"https://other.com/path/one",
];
expect(actual).toEqual(expected);
});
test("getURLsFromHTML handle error", () => {
const inputURL = "https://blog.boot.dev";
const inputBody =
'<html><body><a href="path/one"><span>Boot.dev></span></a></body></html>';
const actual = getURLsFromHTML(inputBody, inputURL);
const expected = [];
expect(actual).toEqual(expected);
});