test router using file protocol as start point

This commit is contained in:
Leo Horie 2016-08-02 23:21:13 -04:00
parent 20da8d3dc8
commit 8ec3a3f2c5
6 changed files with 686 additions and 676 deletions

View file

@ -11,8 +11,9 @@ var apiPubSub = require("../../api/pubsub")
var apiRouter = require("../../api/router")
o.spec("route", function() {
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
o.spec("using prefix `" + prefix + "`", function() {
o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() {
var FRAME_BUDGET = Math.floor(1000 / 60)
var $window, root, redraw, route
@ -22,7 +23,7 @@ o.spec("route", function() {
var dom = domMock()
for (var key in dom) $window[key] = dom[key]
var loc = pushStateMock()
var loc = pushStateMock(env)
for (var key in loc) $window[key] = loc[key]
root = $window.document.body
@ -220,11 +221,11 @@ o.spec("route", function() {
callAsync(function() {
var slash = prefix[0] === "/" ? "" : "/"
o($window.location.href).equals("http://localhost" + slash + (prefix ? prefix + "/" : ""))
o($window.location.href).equals(env.protocol + "//" + (env.hostname === "/" ? "" : env.hostname) + slash + (prefix ? prefix + "/" : ""))
root.firstChild.dispatchEvent(e)
o($window.location.href).equals("http://localhost" + slash + (prefix ? prefix + "/" : "") + "test")
o($window.location.href).equals(env.protocol + "//" + (env.hostname === "/" ? "" : env.hostname) + slash + (prefix ? prefix + "/" : "") + "test")
done()
})
@ -334,3 +335,4 @@ o.spec("route", function() {
})
})
})
})

View file

@ -4,7 +4,7 @@ var buildQueryString = require("../querystring/build")
var parseQueryString = require("../querystring/parse")
module.exports = function($window) {
var supportsPushState = typeof $window.history.pushState === "function" && $window.location.protocol !== "file:"
var supportsPushState = typeof $window.history.pushState === "function"
var callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout
var prefix = "#!"

View file

@ -6,12 +6,13 @@ var pushStateMock = require("../../test-utils/pushStateMock")
var Router = require("../../router/router")
o.spec("Router.defineRoutes", function() {
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
o.spec("using prefix `" + prefix + "`", function() {
o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() {
var $window, router, onRouteChange, onFail
o.beforeEach(function() {
$window = pushStateMock()
$window = pushStateMock(env)
router = new Router($window)
router.setPrefix(prefix)
onRouteChange = o.spy()
@ -300,3 +301,4 @@ o.spec("Router.defineRoutes", function() {
})
})
})
})

View file

@ -5,12 +5,13 @@ var pushStateMock = require("../../test-utils/pushStateMock")
var Router = require("../../router/router")
o.spec("Router.getPath", function() {
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
void ["#", "?", "", "#!", "?!", '/foo'].forEach(function(prefix) {
o.spec("using prefix `" + prefix + "`", function() {
o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() {
var $window, router, onRouteChange, onFail
o.beforeEach(function() {
$window = pushStateMock()
$window = pushStateMock(env)
router = new Router($window)
router.setPrefix(prefix)
onRouteChange = o.spy()
@ -44,3 +45,4 @@ o.spec("Router.getPath", function() {
})
})
})
})

View file

@ -6,12 +6,13 @@ var pushStateMock = require("../../test-utils/pushStateMock")
var Router = require("../../router/router")
o.spec("Router.setPath", function() {
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
o.spec("using prefix `" + prefix + "`", function() {
o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() {
var $window, router, onRouteChange, onFail
o.beforeEach(function() {
$window = pushStateMock()
$window = pushStateMock(env)
router = new Router($window)
router.setPrefix(prefix)
onRouteChange = o.spy()
@ -132,7 +133,7 @@ o.spec("Router.setPath", function() {
router.setPath("/other", null, {replace: true})
$window.history.back()
o($window.location.href).equals("http://localhost/")
o($window.location.href).equals(env.protocol + "//" + (env.hostname === "/" ? "" : env.hostname) + "/")
done()
})
@ -147,7 +148,7 @@ o.spec("Router.setPath", function() {
var slash = prefix[0] === "/" ? "" : "/"
o($window.location.href).equals("http://localhost" + slash + (prefix ? prefix + "/" : "") + "test")
o($window.location.href).equals(env.protocol + "//" + (env.hostname === "/" ? "" : env.hostname) + slash + (prefix ? prefix + "/" : "") + "test")
done()
})
@ -155,3 +156,4 @@ o.spec("Router.setPath", function() {
})
})
})
})

View file

@ -2,9 +2,11 @@
var parseURL = require("../test-utils/parseURL")
module.exports = function() {
var protocol = "http:"
var hostname = "localhost"
module.exports = function(options) {
if (options == null) options = {}
var protocol = options.protocol || "http:"
var hostname = options.hostname || "localhost"
var port = ""
var pathname = "/"
var search = ""