test router using file protocol as start point
This commit is contained in:
parent
20da8d3dc8
commit
8ec3a3f2c5
6 changed files with 686 additions and 676 deletions
|
|
@ -11,8 +11,9 @@ var apiPubSub = require("../../api/pubsub")
|
||||||
var apiRouter = require("../../api/router")
|
var apiRouter = require("../../api/router")
|
||||||
|
|
||||||
o.spec("route", function() {
|
o.spec("route", function() {
|
||||||
|
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
|
||||||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
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 FRAME_BUDGET = Math.floor(1000 / 60)
|
||||||
var $window, root, redraw, route
|
var $window, root, redraw, route
|
||||||
|
|
||||||
|
|
@ -22,7 +23,7 @@ o.spec("route", function() {
|
||||||
var dom = domMock()
|
var dom = domMock()
|
||||||
for (var key in dom) $window[key] = dom[key]
|
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]
|
for (var key in loc) $window[key] = loc[key]
|
||||||
|
|
||||||
root = $window.document.body
|
root = $window.document.body
|
||||||
|
|
@ -220,11 +221,11 @@ o.spec("route", function() {
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
var slash = prefix[0] === "/" ? "" : "/"
|
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)
|
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()
|
done()
|
||||||
})
|
})
|
||||||
|
|
@ -333,4 +334,5 @@ o.spec("route", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ var buildQueryString = require("../querystring/build")
|
||||||
var parseQueryString = require("../querystring/parse")
|
var parseQueryString = require("../querystring/parse")
|
||||||
|
|
||||||
module.exports = function($window) {
|
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 callAsync = typeof setImmediate === "function" ? setImmediate : setTimeout
|
||||||
|
|
||||||
var prefix = "#!"
|
var prefix = "#!"
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@ var pushStateMock = require("../../test-utils/pushStateMock")
|
||||||
var Router = require("../../router/router")
|
var Router = require("../../router/router")
|
||||||
|
|
||||||
o.spec("Router.defineRoutes", function() {
|
o.spec("Router.defineRoutes", function() {
|
||||||
|
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
|
||||||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
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
|
var $window, router, onRouteChange, onFail
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = pushStateMock()
|
$window = pushStateMock(env)
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
router.setPrefix(prefix)
|
router.setPrefix(prefix)
|
||||||
onRouteChange = o.spy()
|
onRouteChange = o.spy()
|
||||||
|
|
@ -299,4 +300,5 @@ o.spec("Router.defineRoutes", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,13 @@ var pushStateMock = require("../../test-utils/pushStateMock")
|
||||||
var Router = require("../../router/router")
|
var Router = require("../../router/router")
|
||||||
|
|
||||||
o.spec("Router.getPath", function() {
|
o.spec("Router.getPath", function() {
|
||||||
|
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
|
||||||
void ["#", "?", "", "#!", "?!", '/foo'].forEach(function(prefix) {
|
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
|
var $window, router, onRouteChange, onFail
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = pushStateMock()
|
$window = pushStateMock(env)
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
router.setPrefix(prefix)
|
router.setPrefix(prefix)
|
||||||
onRouteChange = o.spy()
|
onRouteChange = o.spy()
|
||||||
|
|
@ -43,4 +44,5 @@ o.spec("Router.getPath", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,13 @@ var pushStateMock = require("../../test-utils/pushStateMock")
|
||||||
var Router = require("../../router/router")
|
var Router = require("../../router/router")
|
||||||
|
|
||||||
o.spec("Router.setPath", function() {
|
o.spec("Router.setPath", function() {
|
||||||
|
void [{protocol: "http:", hostname: "localhost"}, {protocol: "file:", hostname: "/"}].forEach(function(env) {
|
||||||
void ["#", "?", "", "#!", "?!", "/foo"].forEach(function(prefix) {
|
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
|
var $window, router, onRouteChange, onFail
|
||||||
|
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = pushStateMock()
|
$window = pushStateMock(env)
|
||||||
router = new Router($window)
|
router = new Router($window)
|
||||||
router.setPrefix(prefix)
|
router.setPrefix(prefix)
|
||||||
onRouteChange = o.spy()
|
onRouteChange = o.spy()
|
||||||
|
|
@ -132,7 +133,7 @@ o.spec("Router.setPath", function() {
|
||||||
router.setPath("/other", null, {replace: true})
|
router.setPath("/other", null, {replace: true})
|
||||||
$window.history.back()
|
$window.history.back()
|
||||||
|
|
||||||
o($window.location.href).equals("http://localhost/")
|
o($window.location.href).equals(env.protocol + "//" + (env.hostname === "/" ? "" : env.hostname) + "/")
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
@ -147,11 +148,12 @@ o.spec("Router.setPath", function() {
|
||||||
|
|
||||||
var slash = prefix[0] === "/" ? "" : "/"
|
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()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@
|
||||||
|
|
||||||
var parseURL = require("../test-utils/parseURL")
|
var parseURL = require("../test-utils/parseURL")
|
||||||
|
|
||||||
module.exports = function() {
|
module.exports = function(options) {
|
||||||
var protocol = "http:"
|
if (options == null) options = {}
|
||||||
var hostname = "localhost"
|
|
||||||
|
var protocol = options.protocol || "http:"
|
||||||
|
var hostname = options.hostname || "localhost"
|
||||||
var port = ""
|
var port = ""
|
||||||
var pathname = "/"
|
var pathname = "/"
|
||||||
var search = ""
|
var search = ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue