"use strict" and other linty fixes
This commit is contained in:
parent
aaa6de784b
commit
1cc5fa5ba7
50 changed files with 463 additions and 478 deletions
|
|
@ -1,11 +1,6 @@
|
||||||
coverage
|
|
||||||
.vscode
|
.vscode
|
||||||
examples
|
/node_modules
|
||||||
docs
|
/examples
|
||||||
node_modules
|
/docs/lib
|
||||||
tests
|
/mithril.js
|
||||||
test-utils
|
/mithril.min.js
|
||||||
ospec
|
|
||||||
mithril.js
|
|
||||||
mithril.min.js
|
|
||||||
archive
|
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ module.exports = {
|
||||||
"quotes": [
|
"quotes": [
|
||||||
"error",
|
"error",
|
||||||
"double",
|
"double",
|
||||||
"avoid-escape"
|
{"avoidEscape": true}
|
||||||
],
|
],
|
||||||
"radix": [
|
"radix": [
|
||||||
"error",
|
"error",
|
||||||
|
|
@ -209,7 +209,7 @@ module.exports = {
|
||||||
"space-infix-ops": "off",
|
"space-infix-ops": "off",
|
||||||
"space-unary-ops": "error",
|
"space-unary-ops": "error",
|
||||||
"spaced-comment": "off",
|
"spaced-comment": "off",
|
||||||
"strict": "off",
|
"strict": ["error", "global"],
|
||||||
"template-curly-spacing": "error",
|
"template-curly-spacing": "error",
|
||||||
"valid-jsdoc": "off",
|
"valid-jsdoc": "off",
|
||||||
"vars-on-top": "off",
|
"vars-on-top": "off",
|
||||||
|
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ jsconfig.json
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
.vscode
|
.vscode
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.eslintcache
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,8 @@ o.spec("mount", function() {
|
||||||
|
|
||||||
o("redraws on events", function(done) {
|
o("redraws on events", function(done) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var onclick = o.spy()
|
var onclick = o.spy()
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
@ -109,11 +109,11 @@ o.spec("mount", function() {
|
||||||
timeout(60)
|
timeout(60)
|
||||||
|
|
||||||
var onupdate0 = o.spy()
|
var onupdate0 = o.spy()
|
||||||
var oninit0 = o.spy()
|
var oninit0 = o.spy()
|
||||||
var onclick0 = o.spy()
|
var onclick0 = o.spy()
|
||||||
var onupdate1 = o.spy()
|
var onupdate1 = o.spy()
|
||||||
var oninit1 = o.spy()
|
var oninit1 = o.spy()
|
||||||
var onclick1 = o.spy()
|
var onclick1 = o.spy()
|
||||||
|
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ var browserMock = require("../../test-utils/browserMock")
|
||||||
|
|
||||||
var m = require("../../render/hyperscript")
|
var m = require("../../render/hyperscript")
|
||||||
var callAsync = require("../../test-utils/callAsync")
|
var callAsync = require("../../test-utils/callAsync")
|
||||||
var coreRenderer = require("../../render/render")
|
|
||||||
var apiRedraw = require("../../api/redraw")
|
var apiRedraw = require("../../api/redraw")
|
||||||
var apiRouter = require("../../api/router")
|
var apiRouter = require("../../api/router")
|
||||||
var Promise = require("../../promise/promise")
|
var Promise = require("../../promise/promise")
|
||||||
|
|
@ -31,7 +30,7 @@ o.spec("route", function() {
|
||||||
o("throws on invalid `root` DOM node", function() {
|
o("throws on invalid `root` DOM node", function() {
|
||||||
var threw = false
|
var threw = false
|
||||||
try {
|
try {
|
||||||
route(null, '/', {'/':{view: function() {}}})
|
route(null, "/", {"/":{view: function() {}}})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
threw = true
|
threw = true
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +205,6 @@ o.spec("route", function() {
|
||||||
o("event handlers can skip redraw", function(done) {
|
o("event handlers can skip redraw", function(done) {
|
||||||
var onupdate = o.spy()
|
var onupdate = o.spy()
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var onclick = o.spy()
|
|
||||||
var e = $window.document.createEvent("MouseEvents")
|
var e = $window.document.createEvent("MouseEvents")
|
||||||
|
|
||||||
e.initEvent("click", true, true)
|
e.initEvent("click", true, true)
|
||||||
|
|
@ -354,11 +352,6 @@ o.spec("route", function() {
|
||||||
o("accepts RouteResolver with onmatch that returns Promise<undefined>", function(done) {
|
o("accepts RouteResolver with onmatch that returns Promise<undefined>", function(done) {
|
||||||
var matchCount = 0
|
var matchCount = 0
|
||||||
var renderCount = 0
|
var renderCount = 0
|
||||||
var Component = {
|
|
||||||
view: function() {
|
|
||||||
return m("span")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var resolver = {
|
var resolver = {
|
||||||
onmatch: function(args, requestedPath) {
|
onmatch: function(args, requestedPath) {
|
||||||
|
|
@ -395,11 +388,6 @@ o.spec("route", function() {
|
||||||
o("accepts RouteResolver with onmatch that returns Promise<any>", function(done) {
|
o("accepts RouteResolver with onmatch that returns Promise<any>", function(done) {
|
||||||
var matchCount = 0
|
var matchCount = 0
|
||||||
var renderCount = 0
|
var renderCount = 0
|
||||||
var Component = {
|
|
||||||
view: function() {
|
|
||||||
return m("span")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var resolver = {
|
var resolver = {
|
||||||
onmatch: function(args, requestedPath) {
|
onmatch: function(args, requestedPath) {
|
||||||
|
|
@ -437,14 +425,9 @@ o.spec("route", function() {
|
||||||
var matchCount = 0
|
var matchCount = 0
|
||||||
var renderCount = 0
|
var renderCount = 0
|
||||||
var spy = o.spy()
|
var spy = o.spy()
|
||||||
var Component = {
|
|
||||||
view: function() {
|
|
||||||
return m("span")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var resolver = {
|
var resolver = {
|
||||||
onmatch: function(args, requestedPath) {
|
onmatch: function() {
|
||||||
matchCount++
|
matchCount++
|
||||||
return Promise.reject(new Error("error"))
|
return Promise.reject(new Error("error"))
|
||||||
},
|
},
|
||||||
|
|
@ -499,7 +482,7 @@ o.spec("route", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
o("changing `vnode.key` in `render` resets the component", function(done, timeout){
|
o("changing `vnode.key` in `render` resets the component", function(done){
|
||||||
var oninit = o.spy()
|
var oninit = o.spy()
|
||||||
var Component = {
|
var Component = {
|
||||||
oninit: oninit,
|
oninit: oninit,
|
||||||
|
|
@ -548,22 +531,15 @@ o.spec("route", function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
o("RouteResolver `render` does not have component semantics", function(done) {
|
o("RouteResolver `render` does not have component semantics", function(done) {
|
||||||
var renderCount = 0
|
|
||||||
var A = {
|
|
||||||
view: function() {
|
|
||||||
return m("div")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$window.location.href = prefix + "/a"
|
$window.location.href = prefix + "/a"
|
||||||
route(root, "/a", {
|
route(root, "/a", {
|
||||||
"/a" : {
|
"/a" : {
|
||||||
render: function(vnode) {
|
render: function() {
|
||||||
return m("div")
|
return m("div")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"/b" : {
|
"/b" : {
|
||||||
render: function(vnode) {
|
render: function() {
|
||||||
return m("div")
|
return m("div")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -632,7 +608,7 @@ o.spec("route", function() {
|
||||||
onmatch: function() {
|
onmatch: function() {
|
||||||
matchCount++
|
matchCount++
|
||||||
},
|
},
|
||||||
render: function(vnode) {
|
render: function() {
|
||||||
renderCount++
|
renderCount++
|
||||||
return {tag: Component}
|
return {tag: Component}
|
||||||
},
|
},
|
||||||
|
|
@ -726,7 +702,7 @@ o.spec("route", function() {
|
||||||
render: render
|
render: render
|
||||||
},
|
},
|
||||||
"/b" : {
|
"/b" : {
|
||||||
render: function(vnode){
|
render: function(){
|
||||||
redirected = true
|
redirected = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -838,7 +814,7 @@ o.spec("route", function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
route.set('/b')
|
route.set("/b")
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
|
|
@ -865,7 +841,7 @@ o.spec("route", function() {
|
||||||
render: render
|
render: render
|
||||||
},
|
},
|
||||||
"/b" : {
|
"/b" : {
|
||||||
onmatch: function(vnode){
|
onmatch: function(){
|
||||||
redirected = true
|
redirected = true
|
||||||
return {view: function() {}}
|
return {view: function() {}}
|
||||||
}
|
}
|
||||||
|
|
@ -895,7 +871,7 @@ o.spec("route", function() {
|
||||||
render: render
|
render: render
|
||||||
},
|
},
|
||||||
"/b" : {
|
"/b" : {
|
||||||
render: function(vnode){
|
render: function(){
|
||||||
redirected = true
|
redirected = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -924,7 +900,7 @@ o.spec("route", function() {
|
||||||
render: render
|
render: render
|
||||||
},
|
},
|
||||||
"/b" : {
|
"/b" : {
|
||||||
view: function(vnode){
|
view: function(){
|
||||||
redirected = true
|
redirected = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1032,7 +1008,7 @@ o.spec("route", function() {
|
||||||
var render = o.spy(function() {return m("div")})
|
var render = o.spy(function() {return m("div")})
|
||||||
|
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, '/', {
|
route(root, "/", {
|
||||||
"/": {
|
"/": {
|
||||||
onmatch: onmatch,
|
onmatch: onmatch,
|
||||||
render: render
|
render: render
|
||||||
|
|
@ -1081,23 +1057,23 @@ o.spec("route", function() {
|
||||||
|
|
||||||
o("routing with RouteResolver works more than once", function(done) {
|
o("routing with RouteResolver works more than once", function(done) {
|
||||||
$window.location.href = prefix + "/a"
|
$window.location.href = prefix + "/a"
|
||||||
route(root, '/a', {
|
route(root, "/a", {
|
||||||
'/a': {
|
"/a": {
|
||||||
render: function() {
|
render: function() {
|
||||||
return m("a", "a")
|
return m("a", "a")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'/b': {
|
"/b": {
|
||||||
render: function() {
|
render: function() {
|
||||||
return m("b", "b")
|
return m("b", "b")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
route.set('/b')
|
route.set("/b")
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
route.set('/a')
|
route.set("/a")
|
||||||
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
o(root.firstChild.nodeName).equals("A")
|
o(root.firstChild.nodeName).equals("A")
|
||||||
|
|
@ -1122,7 +1098,7 @@ o.spec("route", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
render: function(vnode) {
|
render: function() {
|
||||||
rendered = true
|
rendered = true
|
||||||
resolved = "a"
|
resolved = "a"
|
||||||
}
|
}
|
||||||
|
|
@ -1180,7 +1156,7 @@ o.spec("route", function() {
|
||||||
route.set("/b")
|
route.set("/b")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
render: function(vnode) {
|
render: function() {
|
||||||
rendered = true
|
rendered = true
|
||||||
resolved = "a"
|
resolved = "a"
|
||||||
}
|
}
|
||||||
|
|
@ -1210,7 +1186,7 @@ o.spec("route", function() {
|
||||||
var i = 0
|
var i = 0
|
||||||
$window.location.href = prefix + "/"
|
$window.location.href = prefix + "/"
|
||||||
route(root, "/", {
|
route(root, "/", {
|
||||||
"/": {view: function(v) {i++}}
|
"/": {view: function() {i++}}
|
||||||
})
|
})
|
||||||
var before = i
|
var before = i
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var m = require("./index")
|
var m = require("./index")
|
||||||
if (typeof module !== "undefined") module["exports"] = m
|
if (typeof module !== "undefined") module["exports"] = m
|
||||||
else window.m = m
|
else window.m = m
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
"use strict"
|
||||||
|
|
||||||
require("../cli")
|
require("../cli")
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var o = require("../../ospec/ospec")
|
var o = require("../../ospec/ospec")
|
||||||
var bundle = require("../bundle")
|
var bundle = require("../bundle")
|
||||||
|
|
||||||
|
|
@ -5,10 +7,10 @@ var fs = require("fs")
|
||||||
|
|
||||||
var ns = "bundler/tests/"
|
var ns = "bundler/tests/"
|
||||||
function read(filepath) {
|
function read(filepath) {
|
||||||
try {return fs.readFileSync(ns + filepath, "utf8")} catch (e) {}
|
try {return fs.readFileSync(ns + filepath, "utf8")} catch (e) {/* ignore */}
|
||||||
}
|
}
|
||||||
function write(filepath, data) {
|
function write(filepath, data) {
|
||||||
try {var exists = fs.statSync(ns + filepath).isFile()} catch (e) {}
|
try {var exists = fs.statSync(ns + filepath).isFile()} catch (e) {/* ignore */}
|
||||||
if (exists) throw new Error("Don't call `write('" + filepath + "')`. Cannot overwrite file")
|
if (exists) throw new Error("Don't call `write('" + filepath + "')`. Cannot overwrite file")
|
||||||
fs.writeFileSync(ns + filepath, data, "utf8")
|
fs.writeFileSync(ns + filepath, data, "utf8")
|
||||||
}
|
}
|
||||||
|
|
@ -18,33 +20,33 @@ function remove(filepath) {
|
||||||
|
|
||||||
o.spec("bundler", function() {
|
o.spec("bundler", function() {
|
||||||
o("relative imports works", function() {
|
o("relative imports works", function() {
|
||||||
write("a.js", `var b = require("./b")`)
|
write("a.js", 'var b = require("./b")')
|
||||||
write("b.js", `module.exports = 1`)
|
write("b.js", "module.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b = 1\n}`)
|
o(read("out.js")).equals("new function() {\nvar b = 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("relative imports works with semicolons", function() {
|
o("relative imports works with semicolons", function() {
|
||||||
write("a.js", `var b = require("./b");`)
|
write("a.js", 'var b = require("./b");')
|
||||||
write("b.js", `module.exports = 1;`)
|
write("b.js", "module.exports = 1;")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b = 1;\n}`)
|
o(read("out.js")).equals("new function() {\nvar b = 1;\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("relative imports works with let", function() {
|
o("relative imports works with let", function() {
|
||||||
write("a.js", `let b = require("./b")`)
|
write("a.js", 'let b = require("./b")')
|
||||||
write("b.js", `module.exports = 1`)
|
write("b.js", "module.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nlet b = 1\n}`)
|
o(read("out.js")).equals("new function() {\nlet b = 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -52,143 +54,143 @@ o.spec("bundler", function() {
|
||||||
})
|
})
|
||||||
o("relative imports works with const", function() {
|
o("relative imports works with const", function() {
|
||||||
write("a.js", 'const b = require("./b")')
|
write("a.js", 'const b = require("./b")')
|
||||||
write("b.js", `module.exports = 1`)
|
write("b.js", "module.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nconst b = 1\n}`)
|
o(read("out.js")).equals("new function() {\nconst b = 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("relative imports works with assignment", function() {
|
o("relative imports works with assignment", function() {
|
||||||
write("a.js", `var a = {}\na.b = require("./b")`)
|
write("a.js", 'var a = {}\na.b = require("./b")')
|
||||||
write("b.js", `module.exports = 1`)
|
write("b.js", "module.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar a = {}\na.b = 1\n}`)
|
o(read("out.js")).equals("new function() {\nvar a = {}\na.b = 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("relative imports works with reassignment", function() {
|
o("relative imports works with reassignment", function() {
|
||||||
write("a.js", `var b = {}\nb = require("./b")`)
|
write("a.js", 'var b = {}\nb = require("./b")')
|
||||||
write("b.js", `module.exports = 1`)
|
write("b.js", "module.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b = {}\nb = 1\n}`)
|
o(read("out.js")).equals("new function() {\nvar b = {}\nb = 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("relative imports removes extra use strict", function() {
|
o("relative imports removes extra use strict", function() {
|
||||||
write("a.js", `"use strict"\nvar b = require("./b")`)
|
write("a.js", '"use strict"\nvar b = require("./b")')
|
||||||
write("b.js", `"use strict"\nmodule.exports = 1`)
|
write("b.js", '"use strict"\nmodule.exports = 1')
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\n"use strict"\nvar b = 1\n}`)
|
o(read("out.js")).equals('new function() {\n"use strict"\nvar b = 1\n}')
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("relative imports removes extra use strict using single quotes", function() {
|
o("relative imports removes extra use strict using single quotes", function() {
|
||||||
write("a.js", `'use strict'\nvar b = require("./b")`)
|
write("a.js", "'use strict'\nvar b = require(\"./b\")")
|
||||||
write("b.js", `'use strict'\nmodule.exports = 1`)
|
write("b.js", "'use strict'\nmodule.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\n'use strict'\nvar b = 1\n}`)
|
o(read("out.js")).equals("new function() {\n'use strict'\nvar b = 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("relative imports removes extra use strict using mixed quotes", function() {
|
o("relative imports removes extra use strict using mixed quotes", function() {
|
||||||
write("a.js", `"use strict"\nvar b = require("./b")`)
|
write("a.js", '"use strict"\nvar b = require("./b")')
|
||||||
write("b.js", `'use strict'\nmodule.exports = 1`)
|
write("b.js", "'use strict'\nmodule.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\n"use strict"\nvar b = 1\n}`)
|
o(read("out.js")).equals('new function() {\n"use strict"\nvar b = 1\n}')
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works w/ window", function() {
|
o("works w/ window", function() {
|
||||||
write("a.js", `window.a = 1\nvar b = require("./b")`)
|
write("a.js", 'window.a = 1\nvar b = require("./b")')
|
||||||
write("b.js", `module.exports = function() {return a}`)
|
write("b.js", "module.exports = function() {return a}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nwindow.a = 1\nvar b = function() {return a}\n}`)
|
o(read("out.js")).equals("new function() {\nwindow.a = 1\nvar b = function() {return a}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works without assignment", function() {
|
o("works without assignment", function() {
|
||||||
write("a.js", `require("./b")`)
|
write("a.js", 'require("./b")')
|
||||||
write("b.js", `1 + 1`)
|
write("b.js", "1 + 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\n1 + 1\n}`)
|
o(read("out.js")).equals("new function() {\n1 + 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if used fluently", function() {
|
o("works if used fluently", function() {
|
||||||
write("a.js", `var b = require("./b").toString()`)
|
write("a.js", 'var b = require("./b").toString()')
|
||||||
write("b.js", `module.exports = []`)
|
write("b.js", "module.exports = []")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar _0 = []\nvar b = _0.toString()\n}`)
|
o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0.toString()\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if used fluently w/ multiline", function() {
|
o("works if used fluently w/ multiline", function() {
|
||||||
write("a.js", `var b = require("./b")\n\t.toString()`)
|
write("a.js", 'var b = require("./b")\n\t.toString()')
|
||||||
write("b.js", `module.exports = []`)
|
write("b.js", "module.exports = []")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}`)
|
o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0\n\t.toString()\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if used w/ curry", function() {
|
o("works if used w/ curry", function() {
|
||||||
write("a.js", `var b = require("./b")()`)
|
write("a.js", 'var b = require("./b")()')
|
||||||
write("b.js", `module.exports = function() {}`)
|
write("b.js", "module.exports = function() {}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar _0 = function() {}\nvar b = _0()\n}`)
|
o(read("out.js")).equals("new function() {\nvar _0 = function() {}\nvar b = _0()\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if used w/ curry w/ multiline", function() {
|
o("works if used w/ curry w/ multiline", function() {
|
||||||
write("a.js", `var b = require("./b")\n()`)
|
write("a.js", 'var b = require("./b")\n()')
|
||||||
write("b.js", `module.exports = function() {}`)
|
write("b.js", "module.exports = function() {}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar _0 = function() {}\nvar b = _0\n()\n}`)
|
o(read("out.js")).equals("new function() {\nvar _0 = function() {}\nvar b = _0\n()\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if used fluently in one place and not in another", function() {
|
o("works if used fluently in one place and not in another", function() {
|
||||||
write("a.js", `var b = require("./b").toString()\nvar c = require("./c")`)
|
write("a.js", 'var b = require("./b").toString()\nvar c = require("./c")')
|
||||||
write("b.js", `module.exports = []`)
|
write("b.js", "module.exports = []")
|
||||||
write("c.js", `var b = require("./b")\nmodule.exports = function() {return b}`)
|
write("c.js", 'var b = require("./b")\nmodule.exports = function() {return b}')
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}`)
|
o(read("out.js")).equals("new function() {\nvar _0 = []\nvar b = _0.toString()\nvar b0 = _0\nvar c = function() {return b0}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -196,12 +198,12 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if used in sequence", function() {
|
o("works if used in sequence", function() {
|
||||||
write("a.js", `var b = require("./b"), c = require("./c")`)
|
write("a.js", 'var b = require("./b"), c = require("./c")')
|
||||||
write("b.js", `module.exports = 1`)
|
write("b.js", "module.exports = 1")
|
||||||
write("c.js", `var x\nmodule.exports = 2`)
|
write("c.js", "var x\nmodule.exports = 2")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b = 1\nvar x\nvar c = 2\n}`)
|
o(read("out.js")).equals("new function() {\nvar b = 1\nvar x\nvar c = 2\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -209,12 +211,12 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if assigned to property", function() {
|
o("works if assigned to property", function() {
|
||||||
write("a.js", `var x = {}\nx.b = require("./b")\nx.c = require("./c")`)
|
write("a.js", 'var x = {}\nx.b = require("./b")\nx.c = require("./c")')
|
||||||
write("b.js", `var bb = 1\nmodule.exports = bb`)
|
write("b.js", "var bb = 1\nmodule.exports = bb")
|
||||||
write("c.js", `var cc = 2\nmodule.exports = cc`)
|
write("c.js", "var cc = 2\nmodule.exports = cc")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}`)
|
o(read("out.js")).equals("new function() {\nvar x = {}\nvar bb = 1\nx.b = bb\nvar cc = 2\nx.c = cc\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -222,12 +224,12 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if assigned to property using bracket notation", function() {
|
o("works if assigned to property using bracket notation", function() {
|
||||||
write("a.js", `var x = {}\nx["b"] = require("./b")\nx["c"] = require("./c")`)
|
write("a.js", 'var x = {}\nx["b"] = require("./b")\nx["c"] = require("./c")')
|
||||||
write("b.js", `var bb = 1\nmodule.exports = bb`)
|
write("b.js", "var bb = 1\nmodule.exports = bb")
|
||||||
write("c.js", `var cc = 2\nmodule.exports = cc`)
|
write("c.js", "var cc = 2\nmodule.exports = cc")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}`)
|
o(read("out.js")).equals('new function() {\nvar x = {}\nvar bb = 1\nx["b"] = bb\nvar cc = 2\nx["c"] = cc\n}')
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -235,23 +237,23 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if collision", function() {
|
o("works if collision", function() {
|
||||||
write("a.js", `var b = require("./b")`)
|
write("a.js", 'var b = require("./b")')
|
||||||
write("b.js", `var b = 1\nmodule.exports = 2`)
|
write("b.js", "var b = 1\nmodule.exports = 2")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b0 = 1\nvar b = 2\n}`)
|
o(read("out.js")).equals("new function() {\nvar b0 = 1\nvar b = 2\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if multiple aliases", function() {
|
o("works if multiple aliases", function() {
|
||||||
write("a.js", `var b = require("./b")\n`)
|
write("a.js", 'var b = require("./b")\n')
|
||||||
write("b.js", `var b = require("./c")\nb.x = 1\nmodule.exports = b`)
|
write("b.js", 'var b = require("./c")\nb.x = 1\nmodule.exports = b')
|
||||||
write("c.js", `var b = {}\nmodule.exports = b`)
|
write("c.js", "var b = {}\nmodule.exports = b")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b = {}\nb.x = 1\n}`)
|
o(read("out.js")).equals("new function() {\nvar b = {}\nb.x = 1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -259,13 +261,13 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if multiple collision", function() {
|
o("works if multiple collision", function() {
|
||||||
write("a.js", `var b = require("./b")\nvar c = require("./c")\nvar d = require("./d")`)
|
write("a.js", 'var b = require("./b")\nvar c = require("./c")\nvar d = require("./d")')
|
||||||
write("b.js", `var a = 1\nmodule.exports = a`)
|
write("b.js", "var a = 1\nmodule.exports = a")
|
||||||
write("c.js", `var a = 2\nmodule.exports = a`)
|
write("c.js", "var a = 2\nmodule.exports = a")
|
||||||
write("d.js", `var a = 3\nmodule.exports = a`)
|
write("d.js", "var a = 3\nmodule.exports = a")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}`)
|
o(read("out.js")).equals("new function() {\nvar a = 1\nvar b = a\nvar a0 = 2\nvar c = a0\nvar a1 = 3\nvar d = a1\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -274,37 +276,37 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("works if included multiple times", function() {
|
o("works if included multiple times", function() {
|
||||||
write("a.js", `module.exports = 123`)
|
write("a.js", "module.exports = 123")
|
||||||
write("b.js", `var a = require("./a").toString()\nmodule.exports = a`)
|
write("b.js", 'var a = require("./a").toString()\nmodule.exports = a')
|
||||||
write("c.js", `var a = require("./a").toString()\nvar b = require("./b")`)
|
write("c.js", 'var a = require("./a").toString()\nvar b = require("./b")')
|
||||||
bundle(ns + "c.js", ns + "out.js")
|
bundle(ns + "c.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}`)
|
o(read("out.js")).equals("new function() {\nvar _0 = 123\nvar a = _0.toString()\nvar a0 = _0.toString()\nvar b = a0\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("c.js")
|
remove("c.js")
|
||||||
})
|
})
|
||||||
o("works if included multiple times reverse", function() {
|
o("works if included multiple times reverse", function() {
|
||||||
write("a.js", `module.exports = 123`)
|
write("a.js", "module.exports = 123")
|
||||||
write("b.js", `var a = require("./a").toString()\nmodule.exports = a`)
|
write("b.js", 'var a = require("./a").toString()\nmodule.exports = a')
|
||||||
write("c.js", `var b = require("./b")\nvar a = require("./a").toString()`)
|
write("c.js", 'var b = require("./b")\nvar a = require("./a").toString()')
|
||||||
bundle(ns + "c.js", ns + "out.js")
|
bundle(ns + "c.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}`)
|
o(read("out.js")).equals("new function() {\nvar _0 = 123\nvar a0 = _0.toString()\nvar b = a0\nvar a = _0.toString()\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("c.js")
|
remove("c.js")
|
||||||
})
|
})
|
||||||
o("reuses binding if possible", function() {
|
o("reuses binding if possible", function() {
|
||||||
write("a.js", `var b = require("./b")\nvar c = require("./c")`)
|
write("a.js", 'var b = require("./b")\nvar c = require("./c")')
|
||||||
write("b.js", `var d = require("./d")\nmodule.exports = function() {return d + 1}`)
|
write("b.js", 'var d = require("./d")\nmodule.exports = function() {return d + 1}')
|
||||||
write("c.js", `var d = require("./d")\nmodule.exports = function() {return d + 2}`)
|
write("c.js", 'var d = require("./d")\nmodule.exports = function() {return d + 2}')
|
||||||
write("d.js", `module.exports = 1`)
|
write("d.js", "module.exports = 1")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}`)
|
o(read("out.js")).equals("new function() {\nvar d = 1\nvar b = function() {return d + 1}\nvar c = function() {return d + 2}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -313,45 +315,45 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("disambiguates conflicts if imported collides with itself", function() {
|
o("disambiguates conflicts if imported collides with itself", function() {
|
||||||
write("a.js", `var b = require("./b")`)
|
write("a.js", 'var b = require("./b")')
|
||||||
write("b.js", `var b = 1\nmodule.exports = function() {return b}`)
|
write("b.js", "var b = 1\nmodule.exports = function() {return b}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b0 = 1\nvar b = function() {return b0}\n}`)
|
o(read("out.js")).equals("new function() {\nvar b0 = 1\nvar b = function() {return b0}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("disambiguates conflicts if imported collides with something else", function() {
|
o("disambiguates conflicts if imported collides with something else", function() {
|
||||||
write("a.js", `var a = 1\nvar b = require("./b")`)
|
write("a.js", 'var a = 1\nvar b = require("./b")')
|
||||||
write("b.js", `var a = 2\nmodule.exports = function() {return a}`)
|
write("b.js", "var a = 2\nmodule.exports = function() {return a}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}`)
|
o(read("out.js")).equals("new function() {\nvar a = 1\nvar a0 = 2\nvar b = function() {return a0}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("disambiguates conflicts if imported collides with function declaration", function() {
|
o("disambiguates conflicts if imported collides with function declaration", function() {
|
||||||
write("a.js", `function a() {}\nvar b = require("./b")`)
|
write("a.js", 'function a() {}\nvar b = require("./b")')
|
||||||
write("b.js", `var a = 2\nmodule.exports = function() {return a}`)
|
write("b.js", "var a = 2\nmodule.exports = function() {return a}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}`)
|
o(read("out.js")).equals("new function() {\nfunction a() {}\nvar a0 = 2\nvar b = function() {return a0}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("disambiguates conflicts if imported collides with another module's private", function() {
|
o("disambiguates conflicts if imported collides with another module's private", function() {
|
||||||
write("a.js", `var b = require("./b")\nvar c = require("./c")`)
|
write("a.js", 'var b = require("./b")\nvar c = require("./c")')
|
||||||
write("b.js", `var a = 1\nmodule.exports = function() {return a}`)
|
write("b.js", "var a = 1\nmodule.exports = function() {return a}")
|
||||||
write("c.js", `var a = 2\nmodule.exports = function() {return a}`)
|
write("c.js", "var a = 2\nmodule.exports = function() {return a}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}`)
|
o(read("out.js")).equals("new function() {\nvar a = 1\nvar b = function() {return a}\nvar a0 = 2\nvar c = function() {return a0}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
@ -359,22 +361,22 @@ o.spec("bundler", function() {
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("does not mess up strings", function() {
|
o("does not mess up strings", function() {
|
||||||
write("a.js", `var b = require("./b")`)
|
write("a.js", 'var b = require("./b")')
|
||||||
write("b.js", `var b = "b b b \\\" b"\nmodule.exports = function() {return b}`)
|
write("b.js", 'var b = "b b b \\" b"\nmodule.exports = function() {return b}')
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b0 = "b b b \\\" b"\nvar b = function() {return b0}\n}`)
|
o(read("out.js")).equals('new function() {\nvar b0 = "b b b \\" b"\nvar b = function() {return b0}\n}')
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
remove("out.js")
|
remove("out.js")
|
||||||
})
|
})
|
||||||
o("does not mess up properties", function() {
|
o("does not mess up properties", function() {
|
||||||
write("a.js", `var b = require("./b")`)
|
write("a.js", 'var b = require("./b")')
|
||||||
write("b.js", `var b = {b: 1}\nmodule.exports = function() {return b.b}`)
|
write("b.js", "var b = {b: 1}\nmodule.exports = function() {return b.b}")
|
||||||
bundle(ns + "a.js", ns + "out.js")
|
bundle(ns + "a.js", ns + "out.js")
|
||||||
|
|
||||||
o(read("out.js")).equals(`new function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}`)
|
o(read("out.js")).equals("new function() {\nvar b0 = {b: 1}\nvar b = function() {return b0.b}\n}")
|
||||||
|
|
||||||
remove("a.js")
|
remove("a.js")
|
||||||
remove("b.js")
|
remove("b.js")
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var fs = require("fs")
|
var fs = require("fs")
|
||||||
var path = require("path")
|
var path = require("path")
|
||||||
var marked = require("marked")
|
var marked = require("marked")
|
||||||
var layout = fs.readFileSync("./docs/layout.html", "utf-8")
|
var layout = fs.readFileSync("./docs/layout.html", "utf-8")
|
||||||
var version = JSON.parse(fs.readFileSync("./package.json", "utf-8")).version
|
var version = JSON.parse(fs.readFileSync("./package.json", "utf-8")).version
|
||||||
try {fs.mkdirSync("../mithril")} catch (e) {}
|
try {fs.mkdirSync("../mithril")} catch (e) {/* ignore */}
|
||||||
try {fs.mkdirSync("../mithril/archive")} catch (e) {}
|
try {fs.mkdirSync("../mithril/archive")} catch (e) {/* ignore */}
|
||||||
try {fs.mkdirSync("../mithril/archive/v" + version)} catch (e) {}
|
try {fs.mkdirSync("../mithril/archive/v" + version)} catch (e) {/* ignore */}
|
||||||
try {fs.mkdirSync("../mithril/archive/v" + version + "/lib")} catch (e) {}
|
try {fs.mkdirSync("../mithril/archive/v" + version + "/lib")} catch (e) {/* ignore */}
|
||||||
try {fs.mkdirSync("../mithril/archive/v" + version + "/lib/prism")} catch (e) {}
|
try {fs.mkdirSync("../mithril/archive/v" + version + "/lib/prism")} catch (e) {/* ignore */}
|
||||||
try {fs.mkdirSync("../mithril/lib")} catch (e) {}
|
try {fs.mkdirSync("../mithril/lib")} catch (e) {/* ignore */}
|
||||||
try {fs.mkdirSync("../mithril/lib/prism")} catch (e) {}
|
try {fs.mkdirSync("../mithril/lib/prism")} catch (e) {/* ignore */}
|
||||||
|
|
||||||
var guides = fs.readFileSync("docs/guides.md", "utf-8")
|
var guides = fs.readFileSync("docs/guides.md", "utf-8")
|
||||||
var methods = fs.readFileSync("docs/methods.md", "utf-8")
|
var methods = fs.readFileSync("docs/methods.md", "utf-8")
|
||||||
|
|
@ -33,7 +35,7 @@ function generate(pathname) {
|
||||||
.replace(/`((?:\S| -> |, )+)(\|)(\S+)`/gim, function(match, a, b, c) { // fix pipes in code tags
|
.replace(/`((?:\S| -> |, )+)(\|)(\S+)`/gim, function(match, a, b, c) { // fix pipes in code tags
|
||||||
return "<code>" + (a + b + c).replace(/\|/g, "|") + "</code>"
|
return "<code>" + (a + b + c).replace(/\|/g, "|") + "</code>"
|
||||||
})
|
})
|
||||||
.replace(/(^# .+?(?:\r?\n){2,}?)(?:(-(?:.|\r|\n)+?)((?:\r?\n){2,})|)/m, function(match, title, nav, space) { // inject menu
|
.replace(/(^# .+?(?:\r?\n){2,}?)(?:(-(?:.|\r|\n)+?)((?:\r?\n){2,})|)/m, function(match, title, nav) { // inject menu
|
||||||
var file = path.basename(pathname)
|
var file = path.basename(pathname)
|
||||||
var link = new RegExp("([ \t]*)(- )(\\[.+?\\]\\(" + file + "\\))")
|
var link = new RegExp("([ \t]*)(- )(\\[.+?\\]\\(" + file + "\\))")
|
||||||
var replace = function(match, space, li, link) {
|
var replace = function(match, space, li, link) {
|
||||||
|
|
@ -53,7 +55,7 @@ function generate(pathname) {
|
||||||
.replace(/\[version\]/, version) // update version
|
.replace(/\[version\]/, version) // update version
|
||||||
.replace(/\[body\]/, markedHtml)
|
.replace(/\[body\]/, markedHtml)
|
||||||
.replace(/<h(.) id="([^"]+?)">(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors
|
.replace(/<h(.) id="([^"]+?)">(.+?)<\/h.>/gim, function(match, n, id, text) { // fix anchors
|
||||||
return "<h" + n + " id=\"" + text.toLowerCase().replace(/<(\/?)code>/g, "").replace(/<a.*?>.+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-") + "\">" + text + "</h" + n + ">"
|
return "<h" + n + ' id="' + text.toLowerCase().replace(/<(\/?)code>/g, "").replace(/<a.*?>.+?<\/a>/g, "").replace(/\.|\[|\]|"|\/|\(|\)/g, "").replace(/\s/g, "-") + '">' + text + "</h" + n + ">"
|
||||||
})
|
})
|
||||||
fs.writeFileSync("../mithril/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")
|
fs.writeFileSync("../mithril/archive/v" + version + "/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")
|
||||||
fs.writeFileSync("../mithril/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")
|
fs.writeFileSync("../mithril/" + outputFilename.replace(/^docs\//, ""), html, "utf-8")
|
||||||
|
|
|
||||||
11
docs/lint.js
11
docs/lint.js
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var fs = require("fs")
|
var fs = require("fs")
|
||||||
var path = require("path")
|
var path = require("path")
|
||||||
|
|
@ -100,11 +101,11 @@ function ensureLinkIsValid(file, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initMocks() {
|
function initMocks() {
|
||||||
global.window = require("../test-utils/browserMock")()
|
global.window = require("../test-utils/browserMock")() // eslint-disable-line global-require
|
||||||
global.document = window.document
|
global.document = window.document
|
||||||
global.m = require("../index")
|
global.m = require("../index") // eslint-disable-line global-require
|
||||||
global.o = require("../ospec/ospec")
|
global.o = require("../ospec/ospec") // eslint-disable-line global-require
|
||||||
global.stream = require("../stream")
|
global.stream = require("../stream") // eslint-disable-line global-require
|
||||||
global.alert = function() {}
|
global.alert = function() {}
|
||||||
|
|
||||||
//routes consumed by request.md
|
//routes consumed by request.md
|
||||||
|
|
@ -121,7 +122,7 @@ function initMocks() {
|
||||||
"GET /api/v1/todos": function() {
|
"GET /api/v1/todos": function() {
|
||||||
return {status: 200, responseText: JSON.stringify([])}
|
return {status: 200, responseText: JSON.stringify([])}
|
||||||
},
|
},
|
||||||
"PUT /api/v1/users/1": function() {
|
"PUT /api/v1/users/1": function(request) {
|
||||||
return {status: 200, responseText: request.query.callback ? request.query.callback + "([])" : "[]"}
|
return {status: 200, responseText: request.query.callback ? request.query.callback + "([])" : "[]"}
|
||||||
},
|
},
|
||||||
"POST /api/v1/upload": function() {
|
"POST /api/v1/upload": function() {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var hyperscript = require("./render/hyperscript")
|
var hyperscript = require("./render/hyperscript")
|
||||||
|
|
||||||
hyperscript.trust = require("./render/trust")
|
hyperscript.trust = require("./render/trust")
|
||||||
|
|
|
||||||
2
mount.js
2
mount.js
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var redrawService = require("./redraw")
|
var redrawService = require("./redraw")
|
||||||
|
|
||||||
module.exports = require("./api/mount")(redrawService)
|
module.exports = require("./api/mount")(redrawService)
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var fs = require("fs")
|
var fs = require("fs")
|
||||||
var path = require("path")
|
var path = require("path")
|
||||||
|
|
@ -31,9 +32,9 @@ function traverseDirectory(pathname, callback) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
traverseDirectory(".", function(pathname, stat, children) {
|
traverseDirectory(".", function(pathname) {
|
||||||
if (pathname.match(/(?:^|\/)tests\/.*\.js$/)) {
|
if (pathname.match(/(?:^|\/)tests\/.*\.js$/)) {
|
||||||
require(path.normalize(process.cwd()) + "/" + pathname)
|
require(path.normalize(process.cwd()) + "/" + pathname) // eslint-disable-line global-require
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(o.run)
|
.then(o.run)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-bitwise, no-process-exit */
|
||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
module.exports = new function init() {
|
module.exports = new function init() {
|
||||||
|
|
@ -122,7 +123,7 @@ module.exports = new function init() {
|
||||||
function unique(subject) {
|
function unique(subject) {
|
||||||
if (hasOwn.call(ctx, subject)) {
|
if (hasOwn.call(ctx, subject)) {
|
||||||
console.warn("A test or a spec named `" + subject + "` was already defined")
|
console.warn("A test or a spec named `" + subject + "` was already defined")
|
||||||
while (hasOwn.call(ctx, subject)) subject += '*'
|
while (hasOwn.call(ctx, subject)) subject += "*"
|
||||||
}
|
}
|
||||||
return subject
|
return subject
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@ o.spec("ospec", function() {
|
||||||
o.beforeEach(function() {b = 1})
|
o.beforeEach(function() {b = 1})
|
||||||
o.afterEach(function() {b = 0})
|
o.afterEach(function() {b = 0})
|
||||||
|
|
||||||
try {o('illegal assertion')} catch (e) {illegalAssertionThrows = true}
|
try {o("illegal assertion")} catch (e) {illegalAssertionThrows = true}
|
||||||
|
|
||||||
o("assertions", function() {
|
o("assertions", function() {
|
||||||
var nestedTestDeclarationThrows = false
|
var nestedTestDeclarationThrows = false
|
||||||
try {o('illegal nested test', function(){})} catch (e) {nestedTestDeclarationThrows = true}
|
try {o("illegal nested test", function(){})} catch (e) {nestedTestDeclarationThrows = true}
|
||||||
|
|
||||||
o(illegalAssertionThrows).equals(true)
|
o(illegalAssertionThrows).equals(true)
|
||||||
o(nestedTestDeclarationThrows).equals(true)
|
o(nestedTestDeclarationThrows).equals(true)
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ o.spec("promise", function() {
|
||||||
o.spec("resolve", function() {
|
o.spec("resolve", function() {
|
||||||
o("resolves once", function(done) {
|
o("resolves once", function(done) {
|
||||||
var callCount = 0
|
var callCount = 0
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve) {
|
||||||
resolve(1)
|
resolve(1)
|
||||||
resolve(2)
|
resolve(2)
|
||||||
callAsync(function() {resolve(3)})
|
callAsync(function() {resolve(3)})
|
||||||
|
|
@ -89,7 +89,7 @@ o.spec("promise", function() {
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
||||||
state = 1
|
state = 1
|
||||||
promise.then(function(value) {
|
promise.then(function() {
|
||||||
o(state).equals(2)
|
o(state).equals(2)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
@ -104,7 +104,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("resolves asynchronously via executor", function(done) {
|
o("resolves asynchronously via executor", function(done) {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve) {
|
||||||
callAsync(function() {resolve(1)})
|
callAsync(function() {resolve(1)})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -185,7 +185,7 @@ o.spec("promise", function() {
|
||||||
var promise = Promise.reject()
|
var promise = Promise.reject()
|
||||||
|
|
||||||
state = 1
|
state = 1
|
||||||
promise.then(null, function(value) {
|
promise.then(null, function() {
|
||||||
o(state).equals(2)
|
o(state).equals(2)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
@ -232,7 +232,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("rejects via executor on error", function(done) {
|
o("rejects via executor on error", function(done) {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function() {
|
||||||
throw 1
|
throw 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -281,7 +281,7 @@ o.spec("promise", function() {
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
o("absorbs resolved promise in executor resolve", function(done) {
|
o("absorbs resolved promise in executor resolve", function(done) {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve) {
|
||||||
var p = Promise.resolve(1)
|
var p = Promise.resolve(1)
|
||||||
resolve(p)
|
resolve(p)
|
||||||
})
|
})
|
||||||
|
|
@ -310,7 +310,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("absorbs rejected promise in executor resolve", function(done) {
|
o("absorbs rejected promise in executor resolve", function(done) {
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve) {
|
||||||
resolve(Promise.reject(1))
|
resolve(Promise.reject(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -330,7 +330,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("absorbs pending promise that resolves via static resolver", function(done) {
|
o("absorbs pending promise that resolves via static resolver", function(done) {
|
||||||
var pending = new Promise(function(resolve, reject) {
|
var pending = new Promise(function(resolve) {
|
||||||
setTimeout(function() {resolve(1)}, 10)
|
setTimeout(function() {resolve(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = Promise.resolve(pending)
|
var promise = Promise.resolve(pending)
|
||||||
|
|
@ -341,10 +341,10 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("absorbs pending promise that resolves in executor resolve", function(done) {
|
o("absorbs pending promise that resolves in executor resolve", function(done) {
|
||||||
var pending = new Promise(function(resolve, reject) {
|
var pending = new Promise(function(resolve) {
|
||||||
setTimeout(function() {resolve(1)}, 10)
|
setTimeout(function() {resolve(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve) {
|
||||||
resolve(pending)
|
resolve(pending)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -354,7 +354,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("absorbs pending promise that resolves on fulfillment", function(done) {
|
o("absorbs pending promise that resolves on fulfillment", function(done) {
|
||||||
var pending = new Promise(function(resolve, reject) {
|
var pending = new Promise(function(resolve) {
|
||||||
setTimeout(function() {resolve(1)}, 10)
|
setTimeout(function() {resolve(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = Promise.resolve()
|
var promise = Promise.resolve()
|
||||||
|
|
@ -381,7 +381,7 @@ o.spec("promise", function() {
|
||||||
var pending = new Promise(function(resolve, reject) {
|
var pending = new Promise(function(resolve, reject) {
|
||||||
setTimeout(function() {reject(1)}, 10)
|
setTimeout(function() {reject(1)}, 10)
|
||||||
})
|
})
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve) {
|
||||||
resolve(pending)
|
resolve(pending)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -521,7 +521,7 @@ o.spec("promise", function() {
|
||||||
o.spec("race", function() {
|
o.spec("race", function() {
|
||||||
o("resolves to first resolved", function(done) {
|
o("resolves to first resolved", function(done) {
|
||||||
var a = Promise.resolve(1)
|
var a = Promise.resolve(1)
|
||||||
var b = new Promise(function(resolve, reject) {
|
var b = new Promise(function(resolve) {
|
||||||
callAsync(function() {resolve(2)})
|
callAsync(function() {resolve(2)})
|
||||||
})
|
})
|
||||||
Promise.race([a, b]).then(function(value) {
|
Promise.race([a, b]).then(function(value) {
|
||||||
|
|
@ -542,7 +542,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
o.spec("all", function() {
|
o.spec("all", function() {
|
||||||
o("resolves to array", function(done) {
|
o("resolves to array", function(done) {
|
||||||
var a = new Promise(function(resolve, reject) {
|
var a = new Promise(function(resolve) {
|
||||||
callAsync(function() {resolve(1)})
|
callAsync(function() {resolve(1)})
|
||||||
})
|
})
|
||||||
var b = Promise.resolve(2)
|
var b = Promise.resolve(2)
|
||||||
|
|
@ -558,7 +558,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("resolves non-promise to itself", function(done) {
|
o("resolves non-promise to itself", function(done) {
|
||||||
var a = new Promise(function(resolve, reject) {
|
var a = new Promise(function(resolve) {
|
||||||
callAsync(function() {resolve(1)})
|
callAsync(function() {resolve(1)})
|
||||||
})
|
})
|
||||||
var b = Promise.resolve(2)
|
var b = Promise.resolve(2)
|
||||||
|
|
@ -595,7 +595,7 @@ o.spec("promise", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
promise.then(function(value) {
|
promise.then(function() {
|
||||||
o(readCount).equals(1)
|
o(readCount).equals(1)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
module.exports = require("./api/redraw")(window)
|
module.exports = require("./api/redraw")(window)
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
module.exports = require("./render/render")(window)
|
module.exports = require("./render/render")(window)
|
||||||
|
|
@ -15,16 +15,16 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
o("when vnode is customElement, custom setAttribute called", function(){
|
o("when vnode is customElement, custom setAttribute called", function(){
|
||||||
|
|
||||||
var normal = [
|
var normal = [
|
||||||
{ tag: "input", attrs: { value: 'hello' } },
|
{tag: "input", attrs: {value: "hello"}},
|
||||||
{ tag: "input", attrs: { value: 'hello' } },
|
{tag: "input", attrs: {value: "hello"}},
|
||||||
{ tag: "input", attrs: { value: 'hello' } }
|
{tag: "input", attrs: {value: "hello"}}
|
||||||
]
|
]
|
||||||
|
|
||||||
var custom = [
|
var custom = [
|
||||||
{ tag: "custom-element", attrs: { custom: 'x' } },
|
{tag: "custom-element", attrs: {custom: "x"}},
|
||||||
{ tag: "input", attrs: { is: 'something-special', custom: 'x' } },
|
{tag: "input", attrs: {is: "something-special", custom: "x"}},
|
||||||
{ tag: "custom-element", attrs: { is: 'something-special', custom: 'x' } }
|
{tag: "custom-element", attrs: {is: "something-special", custom: "x"}}
|
||||||
]
|
]
|
||||||
|
|
||||||
var view = normal.concat(custom)
|
var view = normal.concat(custom)
|
||||||
|
|
@ -44,7 +44,7 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
render(root, view)
|
render(root, view)
|
||||||
|
|
||||||
o(spy.callCount).equals( custom.length )
|
o(spy.callCount).equals(custom.length)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
@ -133,7 +133,7 @@ o.spec("attributes", function() {
|
||||||
})
|
})
|
||||||
o.spec("contenteditable throws on untrusted children", function() {
|
o.spec("contenteditable throws on untrusted children", function() {
|
||||||
o("including text nodes", function() {
|
o("including text nodes", function() {
|
||||||
var div = {tag: "div", attrs: {contenteditable: true}, text: ''}
|
var div = {tag: "div", attrs: {contenteditable: true}, text: ""}
|
||||||
var succeeded = false
|
var succeeded = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -141,7 +141,7 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
succeeded = true
|
succeeded = true
|
||||||
}
|
}
|
||||||
catch(e){}
|
catch(e){/* ignore */}
|
||||||
|
|
||||||
o(succeeded).equals(false)
|
o(succeeded).equals(false)
|
||||||
})
|
})
|
||||||
|
|
@ -154,7 +154,7 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
succeeded = true
|
succeeded = true
|
||||||
}
|
}
|
||||||
catch(e){}
|
catch(e){/* ignore */}
|
||||||
|
|
||||||
o(succeeded).equals(false)
|
o(succeeded).equals(false)
|
||||||
})
|
})
|
||||||
|
|
@ -167,7 +167,7 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
succeeded = true
|
succeeded = true
|
||||||
}
|
}
|
||||||
catch(e){}
|
catch(e){/* ignore */}
|
||||||
|
|
||||||
o(succeeded).equals(true)
|
o(succeeded).equals(true)
|
||||||
})
|
})
|
||||||
|
|
@ -180,7 +180,7 @@ o.spec("attributes", function() {
|
||||||
|
|
||||||
succeeded = true
|
succeeded = true
|
||||||
}
|
}
|
||||||
catch(e){}
|
catch(e){/* ignore */}
|
||||||
|
|
||||||
o(succeeded).equals(true)
|
o(succeeded).equals(true)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ o.spec("component", function() {
|
||||||
o("updates root from null", function() {
|
o("updates root from null", function() {
|
||||||
var visible = false
|
var visible = false
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return visible ? {tag: "div"} : null
|
return visible ? {tag: "div"} : null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -76,7 +76,7 @@ o.spec("component", function() {
|
||||||
o("updates root from primitive", function() {
|
o("updates root from primitive", function() {
|
||||||
var visible = false
|
var visible = false
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return visible ? {tag: "div"} : false
|
return visible ? {tag: "div"} : false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -89,7 +89,7 @@ o.spec("component", function() {
|
||||||
o("updates root to null", function() {
|
o("updates root to null", function() {
|
||||||
var visible = true
|
var visible = true
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return visible ? {tag: "div"} : null
|
return visible ? {tag: "div"} : null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -102,7 +102,7 @@ o.spec("component", function() {
|
||||||
o("updates root to primitive", function() {
|
o("updates root to primitive", function() {
|
||||||
var visible = true
|
var visible = true
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return visible ? {tag: "div"} : false
|
return visible ? {tag: "div"} : false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -114,7 +114,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("updates root from null to null", function() {
|
o("updates root from null to null", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -125,7 +125,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("removes", function() {
|
o("removes", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return {tag: "div"}
|
return {tag: "div"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -138,7 +138,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("svg works when creating across component boundary", function() {
|
o("svg works when creating across component boundary", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return {tag: "g"}
|
return {tag: "g"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -148,7 +148,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("svg works when updating across component boundary", function() {
|
o("svg works when updating across component boundary", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return {tag: "g"}
|
return {tag: "g"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -161,7 +161,7 @@ o.spec("component", function() {
|
||||||
o.spec("return value", function() {
|
o.spec("return value", function() {
|
||||||
o("can return fragments", function() {
|
o("can return fragments", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return [
|
return [
|
||||||
{tag: "label"},
|
{tag: "label"},
|
||||||
{tag: "input"},
|
{tag: "input"},
|
||||||
|
|
@ -176,7 +176,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return string", function() {
|
o("can return string", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return "a"
|
return "a"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -187,7 +187,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return falsy string", function() {
|
o("can return falsy string", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -198,7 +198,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return number", function() {
|
o("can return number", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -209,7 +209,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return falsy number", function() {
|
o("can return falsy number", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -220,7 +220,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return boolean", function() {
|
o("can return boolean", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -231,7 +231,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return falsy boolean", function() {
|
o("can return falsy boolean", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -242,7 +242,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return null", function() {
|
o("can return null", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -252,7 +252,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can return undefined", function() {
|
o("can return undefined", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -278,7 +278,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can update when returning fragments", function() {
|
o("can update when returning fragments", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return [
|
return [
|
||||||
{tag: "label"},
|
{tag: "label"},
|
||||||
{tag: "input"},
|
{tag: "input"},
|
||||||
|
|
@ -294,7 +294,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can update when returning primitive", function() {
|
o("can update when returning primitive", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return "a"
|
return "a"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -306,7 +306,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can update when returning null", function() {
|
o("can update when returning null", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -317,7 +317,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can remove when returning fragments", function() {
|
o("can remove when returning fragments", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return [
|
return [
|
||||||
{tag: "label"},
|
{tag: "label"},
|
||||||
{tag: "input"},
|
{tag: "input"},
|
||||||
|
|
@ -334,7 +334,7 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o("can remove when returning primitive", function() {
|
o("can remove when returning primitive", function() {
|
||||||
var component = createComponent({
|
var component = createComponent({
|
||||||
view: function(vnode) {
|
view: function() {
|
||||||
return "a"
|
return "a"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -403,7 +403,7 @@ o.spec("component", function() {
|
||||||
viewCalled = true
|
viewCalled = true
|
||||||
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
return [{tag: "div", attrs: {id: "a"}, text: "b"}]
|
||||||
},
|
},
|
||||||
oninit: function(vnode) {
|
oninit: function() {
|
||||||
o(viewCalled).equals(false)
|
o(viewCalled).equals(false)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -646,7 +646,6 @@ o.spec("component", function() {
|
||||||
return {tag: "div"}
|
return {tag: "div"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var update = o.spy()
|
|
||||||
var vnode = {tag: component, key: 1}
|
var vnode = {tag: component, key: 1}
|
||||||
var updated = {tag: component, key: 1}
|
var updated = {tag: component, key: 1}
|
||||||
|
|
||||||
|
|
@ -659,7 +658,6 @@ o.spec("component", function() {
|
||||||
})
|
})
|
||||||
o.spec("state", function() {
|
o.spec("state", function() {
|
||||||
o("initializes state", function() {
|
o("initializes state", function() {
|
||||||
var called = 0
|
|
||||||
var data = {a: 1}
|
var data = {a: 1}
|
||||||
var component = createComponent(createComponent({
|
var component = createComponent(createComponent({
|
||||||
data: data,
|
data: data,
|
||||||
|
|
@ -676,7 +674,6 @@ o.spec("component", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
o('state "copy" is shallow', function() {
|
o('state "copy" is shallow', function() {
|
||||||
var called = 0
|
|
||||||
var body = {a: 1}
|
var body = {a: 1}
|
||||||
var data = [body]
|
var data = [body]
|
||||||
var component = createComponent(createComponent({
|
var component = createComponent(createComponent({
|
||||||
|
|
@ -701,7 +698,6 @@ o.spec("component", function() {
|
||||||
|
|
||||||
o.spec("POJO state", function() {
|
o.spec("POJO state", function() {
|
||||||
o("copies state", function() {
|
o("copies state", function() {
|
||||||
var called = 0
|
|
||||||
var data = {a: 1}
|
var data = {a: 1}
|
||||||
var component = {
|
var component = {
|
||||||
data: data,
|
data: data,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-script-url */
|
||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
var o = require("../../ospec/ospec")
|
var o = require("../../ospec/ospec")
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var o = require("../../ospec/ospec")
|
var o = require("../../ospec/ospec")
|
||||||
var m = require("../../render/hyperscript")
|
var m = require("../../render/hyperscript")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ o.spec("onbeforeremove", function() {
|
||||||
|
|
||||||
o("does not call onbeforeremove when creating", function() {
|
o("does not call onbeforeremove when creating", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var update = o.spy()
|
|
||||||
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
var vnode = {tag: "div", attrs: {onbeforeremove: create}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
@ -142,7 +141,7 @@ o.spec("onbeforeremove", function() {
|
||||||
o(vnode.dom.attributes["onbeforeremove"]).equals(undefined)
|
o(vnode.dom.attributes["onbeforeremove"]).equals(undefined)
|
||||||
})
|
})
|
||||||
o("does not recycle when there's an onbeforeremove", function() {
|
o("does not recycle when there's an onbeforeremove", function() {
|
||||||
var remove = function(vnode) {}
|
var remove = function() {}
|
||||||
var vnode = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
var vnode = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||||
var updated = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
var updated = {tag: "div", key: 1, attrs: {onbeforeremove: remove}}
|
||||||
|
|
||||||
|
|
@ -153,7 +152,7 @@ o.spec("onbeforeremove", function() {
|
||||||
o(vnode.dom).notEquals(updated.dom)
|
o(vnode.dom).notEquals(updated.dom)
|
||||||
})
|
})
|
||||||
o("does not leave elements out of order during removal", function(done) {
|
o("does not leave elements out of order during removal", function(done) {
|
||||||
var remove = function(vnode) {return Promise.resolve()}
|
var remove = function() {return Promise.resolve()}
|
||||||
var vnodes = [{tag: "div", key: 1, attrs: {onbeforeremove: remove}, text: "1"}, {tag: "div", key: 2, attrs: {onbeforeremove: remove}, text: "2"}]
|
var vnodes = [{tag: "div", key: 1, attrs: {onbeforeremove: remove}, text: "1"}, {tag: "div", key: 2, attrs: {onbeforeremove: remove}, text: "2"}]
|
||||||
var updated = {tag: "div", key: 2, attrs: {onbeforeremove: remove}, text: "2"}
|
var updated = {tag: "div", key: 2, attrs: {onbeforeremove: remove}, text: "2"}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,11 +92,10 @@ o.spec("onbeforeupdate", function() {
|
||||||
o("is not called on creation", function() {
|
o("is not called on creation", function() {
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
var vnode = {tag: "div", attrs: {id: "a", onbeforeupdate: onbeforeupdate}}
|
||||||
var updated = {tag: "div", attrs: {id: "b", onbeforeupdate: onbeforeupdate}}
|
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate() {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +111,7 @@ o.spec("onbeforeupdate", function() {
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate() {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -248,7 +247,7 @@ o.spec("onbeforeupdate", function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
o("is not called on component creation", function() {
|
o("is not called on component creation", function() {
|
||||||
var component = createComponent({
|
createComponent({
|
||||||
onbeforeupdate: onbeforeupdate,
|
onbeforeupdate: onbeforeupdate,
|
||||||
view: function(vnode) {
|
view: function(vnode) {
|
||||||
return {tag: "div", attrs: vnode.attrs}
|
return {tag: "div", attrs: vnode.attrs}
|
||||||
|
|
@ -257,11 +256,10 @@ o.spec("onbeforeupdate", function() {
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
var vnode = {tag: "div", attrs: {id: "a"}}
|
var vnode = {tag: "div", attrs: {id: "a"}}
|
||||||
var updated = {tag: "div", attrs: {id: "b"}}
|
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate() {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +282,7 @@ o.spec("onbeforeupdate", function() {
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
render(root, [updated])
|
render(root, [updated])
|
||||||
|
|
||||||
function onbeforeupdate(vnode, old) {
|
function onbeforeupdate() {
|
||||||
count++
|
count++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,6 @@ o.spec("oncreate", function() {
|
||||||
})
|
})
|
||||||
o("does not call oncreate when removing", function() {
|
o("does not call oncreate when removing", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var update = o.spy()
|
|
||||||
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oncreate: create}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,6 @@ o.spec("oninit", function() {
|
||||||
})
|
})
|
||||||
o("does not call oninit when removing", function() {
|
o("does not call oninit when removing", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var update = o.spy()
|
|
||||||
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
var vnode = {tag: "div", attrs: {oninit: create}, state: {}}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,6 @@ o.spec("onupdate", function() {
|
||||||
})
|
})
|
||||||
o("does not call old onupdate when removing the onupdate property in new vnode", function() {
|
o("does not call old onupdate when removing the onupdate property in new vnode", function() {
|
||||||
var create = o.spy()
|
var create = o.spy()
|
||||||
var update = o.spy()
|
|
||||||
var vnode = {tag: "a", attrs: {onupdate: create}}
|
var vnode = {tag: "a", attrs: {onupdate: create}}
|
||||||
var updated = {tag: "a"}
|
var updated = {tag: "a"}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
var o = require("../../ospec/ospec")
|
var o = require("../../ospec/ospec")
|
||||||
var components = require("../../test-utils/components")
|
|
||||||
var domMock = require("../../test-utils/domMock")
|
var domMock = require("../../test-utils/domMock")
|
||||||
var vdom = require("../../render/render")
|
var vdom = require("../../render/render")
|
||||||
|
|
||||||
|
|
@ -124,7 +123,7 @@ o.spec("render", function() {
|
||||||
var onbeforeupdate = o.spy()
|
var onbeforeupdate = o.spy()
|
||||||
function A() {
|
function A() {
|
||||||
return {
|
return {
|
||||||
view: function(vnode) {throw new Error("error")},
|
view: function() {throw new Error("error")},
|
||||||
oninit: oninit,
|
oninit: oninit,
|
||||||
onbeforeupdate: onbeforeupdate
|
onbeforeupdate: onbeforeupdate
|
||||||
}
|
}
|
||||||
|
|
@ -143,11 +142,11 @@ o.spec("render", function() {
|
||||||
o(onbeforeupdate.callCount).equals(0)
|
o(onbeforeupdate.callCount).equals(0)
|
||||||
})
|
})
|
||||||
o("does not try to re-initialize a closure component whose oninit has thrown", function() {
|
o("does not try to re-initialize a closure component whose oninit has thrown", function() {
|
||||||
var oninit = o.spy(function(vnode) {throw new Error("error")})
|
var oninit = o.spy(function() {throw new Error("error")})
|
||||||
var onbeforeupdate = o.spy()
|
var onbeforeupdate = o.spy()
|
||||||
function A() {
|
function A() {
|
||||||
return {
|
return {
|
||||||
view: function(vnode) {},
|
view: function() {},
|
||||||
oninit: oninit,
|
oninit: oninit,
|
||||||
onbeforeupdate: onbeforeupdate
|
onbeforeupdate: onbeforeupdate
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -213,10 +213,10 @@ o.spec("updateElement", function() {
|
||||||
})
|
})
|
||||||
o("updates svg child", function() {
|
o("updates svg child", function() {
|
||||||
var vnode = {tag: "svg", children: [{
|
var vnode = {tag: "svg", children: [{
|
||||||
tag: 'circle'
|
tag: "circle"
|
||||||
}]}
|
}]}
|
||||||
var updated = {tag: "svg", children: [{
|
var updated = {tag: "svg", children: [{
|
||||||
tag: 'line'
|
tag: "line"
|
||||||
}]}
|
}]}
|
||||||
|
|
||||||
render(root, [vnode])
|
render(root, [vnode])
|
||||||
|
|
|
||||||
|
|
@ -900,7 +900,6 @@ o.spec("updateNodes", function() {
|
||||||
var updated = {tag: "b"}
|
var updated = {tag: "b"}
|
||||||
|
|
||||||
render(root, vnode)
|
render(root, vnode)
|
||||||
var dom = vnode.dom
|
|
||||||
render(root, updated)
|
render(root, updated)
|
||||||
|
|
||||||
o(vnode.dom).notEquals(updated.dom)
|
o(vnode.dom).notEquals(updated.dom)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
function Vnode(tag, key, attrs, children, text, dom) {
|
function Vnode(tag, key, attrs, children, text, dom) {
|
||||||
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false}
|
return {tag: tag, key: key, attrs: attrs, children: children, text: text, dom: dom, domSize: undefined, state: {}, events: undefined, instance: undefined, skip: false}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,4 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var PromisePolyfill = require("./promise/promise")
|
var PromisePolyfill = require("./promise/promise")
|
||||||
module.exports = require("./request/request")(window, PromisePolyfill)
|
module.exports = require("./request/request")(window, PromisePolyfill)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ var Promise = require("../../promise/promise")
|
||||||
var parseQueryString = require("../../querystring/parse")
|
var parseQueryString = require("../../querystring/parse")
|
||||||
|
|
||||||
o.spec("jsonp", function() {
|
o.spec("jsonp", function() {
|
||||||
var mock, jsonp, spy, complete
|
var mock, jsonp, complete
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
mock = xhrMock()
|
mock = xhrMock()
|
||||||
var requestService = Request(mock, Promise)
|
var requestService = Request(mock, Promise)
|
||||||
|
|
@ -28,7 +28,6 @@ o.spec("jsonp", function() {
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
o("first argument can be a string aliasing url property", function(done){
|
o("first argument can be a string aliasing url property", function(done){
|
||||||
var s = new Date
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
var queryData = parseQueryString(request.query)
|
var queryData = parseQueryString(request.query)
|
||||||
|
|
@ -104,7 +103,7 @@ o.spec("jsonp", function() {
|
||||||
return {status: 200, responseText: queryData["callback"] + "([])"}
|
return {status: 200, responseText: queryData["callback"] + "([])"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var promise = jsonp("/item", {background: true}).then(function() {})
|
jsonp("/item", {background: true}).then(function() {})
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(complete.callCount).equals(0)
|
o(complete.callCount).equals(0)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ o.spec("xhr", function() {
|
||||||
|
|
||||||
o.spec("success", function() {
|
o.spec("success", function() {
|
||||||
o("works via GET", function(done) {
|
o("works via GET", function(done) {
|
||||||
var s = new Date
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function() {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify({a: 1})}
|
return {status: 200, responseText: JSON.stringify({a: 1})}
|
||||||
|
|
@ -31,7 +30,6 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("implicit GET method", function(done){
|
o("implicit GET method", function(done){
|
||||||
var s = new Date
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function() {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify({a: 1})}
|
return {status: 200, responseText: JSON.stringify({a: 1})}
|
||||||
|
|
@ -44,7 +42,6 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("first argument can be a string aliasing url property", function(done){
|
o("first argument can be a string aliasing url property", function(done){
|
||||||
var s = new Date
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function() {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify({a: 1})}
|
return {status: 200, responseText: JSON.stringify({a: 1})}
|
||||||
|
|
@ -172,7 +169,7 @@ o.spec("xhr", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify([{id: 1}, {id: 2}, {id: 3}])}
|
return {status: 200, responseText: JSON.stringify([{id: 1}, {id: 2}, {id: 3}])}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -186,7 +183,7 @@ o.spec("xhr", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify({id: 1})}
|
return {status: 200, responseText: JSON.stringify({id: 1})}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -228,12 +225,12 @@ o.spec("xhr", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
xhr({method: "GET", url: "/item", deserialize: deserialize}).then(function(data) {
|
xhr({method: "GET", url: "/item", deserialize: deserialize}).then(function(data) {
|
||||||
o(data).equals("{\"test\":123}")
|
o(data).equals('{"test":123}')
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
o("deserialize parameter works in POST", function(done) {
|
o("deserialize parameter works in POST", function(done) {
|
||||||
|
|
@ -242,40 +239,40 @@ o.spec("xhr", function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify({test: 123})}
|
return {status: 200, responseText: JSON.stringify({test: 123})}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
xhr({method: "POST", url: "/item", deserialize: deserialize}).then(function(data) {
|
xhr({method: "POST", url: "/item", deserialize: deserialize}).then(function(data) {
|
||||||
o(data).equals("{\"test\":123}")
|
o(data).equals('{"test":123}')
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
o("extract parameter works in GET", function(done) {
|
o("extract parameter works in GET", function(done) {
|
||||||
var extract = function(data) {
|
var extract = function() {
|
||||||
return JSON.stringify({test: 123})
|
return JSON.stringify({test: 123})
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
xhr({method: "GET", url: "/item", extract: extract}).then(function(data) {
|
xhr({method: "GET", url: "/item", extract: extract}).then(function(data) {
|
||||||
o(data).equals("{\"test\":123}")
|
o(data).equals('{"test":123}')
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
o("extract parameter works in POST", function(done) {
|
o("extract parameter works in POST", function(done) {
|
||||||
var extract = function(data) {
|
var extract = function() {
|
||||||
return JSON.stringify({test: 123})
|
return JSON.stringify({test: 123})
|
||||||
}
|
}
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function() {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
xhr({method: "POST", url: "/item", extract: extract}).then(function(data) {
|
xhr({method: "POST", url: "/item", extract: extract}).then(function(data) {
|
||||||
o(data).equals("{\"test\":123}")
|
o(data).equals('{"test":123}')
|
||||||
}).then(done)
|
}).then(done)
|
||||||
})
|
})
|
||||||
o("ignores deserialize if extract is defined", function(done) {
|
o("ignores deserialize if extract is defined", function(done) {
|
||||||
|
|
@ -285,7 +282,7 @@ o.spec("xhr", function() {
|
||||||
var deserialize = o.spy()
|
var deserialize = o.spy()
|
||||||
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -297,7 +294,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("config parameter works", function(done) {
|
o("config parameter works", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function() {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -311,7 +308,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("requests don't block each other", function(done) {
|
o("requests don't block each other", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: "[]"}
|
return {status: 200, responseText: "[]"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -328,7 +325,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("requests trigger finally once with a chained then", function(done) {
|
o("requests trigger finally once with a chained then", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: "[]"}
|
return {status: 200, responseText: "[]"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -342,11 +339,11 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("requests does not trigger finally when background: true", function(done) {
|
o("requests does not trigger finally when background: true", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: "[]"}
|
return {status: 200, responseText: "[]"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var promise = xhr("/item", {background: true}).then(function() {})
|
xhr("/item", {background: true}).then(function() {})
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
o(complete.callCount).equals(0)
|
o(complete.callCount).equals(0)
|
||||||
|
|
@ -355,7 +352,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("headers are set when header arg passed", function(done) {
|
o("headers are set when header arg passed", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function() {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -367,7 +364,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("headers are with higher precedence than default headers", function(done) {
|
o("headers are with higher precedence than default headers", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function() {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -379,7 +376,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("json headers are set to the correct default value", function(done) {
|
o("json headers are set to the correct default value", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function() {
|
||||||
return {status: 200, responseText: ""}
|
return {status: 200, responseText: ""}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -391,7 +388,6 @@ o.spec("xhr", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
o("doesn't fail on abort", function(done) {
|
o("doesn't fail on abort", function(done) {
|
||||||
var s = new Date
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function() {
|
"GET /item": function() {
|
||||||
return {status: 200, responseText: JSON.stringify({a: 1})}
|
return {status: 200, responseText: JSON.stringify({a: 1})}
|
||||||
|
|
@ -410,9 +406,9 @@ o.spec("xhr", function() {
|
||||||
done()
|
done()
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
Object.defineProperty(xhr, 'onreadystatechange', {
|
Object.defineProperty(xhr, "onreadystatechange", {
|
||||||
set: function(val) { onreadystatechange = val }
|
set: function(val) { onreadystatechange = val },
|
||||||
, get: function() { return testonreadystatechange }
|
get: function() { return testonreadystatechange }
|
||||||
})
|
})
|
||||||
xhr.abort()
|
xhr.abort()
|
||||||
}
|
}
|
||||||
|
|
@ -424,7 +420,6 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o("doesn't fail on file:// status 0", function(done) {
|
o("doesn't fail on file:// status 0", function(done) {
|
||||||
var s = new Date
|
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function() {
|
"GET /item": function() {
|
||||||
return {status: 0, responseText: JSON.stringify({a: 1})}
|
return {status: 0, responseText: JSON.stringify({a: 1})}
|
||||||
|
|
@ -456,7 +451,7 @@ o.spec("xhr", function() {
|
||||||
o.spec("failure", function() {
|
o.spec("failure", function() {
|
||||||
o("rejects on server error", function(done) {
|
o("rejects on server error", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 500, responseText: JSON.stringify({error: "error"})}
|
return {status: 500, responseText: JSON.stringify({error: "error"})}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -467,7 +462,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("extends Error with JSON response", function(done) {
|
o("extends Error with JSON response", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 500, responseText: JSON.stringify({message: "error", stack: "error on line 1"})}
|
return {status: 500, responseText: JSON.stringify({message: "error", stack: "error on line 1"})}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -479,7 +474,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("rejects on non-JSON server error", function(done) {
|
o("rejects on non-JSON server error", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 500, responseText: "error"}
|
return {status: 500, responseText: "error"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -489,7 +484,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("triggers all branched catches upon rejection", function(done) {
|
o("triggers all branched catches upon rejection", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 500, responseText: "error"}
|
return {status: 500, responseText: "error"}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -515,7 +510,7 @@ o.spec("xhr", function() {
|
||||||
})
|
})
|
||||||
o("rejects on cors-like error", function(done) {
|
o("rejects on cors-like error", function(done) {
|
||||||
mock.$defineRoutes({
|
mock.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function() {
|
||||||
return {status: 0}
|
return {status: 0}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
2
route.js
2
route.js
|
|
@ -1,3 +1,5 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
var redrawService = require("./redraw")
|
var redrawService = require("./redraw")
|
||||||
|
|
||||||
module.exports = require("./api/router")(window, redrawService)
|
module.exports = require("./api/router")(window, redrawService)
|
||||||
|
|
@ -6,7 +6,7 @@ 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 [{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 + "` starting on " + env.protocol + "//" + env.hostname, function() {
|
o.spec("using prefix `" + prefix + "` starting on " + env.protocol + "//" + env.hostname, function() {
|
||||||
var $window, router, onRouteChange, onFail
|
var $window, router, onRouteChange, onFail
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
module.exports = require("./stream/stream")
|
module.exports = require("./stream/stream")
|
||||||
|
|
@ -22,7 +22,7 @@ o.spec("scan", function() {
|
||||||
parent(7)
|
parent(7)
|
||||||
parent("11")
|
parent("11")
|
||||||
parent(undefined)
|
parent(undefined)
|
||||||
parent({ a: 1 })
|
parent({a: 1})
|
||||||
var result = child()
|
var result = child()
|
||||||
|
|
||||||
// deepEquals fails on arrays?
|
// deepEquals fails on arrays?
|
||||||
|
|
@ -32,4 +32,3 @@ o.spec("scan", function() {
|
||||||
o(result[3]).deepEquals({a: 1})
|
o(result[3]).deepEquals({a: 1})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
"use strict"
|
"use strict"
|
||||||
|
|
||||||
var o = require("../../ospec/ospec")
|
var o = require("../../ospec/ospec")
|
||||||
var callAsync = require("../../test-utils/callAsync")
|
|
||||||
var Stream = require("../stream")
|
var Stream = require("../stream")
|
||||||
|
|
||||||
o.spec("stream", function() {
|
o.spec("stream", function() {
|
||||||
|
|
@ -105,7 +104,7 @@ o.spec("stream", function() {
|
||||||
var streams = []
|
var streams = []
|
||||||
var a = Stream()
|
var a = Stream()
|
||||||
var b = Stream()
|
var b = Stream()
|
||||||
var c = Stream.combine(function(a, b, changed) {
|
Stream.combine(function(a, b, changed) {
|
||||||
streams = changed
|
streams = changed
|
||||||
}, [a, b])
|
}, [a, b])
|
||||||
|
|
||||||
|
|
@ -119,7 +118,7 @@ o.spec("stream", function() {
|
||||||
var streams = []
|
var streams = []
|
||||||
var a = Stream(3)
|
var a = Stream(3)
|
||||||
var b = Stream(5)
|
var b = Stream(5)
|
||||||
var c = Stream.combine(function(a, b, changed) {
|
Stream.combine(function(a, b, changed) {
|
||||||
streams = changed
|
streams = changed
|
||||||
}, [a, b])
|
}, [a, b])
|
||||||
|
|
||||||
|
|
@ -130,7 +129,7 @@ o.spec("stream", function() {
|
||||||
})
|
})
|
||||||
o("combine can return undefined", function() {
|
o("combine can return undefined", function() {
|
||||||
var a = Stream(1)
|
var a = Stream(1)
|
||||||
var b = Stream.combine(function(a) {
|
var b = Stream.combine(function() {
|
||||||
return undefined
|
return undefined
|
||||||
}, [a])
|
}, [a])
|
||||||
|
|
||||||
|
|
@ -138,7 +137,7 @@ o.spec("stream", function() {
|
||||||
})
|
})
|
||||||
o("combine can return stream", function() {
|
o("combine can return stream", function() {
|
||||||
var a = Stream(1)
|
var a = Stream(1)
|
||||||
var b = Stream.combine(function(a) {
|
var b = Stream.combine(function() {
|
||||||
return Stream(2)
|
return Stream(2)
|
||||||
}, [a])
|
}, [a])
|
||||||
|
|
||||||
|
|
@ -146,7 +145,7 @@ o.spec("stream", function() {
|
||||||
})
|
})
|
||||||
o("combine can return pending stream", function() {
|
o("combine can return pending stream", function() {
|
||||||
var a = Stream(1)
|
var a = Stream(1)
|
||||||
var b = Stream.combine(function(a) {
|
var b = Stream.combine(function() {
|
||||||
return Stream()
|
return Stream()
|
||||||
}, [a])
|
}, [a])
|
||||||
|
|
||||||
|
|
@ -155,10 +154,9 @@ o.spec("stream", function() {
|
||||||
o("combine can halt", function() {
|
o("combine can halt", function() {
|
||||||
var count = 0
|
var count = 0
|
||||||
var a = Stream(1)
|
var a = Stream(1)
|
||||||
var b = Stream.combine(function(a) {
|
var b = Stream.combine(function() {
|
||||||
return Stream.HALT
|
return Stream.HALT
|
||||||
}, [a])
|
}, [a])["fantasy-land/map"](function() {
|
||||||
["fantasy-land/map"](function() {
|
|
||||||
count++
|
count++
|
||||||
return 1
|
return 1
|
||||||
})
|
})
|
||||||
|
|
@ -170,7 +168,7 @@ o.spec("stream", function() {
|
||||||
var a = Stream(1)
|
var a = Stream(1)
|
||||||
var thrown = null;
|
var thrown = null;
|
||||||
try {
|
try {
|
||||||
var b = Stream.combine(spy, [a, ''])
|
Stream.combine(spy, [a, ""])
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
thrown = e
|
thrown = e
|
||||||
}
|
}
|
||||||
|
|
@ -210,8 +208,9 @@ o.spec("stream", function() {
|
||||||
var a = Stream()
|
var a = Stream()
|
||||||
var b = Stream()
|
var b = Stream()
|
||||||
|
|
||||||
var all = Stream.merge([a.map(id), b.map(id)]).map(function(data) {
|
Stream.merge([a.map(id), b.map(id)]).map(function(data) {
|
||||||
value = data[0] + data[1]
|
value = data[0] + data[1]
|
||||||
|
return undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
a(1)
|
a(1)
|
||||||
|
|
@ -344,7 +343,7 @@ o.spec("stream", function() {
|
||||||
})
|
})
|
||||||
o("works with pending stream", function() {
|
o("works with pending stream", function() {
|
||||||
var stream = Stream(undefined)
|
var stream = Stream(undefined)
|
||||||
var mapped = stream["fantasy-land/map"](function(value) {return Stream()})
|
var mapped = stream["fantasy-land/map"](function() {return Stream()})
|
||||||
|
|
||||||
o(mapped()()).equals(undefined)
|
o(mapped()()).equals(undefined)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,26 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
kind: 'POJO',
|
kind: "POJO",
|
||||||
create: function(methods) {
|
create: function(methods) {
|
||||||
var res = {view: function() {return {tag:'div'}}}
|
var res = {view: function() {return {tag:"div"}}}
|
||||||
Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]})
|
Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]})
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
kind: 'constructible',
|
kind: "constructible",
|
||||||
create: function(methods) {
|
create: function(methods) {
|
||||||
function res(){}
|
function res(){}
|
||||||
res.prototype.view = function() {return {tag:'div'}}
|
res.prototype.view = function() {return {tag:"div"}}
|
||||||
Object.keys(methods || {}).forEach(function(m){res.prototype[m] = methods[m]})
|
Object.keys(methods || {}).forEach(function(m){res.prototype[m] = methods[m]})
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
kind: 'closure',
|
kind: "closure",
|
||||||
create: function(methods) {
|
create: function(methods) {
|
||||||
return function() {
|
return function() {
|
||||||
var res = {view: function() {return {tag:'div'}}}
|
var res = {view: function() {return {tag:"div"}}}
|
||||||
Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]})
|
Object.keys(methods || {}).forEach(function(m){res[m] = methods[m]})
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ module.exports = function() {
|
||||||
declList = declList.replace(
|
declList = declList.replace(
|
||||||
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*')|\/\*[\s\S]*?\*\//g,
|
/("(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*')|\/\*[\s\S]*?\*\//g,
|
||||||
function(m, str){
|
function(m, str){
|
||||||
return str || ''
|
return str || ""
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
/*eslint-disable no-cond-assign*/
|
/*eslint-disable no-cond-assign*/
|
||||||
|
|
@ -115,7 +115,7 @@ module.exports = function() {
|
||||||
var activeElement
|
var activeElement
|
||||||
var $window = {
|
var $window = {
|
||||||
document: {
|
document: {
|
||||||
createElement: function(tag, is) {
|
createElement: function(tag) {
|
||||||
var cssText = ""
|
var cssText = ""
|
||||||
var style = {}
|
var style = {}
|
||||||
Object.defineProperty(style, "cssText", {
|
Object.defineProperty(style, "cssText", {
|
||||||
|
|
@ -211,11 +211,11 @@ module.exports = function() {
|
||||||
else this.setAttribute("class", value)
|
else this.setAttribute("class", value)
|
||||||
},
|
},
|
||||||
focus: function() {activeElement = this},
|
focus: function() {activeElement = this},
|
||||||
addEventListener: function(type, callback, useCapture) {
|
addEventListener: function(type, callback) {
|
||||||
if (events[type] == null) events[type] = [callback]
|
if (events[type] == null) events[type] = [callback]
|
||||||
else events[type].push(callback)
|
else events[type].push(callback)
|
||||||
},
|
},
|
||||||
removeEventListener: function(type, callback, useCapture) {
|
removeEventListener: function(type, callback) {
|
||||||
if (events[type] != null) {
|
if (events[type] != null) {
|
||||||
var index = events[type].indexOf(callback)
|
var index = events[type].indexOf(callback)
|
||||||
if (index > -1) events[type].splice(index, 1)
|
if (index > -1) events[type].splice(index, 1)
|
||||||
|
|
@ -241,7 +241,6 @@ module.exports = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element.nodeName === "A") {
|
if (element.nodeName === "A") {
|
||||||
var href
|
|
||||||
Object.defineProperty(element, "href", {
|
Object.defineProperty(element, "href", {
|
||||||
get: function() {return this.attributes["href"] === undefined ? "" : "[FIXME implement]"},
|
get: function() {return this.attributes["href"] === undefined ? "" : "[FIXME implement]"},
|
||||||
set: function(value) {this.setAttribute("href", value)},
|
set: function(value) {this.setAttribute("href", value)},
|
||||||
|
|
@ -272,6 +271,8 @@ module.exports = function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eslint-disable radix */
|
||||||
|
|
||||||
if (element.nodeName === "CANVAS") {
|
if (element.nodeName === "CANVAS") {
|
||||||
Object.defineProperty(element, "width", {
|
Object.defineProperty(element, "width", {
|
||||||
get: function() {return this.attributes["width"] ? Math.floor(parseInt(this.attributes["width"].nodeValue) || 0) : 300},
|
get: function() {return this.attributes["width"] ? Math.floor(parseInt(this.attributes["width"].nodeValue) || 0) : 300},
|
||||||
|
|
@ -283,6 +284,8 @@ module.exports = function() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eslint-enable radix */
|
||||||
|
|
||||||
function getOptions(element) {
|
function getOptions(element) {
|
||||||
var options = []
|
var options = []
|
||||||
for (var i = 0; i < element.childNodes.length; i++) {
|
for (var i = 0; i < element.childNodes.length; i++) {
|
||||||
|
|
@ -297,17 +300,18 @@ module.exports = function() {
|
||||||
element.firstChild != null ? element.firstChild.nodeValue : ""
|
element.firstChild != null ? element.firstChild.nodeValue : ""
|
||||||
}
|
}
|
||||||
if (element.nodeName === "SELECT") {
|
if (element.nodeName === "SELECT") {
|
||||||
var selectedValue, selectedIndex = 0
|
// var selectedValue
|
||||||
|
var selectedIndex = 0
|
||||||
Object.defineProperty(element, "selectedIndex", {
|
Object.defineProperty(element, "selectedIndex", {
|
||||||
get: function() {return getOptions(this).length > 0 ? selectedIndex : -1},
|
get: function() {return getOptions(this).length > 0 ? selectedIndex : -1},
|
||||||
set: function(value) {
|
set: function(value) {
|
||||||
var options = getOptions(this)
|
var options = getOptions(this)
|
||||||
if (value >= 0 && value < options.length) {
|
if (value >= 0 && value < options.length) {
|
||||||
selectedValue = getOptionValue(options[selectedIndex])
|
// selectedValue = getOptionValue(options[selectedIndex])
|
||||||
selectedIndex = value
|
selectedIndex = value
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
selectedValue = ""
|
// selectedValue = ""
|
||||||
selectedIndex = -1
|
selectedIndex = -1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -323,12 +327,12 @@ module.exports = function() {
|
||||||
var stringValue = String(value)
|
var stringValue = String(value)
|
||||||
for (var i = 0; i < options.length; i++) {
|
for (var i = 0; i < options.length; i++) {
|
||||||
if (getOptionValue(options[i]) === stringValue) {
|
if (getOptionValue(options[i]) === stringValue) {
|
||||||
selectedValue = stringValue
|
// selectedValue = stringValue
|
||||||
selectedIndex = i
|
selectedIndex = i
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectedValue = stringValue
|
// selectedValue = stringValue
|
||||||
selectedIndex = -1
|
selectedIndex = -1
|
||||||
},
|
},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
module.exports = function parseURL(url, root) {
|
module.exports = function parseURL(url, root) {
|
||||||
var data = {}
|
var data = {}
|
||||||
var protocolIndex = url.indexOf("://")
|
var protocolIndex = url.indexOf("://")
|
||||||
var pathnameIndex = protocolIndex > - 1 ? url.indexOf("/", protocolIndex + 3) : url.indexOf("/")
|
var pathnameIndex = protocolIndex > -1 ? url.indexOf("/", protocolIndex + 3) : url.indexOf("/")
|
||||||
var searchIndex = url.indexOf("?")
|
var searchIndex = url.indexOf("?")
|
||||||
var hashIndex = url.indexOf("#")
|
var hashIndex = url.indexOf("#")
|
||||||
if ((pathnameIndex > searchIndex && searchIndex > -1) || (pathnameIndex > hashIndex && hashIndex > -1)) pathnameIndex = -1
|
if ((pathnameIndex > searchIndex && searchIndex > -1) || (pathnameIndex > hashIndex && hashIndex > -1)) pathnameIndex = -1
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ o.spec("browserMock", function() {
|
||||||
})
|
})
|
||||||
o("$window.onhashchange can be reached from the pushStateMock functions", function(done) {
|
o("$window.onhashchange can be reached from the pushStateMock functions", function(done) {
|
||||||
$window.onhashchange = o.spy()
|
$window.onhashchange = o.spy()
|
||||||
$window.location.hash = '#a'
|
$window.location.hash = "#a"
|
||||||
|
|
||||||
callAsync(function(){
|
callAsync(function(){
|
||||||
o($window.onhashchange.callCount).equals(1)
|
o($window.onhashchange.callCount).equals(1)
|
||||||
|
|
@ -33,7 +33,7 @@ o.spec("browserMock", function() {
|
||||||
})
|
})
|
||||||
o("$window.onunload can be reached from the pushStateMock functions", function() {
|
o("$window.onunload can be reached from the pushStateMock functions", function() {
|
||||||
$window.onunload = o.spy()
|
$window.onunload = o.spy()
|
||||||
$window.location.href = '/a'
|
$window.location.href = "/a"
|
||||||
|
|
||||||
o($window.onunload.callCount).equals(1)
|
o($window.onunload.callCount).equals(1)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ var components = require("../../test-utils/components")
|
||||||
o.spec("test-utils/components", function() {
|
o.spec("test-utils/components", function() {
|
||||||
var test = o.spy(function(component) {
|
var test = o.spy(function(component) {
|
||||||
return function() {
|
return function() {
|
||||||
o('works', function() {
|
o("works", function() {
|
||||||
o(typeof component.kind).equals('string')
|
o(typeof component.kind).equals("string")
|
||||||
|
|
||||||
var methods = {oninit: function(){}, view: function(){}}
|
var methods = {oninit: function(){}, view: function(){}}
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ o.spec("test-utils/components", function() {
|
||||||
o(vnode != null).equals(true)
|
o(vnode != null).equals(true)
|
||||||
o(vnode).deepEquals({tag: "div"})
|
o(vnode).deepEquals({tag: "div"})
|
||||||
|
|
||||||
if (component.kind !== 'constructible') {
|
if (component.kind !== "constructible") {
|
||||||
o(cmp2).deepEquals(methods)
|
o(cmp2).deepEquals(methods)
|
||||||
} else {
|
} else {
|
||||||
// deepEquals doesn't search the prototype, do it manually
|
// deepEquals doesn't search the prototype, do it manually
|
||||||
|
|
|
||||||
|
|
@ -393,7 +393,6 @@ o.spec("domMock", function() {
|
||||||
o.spec("textContent", function() {
|
o.spec("textContent", function() {
|
||||||
o("works", function() {
|
o("works", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
var a = $document.createElement("a")
|
|
||||||
div.textContent = "aaa"
|
div.textContent = "aaa"
|
||||||
|
|
||||||
o(div.childNodes.length).equals(1)
|
o(div.childNodes.length).equals(1)
|
||||||
|
|
@ -402,7 +401,6 @@ o.spec("domMock", function() {
|
||||||
})
|
})
|
||||||
o("works with empty string", function() {
|
o("works with empty string", function() {
|
||||||
var div = $document.createElement("div")
|
var div = $document.createElement("div")
|
||||||
var a = $document.createElement("a")
|
|
||||||
div.textContent = ""
|
div.textContent = ""
|
||||||
|
|
||||||
o(div.childNodes.length).equals(0)
|
o(div.childNodes.length).equals(0)
|
||||||
|
|
@ -515,7 +513,7 @@ o.spec("domMock", function() {
|
||||||
div.style.cssText = "background: url(';'); font-family: \";\""
|
div.style.cssText = "background: url(';'); font-family: \";\""
|
||||||
|
|
||||||
o(div.style.background).equals("url(';')")
|
o(div.style.background).equals("url(';')")
|
||||||
o(div.style.fontFamily).equals("\";\"")
|
o(div.style.fontFamily).equals('";"')
|
||||||
o(div.style.cssText).equals("background: url(';'); font-family: \";\";")
|
o(div.style.cssText).equals("background: url(';'); font-family: \";\";")
|
||||||
})
|
})
|
||||||
o("comments in style.cssText are stripped", function(){
|
o("comments in style.cssText are stripped", function(){
|
||||||
|
|
@ -534,9 +532,10 @@ o.spec("domMock", function() {
|
||||||
|
|
||||||
})
|
})
|
||||||
o("setting style throws", function () {
|
o("setting style throws", function () {
|
||||||
|
var div = $document.createElement("div")
|
||||||
var err = false
|
var err = false
|
||||||
try {
|
try {
|
||||||
div.style = ''
|
div.style = ""
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e
|
err = e
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -168,13 +168,13 @@ o.spec("pushStateMock", function() {
|
||||||
})
|
})
|
||||||
o.spec("set protocol", function() {
|
o.spec("set protocol", function() {
|
||||||
o("setting protocol throws", function(done) {
|
o("setting protocol throws", function(done) {
|
||||||
var old = $window.location.href
|
|
||||||
try {
|
try {
|
||||||
$window.location.protocol = "https://"
|
$window.location.protocol = "https://"
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
done()
|
return done()
|
||||||
}
|
}
|
||||||
|
throw new Error("Expected an error")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
o.spec("set port", function() {
|
o.spec("set port", function() {
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ var xhrMock = require("../../test-utils/xhrMock")
|
||||||
var parseQueryString = require("../../querystring/parse")
|
var parseQueryString = require("../../querystring/parse")
|
||||||
|
|
||||||
o.spec("xhrMock", function() {
|
o.spec("xhrMock", function() {
|
||||||
var $window, ajax
|
var $window
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
$window = xhrMock()
|
$window = xhrMock()
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("xhr", function() {
|
o.spec("xhr", function() {
|
||||||
o("works", function(done, timeout) {
|
o("works", function(done) {
|
||||||
$window.$defineRoutes({
|
$window.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
o(request.url).equals("/item")
|
o(request.url).equals("/item")
|
||||||
|
|
@ -29,7 +29,7 @@ o.spec("xhrMock", function() {
|
||||||
}
|
}
|
||||||
xhr.send()
|
xhr.send()
|
||||||
})
|
})
|
||||||
o("works w/ search", function(done, timeout) {
|
o("works w/ search", function(done) {
|
||||||
$window.$defineRoutes({
|
$window.$defineRoutes({
|
||||||
"GET /item": function(request) {
|
"GET /item": function(request) {
|
||||||
o(request.query).equals("?a=b")
|
o(request.query).equals("?a=b")
|
||||||
|
|
@ -45,7 +45,7 @@ o.spec("xhrMock", function() {
|
||||||
}
|
}
|
||||||
xhr.send()
|
xhr.send()
|
||||||
})
|
})
|
||||||
o("works w/ body", function(done, timeout) {
|
o("works w/ body", function(done) {
|
||||||
$window.$defineRoutes({
|
$window.$defineRoutes({
|
||||||
"POST /item": function(request) {
|
"POST /item": function(request) {
|
||||||
o(request.body).equals("a=b")
|
o(request.body).equals("a=b")
|
||||||
|
|
@ -61,7 +61,7 @@ o.spec("xhrMock", function() {
|
||||||
}
|
}
|
||||||
xhr.send("a=b")
|
xhr.send("a=b")
|
||||||
})
|
})
|
||||||
o("handles routing error", function(done, timeout) {
|
o("handles routing error", function(done) {
|
||||||
var xhr = new $window.XMLHttpRequest()
|
var xhr = new $window.XMLHttpRequest()
|
||||||
xhr.open("GET", "/nonexistent")
|
xhr.open("GET", "/nonexistent")
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
|
|
@ -113,7 +113,7 @@ o.spec("xhrMock", function() {
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
o("works with other querystring params", function(done, timeout) {
|
o("works with other querystring params", function(done) {
|
||||||
$window.$defineRoutes({
|
$window.$defineRoutes({
|
||||||
"GET /test": function(request) {
|
"GET /test": function(request) {
|
||||||
var queryData = parseQueryString(request.query)
|
var queryData = parseQueryString(request.query)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ var parseQueryString = require("../querystring/parse")
|
||||||
|
|
||||||
module.exports = function() {
|
module.exports = function() {
|
||||||
var routes = {}
|
var routes = {}
|
||||||
var callback = "callback"
|
// var callback = "callback"
|
||||||
var serverErrorHandler = function(url) {
|
var serverErrorHandler = function(url) {
|
||||||
return {status: 500, responseText: "server error, most likely the URL was not defined " + url}
|
return {status: 500, responseText: "server error, most likely the URL was not defined " + url}
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +43,6 @@ module.exports = function() {
|
||||||
}
|
}
|
||||||
self.readyState = 4
|
self.readyState = 4
|
||||||
if (args.async === true) {
|
if (args.async === true) {
|
||||||
var s = new Date
|
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
if (typeof self.onreadystatechange === "function") self.onreadystatechange()
|
if (typeof self.onreadystatechange === "function") self.onreadystatechange()
|
||||||
})
|
})
|
||||||
|
|
@ -64,7 +63,7 @@ module.exports = function() {
|
||||||
var urlData = parseURL(element.src, {protocol: "http:", hostname: "localhost", port: "", pathname: "/"})
|
var urlData = parseURL(element.src, {protocol: "http:", hostname: "localhost", port: "", pathname: "/"})
|
||||||
var handler = routes["GET " + urlData.pathname] || serverErrorHandler.bind(null, element.src)
|
var handler = routes["GET " + urlData.pathname] || serverErrorHandler.bind(null, element.src)
|
||||||
var data = handler({url: urlData.pathname, query: urlData.search, body: null})
|
var data = handler({url: urlData.pathname, query: urlData.search, body: null})
|
||||||
var query = parseQueryString(urlData.search)
|
parseQueryString(urlData.search)
|
||||||
callAsync(function() {
|
callAsync(function() {
|
||||||
if (data.status === 200) {
|
if (data.status === 200) {
|
||||||
new Function("$window", "with ($window) return " + data.responseText).call($window, $window)
|
new Function("$window", "with ($window) return " + data.responseText).call($window, $window)
|
||||||
|
|
@ -83,8 +82,8 @@ module.exports = function() {
|
||||||
$defineRoutes: function(rules) {
|
$defineRoutes: function(rules) {
|
||||||
routes = rules
|
routes = rules
|
||||||
},
|
},
|
||||||
$defineJSONPCallbackKey: function(key) {
|
$defineJSONPCallbackKey: function(/* key */) {
|
||||||
callback = key
|
// callback = key
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return $window
|
return $window
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ o.spec("api", function() {
|
||||||
o.beforeEach(function() {
|
o.beforeEach(function() {
|
||||||
var mock = browserMock()
|
var mock = browserMock()
|
||||||
if (typeof global !== "undefined") global.window = mock
|
if (typeof global !== "undefined") global.window = mock
|
||||||
m = require("../mithril")
|
m = require("../mithril") // eslint-disable-line global-require
|
||||||
})
|
})
|
||||||
|
|
||||||
o.spec("m", function() {
|
o.spec("m", function() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue