-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawl.test.js
More file actions
64 lines (54 loc) · 2.32 KB
/
crawl.test.js
File metadata and controls
64 lines (54 loc) · 2.32 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
const { normalizeURL, getURLfromHTML } = require('./crawl.js');
const { test, expect } = require('@jest/globals');
test(`normalizeURL protocol`, () => {
const input = 'https://blog.boot.dev/path/'
const actual = normalizeURL(input)
const expected = 'blog.boot.dev/path'
expect(actual).toEqual(expected)
})
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 normal`, () => {
const input = 'http://blog.boot.dev/path/'
const actual = normalizeURL(input)
const expected = 'blog.boot.dev/path'
expect(actual).toEqual(expected)
})
test(`normalizeURL normal slash`, () => {
const input = 'http://blog.boot.dev/path'
const actual = normalizeURL(input)
const expected = 'blog.boot.dev/path'
expect(actual).toEqual(expected)
})
test(`getURLfromHTML 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 = getURLfromHTML(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 = getURLfromHTML(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></body></html><html><body><a href="https://other.boot.dev"><span>Boot.dev></span></a></body></html>'
const actual = getURLfromHTML(inputBODY, inputURL)
const expected = [ 'https://blog.boot.dev/path/one', 'https://other.boot.dev/']
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 = getURLfromHTML(inputBODY, inputURL)
const expected = []
expect(actual).toEqual(expected)
})