-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspiderable_tests.js
executable file
·62 lines (60 loc) · 1.79 KB
/
spiderable_tests.js
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
var url = Npm.require("url");
Tinytest.add("spiderable - phantom url generation", function (test, expect) {
var absUrl = "http://example.com";
_.each([
// Requests resulting from `<meta name="fragment" content="!">`
// will have an `_escaped_fragment_` which is present but blank,
// which we want to represent as having no hash fragment
// parameter. (Note this means we cannot distinguish between `/`
// and `/#!`).
{
requestUrl: "/?_escaped_fragment_=",
expected: "/"
},
// Test that a nonempty fragment is tunneled through to the generated URL
{
requestUrl: "/?_escaped_fragment_=1",
expected: "/#!1"
},
// Test decoding the encoded escaped fragment.
{
requestUrl: "/?_escaped_fragment_=abc%3D123%26def%3D456",
expected: "/#!abc=123&def=456"
},
// Test that query strings are preserved
{
requestUrl: "/?_escaped_fragment_=1&foo=bar",
expected: "/?foo=bar#!1"
},
{
requestUrl: "/?foo=bar&_escaped_fragment_=1",
expected: "/?foo=bar#!1"
},
// Test that paths are preserved
{
requestUrl: "/foo/bar?_escaped_fragment_=1",
expected: "/foo/bar#!1"
},
{
requestUrl: "/foo/bar?_escaped_fragment_=1&foo=bar",
expected: "/foo/bar?foo=bar#!1"
},
// Test with a path on the site's absolute url
{
requestUrl: "/foo/bar?_escaped_fragment_=1",
expected: "/foo/bar#!1",
absUrl: "http://example.com/foo"
},
{
requestUrl: "/bar?_escaped_fragment_=1",
expected: "/bar#!1",
absUrl: "http://example.com/foo"
}
], function (testCase) {
testCase.absUrl = testCase.absUrl || absUrl;
test.equal(
Spiderable._urlForPhantom(absUrl, testCase.requestUrl),
absUrl + testCase.expected
);
});
});