#1520 ospec: report duplicate test names

This commit is contained in:
Leo Horie 2017-01-08 13:05:27 -05:00
parent 3bac29bf78
commit 9ad16858a5
9 changed files with 16 additions and 61 deletions

View file

@ -1074,43 +1074,6 @@ o.spec("route", function() {
})
})
o("calling route.set invalidates pending onmatch resolution", function(done) {
var rendered = false
var resolved
$window.location.href = prefix + "/a"
route(root, "/a", {
"/a": {
onmatch: function() {
return new Promise(function(resolve) {
callAsync(function() {
callAsync(function() {
resolve({view: function() {}})
})
})
})
},
render: function(vnode) {
rendered = true
resolved = "a"
}
},
"/b": {
view: function() {
resolved = "b"
}
}
})
route.set("/b")
callAsync(function() {
o(rendered).equals(false)
o(resolved).equals("b")
done()
})
})
o("calling route.set invalidates pending onmatch resolution", function(done) {
var rendered = false
var resolved

View file

@ -214,14 +214,14 @@ o.spec("bundler", function() {
write("c.js", `var cc = 2\nmodule.exports = cc`)
bundle(ns + "a.js", ns + "out.js")
o(read("out.js")).equals(`new function() {\nvar x = {}\var bb = 1\nnx.b = bb\nvar cc = 1\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("b.js")
remove("c.js")
remove("out.js")
})
o("works if assigned to property", 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("b.js", `var bb = 1\nmodule.exports = bb`)
write("c.js", `var cc = 2\nmodule.exports = cc`)

View file

@ -4,7 +4,7 @@
Noiseless testing framework
Version: 1.2.2
Version: 1.2.3
License: MIT
## About

View file

@ -4,6 +4,7 @@ module.exports = new function init() {
var spec = {}, subjects = [], results = [], only = null, ctx = spec, start, stack = 0, hasProcess = typeof process === "object"
function o(subject, predicate) {
subject = unique(subject, predicate)
ctx[subject] = predicate
if (predicate === undefined) return new Assert(subject)
}
@ -14,6 +15,7 @@ module.exports = new function init() {
o.new = init
o.spec = function(subject, predicate) {
var parent = ctx
subject = unique(subject, predicate)
ctx = ctx[subject] = {}
predicate()
ctx = parent
@ -110,6 +112,13 @@ module.exports = new function init() {
}
}
}
function unique(subject, predicate) {
if (ctx.hasOwnProperty(subject) && predicate) {
console.warn("A test named `" + subject + "` was already defined")
subject = subject + "*"
}
return subject
}
function hook(name) {
return function(predicate) {
if (ctx[name]) throw new Error("This hook should be defined outside of a loop or inside a nested test group:\n" + predicate)

View file

@ -1,6 +1,6 @@
{
"name": "ospec",
"version": "1.2.2",
"version": "1.2.3",
"description": "Noiseless testing framework",
"main": "ospec.js",
"directories": {

View file

@ -27,7 +27,7 @@ o.spec("promise", function() {
o(promise instanceof Promise).equals(true)
})
o("static resolve returns promise", function() {
o("static reject returns promise", function() {
var promise = Promise.reject()
promise.catch(function() {})
@ -141,7 +141,7 @@ o.spec("promise", function() {
done()
})
})
o("non-function onFulfilled is ignored", function(done) {
o("non-function onFulfilled with no second param is ignored", function(done) {
var promise = Promise.resolve(1)
promise.then(null).then(function(value) {

View file

@ -64,17 +64,6 @@ o.spec("jsonp", function() {
o(data).deepEquals({a: 2})
}).then(done)
})
o("works w/ custom callbackKey", function(done) {
mock.$defineRoutes({
"GET /item": function(request) {
var queryData = parseQueryString(request.query)
return {status: 200, responseText: queryData["cb"] + "(" + JSON.stringify({a: 2}) + ")"}
}
})
jsonp({url: "/item", callbackKey: "cb"}).then(function(data) {
o(data).deepEquals({a: 2})
}).then(done)
})
o("requests don't block each other", function(done) {
mock.$defineRoutes({
"GET /item": function(request) {

View file

@ -136,7 +136,7 @@ o.spec("parseURL", function() {
o(data.search).equals("?a/c")
o(data.hash).equals("")
})
o("handles search w/ slash", function() {
o("handles search w/ colon", function() {
var data = parseURL("http://www.google.com/test?a:c")
o(data.pathname).equals("/test")
o(data.search).equals("?a:c")

View file

@ -382,12 +382,6 @@ o.spec("pushStateMock", function() {
o($window.onpopstate.callCount).equals(2)
})
o("history.back() without history does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("history.forward() without history does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.forward()