Files
meteor/packages/spiderable/spiderable_tests.js
Andrew Wilcox 5f1c8f2eeb Add spiderable support for hash fragments
Since the browser application cache appears not to support URL path
routes in a non-buggy way (see
https://github.com/meteor/meteor/pull/2926), applications using the
appcache package will want to use hash fragment routes instead.

This PR adds support to the spiderable package for hash fragment
routes.  An original URL such as `http://example.com/#!a=1&b=2` will
be encoded by a search engine as an escaped fragment, decoded by the
spiderable package, passed through to the phantomjs process, and
appear to the phantom client as `#!a=1&b=2` in `window.location.hash`
(the same as when the original URL is opened in a regular browser).
2015-01-26 15:54:47 -08:00

63 lines
1.8 KiB
JavaScript

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
);
});
});