-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawl.test.js
More file actions
57 lines (49 loc) · 1.97 KB
/
crawl.test.js
File metadata and controls
57 lines (49 loc) · 1.97 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
import { normalizeURL } from './crawl.js'
import { getURLsFromHTML } from './crawl.js'
import { test, expect } from '@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 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)
})
// URL from HTML test
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)
})