-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathserver-utils.spec.ts
More file actions
77 lines (69 loc) · 2.29 KB
/
Copy pathserver-utils.spec.ts
File metadata and controls
77 lines (69 loc) · 2.29 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
import { URLPattern } from "urlpattern-polyfill";
import { expect } from "./test-utils";
import { shouldPassThrough } from "../src/util/server-utils";
describe("shouldPassThrough", () => {
it("should return false when passThroughHostnames is empty and interceptOnlyHostnames is undefined", async () => {
const should = shouldPassThrough("example.org", [], undefined);
expect(should).to.be.false;
});
it("should return true when both lists empty", async () => {
const should = shouldPassThrough("example.org", [], []);
expect(should).to.be.true;
});
it("should return false when hostname is falsy", () => {
const should = shouldPassThrough("", [], []);
expect(should).to.be.false;
});
describe("passThroughHostnames", () => {
it("should return true when hostname is in passThroughHostnames", () => {
const should = shouldPassThrough(
"example.org",
[new URLPattern("https://example.org")],
undefined
);
expect(should).to.be.true;
});
it("should return false when hostname is not in passThroughHostnames", () => {
const should = shouldPassThrough(
"example.org",
[new URLPattern("https://example.com")],
undefined
);
expect(should).to.be.false;
});
it("should return true when hostname match a wildcard", () => {
const should = shouldPassThrough(
"example.org",
[new URLPattern("https://*.org")],
undefined
);
expect(should).to.be.true;
});
});
describe("interceptOnlyHostnames", () => {
it("should return false when hostname is in interceptOnlyHostnames", () => {
const should = shouldPassThrough(
"example.org",
[],
[new URLPattern("https://example.org")]
);
expect(should).to.be.false;
});
it("should return true when hostname is not in interceptOnlyHostnames", () => {
const should = shouldPassThrough(
"example.org",
[],
[new URLPattern("https://example.com")]
);
expect(should).to.be.true;
});
it("should return false when hostname match a wildcard", () => {
const should = shouldPassThrough(
"example.org",
[],
[new URLPattern("https://*.org")]
);
expect(should).to.be.false;
});
});
});