-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
test.ts
92 lines (73 loc) · 2.55 KB
/
test.ts
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
82
83
84
85
86
87
88
89
90
91
92
import { unfurl } from "../../src/";
import nock from "nock";
test("should handle content which is escaped badly", async () => {
nock("http://localhost")
.get("/html/double-escaped-edge-case")
.replyWithFile(200, __dirname + "/double escaped-edge-case.html", {
"Content-Type": "text/html",
});
const result = await unfurl("http://localhost/html/double-escaped-edge-case");
expect(result.description).toEqual('"');
});
test("should detect title, description, keywords and canonical URL", async () => {
nock("http://localhost")
.get("/html/basic")
.replyWithFile(200, __dirname + "/basic.html", {
"Content-Type": "text/html",
});
const result = await unfurl("http://localhost/html/basic");
const expected = {
favicon: "http://localhost/favicon.ico",
author: "abc",
description: "aaa",
keywords: ["a", "b", "c"],
title: "ccc",
theme_color: "#ff00ff",
canonical_url: "https://ccc.website.test/basic/",
};
expect(result).toEqual(expected);
});
test("should detect title, description, keywords and canonical URL even when they are in the body", async () => {
nock("http://localhost")
.get("/html/basic-body")
.replyWithFile(200, __dirname + "/basic-body.html", {
"Content-Type": "text/html",
});
const result = await unfurl("http://localhost/html/basic-body");
const expected = {
favicon: "http://localhost/favicon.ico",
description: "aaa",
keywords: ["a", "b", "c"],
title: "ccc",
canonical_url: "http://ccc.website.test/basic/",
};
expect(result).toEqual(expected);
});
test("should detect last dupe of title, description and keywords", async () => {
nock("http://localhost")
.get("/html/basic-duplicates")
.replyWithFile(200, __dirname + "/basic-duplicates.html", {
"Content-Type": "text/html",
});
const result = await unfurl("http://localhost/html/basic-duplicates");
const expected = {
favicon: "http://localhost/favicon.ico",
description: "aaa",
keywords: ["a", "b", "c"],
title: "ccc",
};
expect(result).toEqual(expected);
});
test("should detect last dupe of title, description and keywords", async () => {
nock("http://localhost")
.get("/html/keyword-edge-cases")
.replyWithFile(200, __dirname + "/keyword-edge-cases.html", {
"Content-Type": "text/html",
});
const result = await unfurl("http://localhost/html/keyword-edge-cases");
const expected = {
favicon: "http://localhost/favicon.ico",
keywords: ["foo", "bar", "baz quix", "foo", "foo"],
};
expect(result).toEqual(expected);
});