From 9ad16858a56bc476f3275036c5e0da8f5967c75e Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 8 Jan 2017 13:05:27 -0500 Subject: [PATCH] #1520 ospec: report duplicate test names --- api/tests/test-router.js | 37 -------------------------- bundler/tests/test-bundler.js | 4 +-- ospec/README.md | 2 +- ospec/ospec.js | 9 +++++++ ospec/package.json | 2 +- promise/tests/test-promise.js | 4 +-- request/tests/test-jsonp.js | 11 -------- test-utils/tests/test-parseURL.js | 2 +- test-utils/tests/test-pushStateMock.js | 6 ----- 9 files changed, 16 insertions(+), 61 deletions(-) diff --git a/api/tests/test-router.js b/api/tests/test-router.js index d70a7c23..6a281237 100644 --- a/api/tests/test-router.js +++ b/api/tests/test-router.js @@ -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 diff --git a/bundler/tests/test-bundler.js b/bundler/tests/test-bundler.js index 60859a11..3055bf7c 100644 --- a/bundler/tests/test-bundler.js +++ b/bundler/tests/test-bundler.js @@ -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`) diff --git a/ospec/README.md b/ospec/README.md index 084d949d..ec0173ea 100644 --- a/ospec/README.md +++ b/ospec/README.md @@ -4,7 +4,7 @@ Noiseless testing framework -Version: 1.2.2 +Version: 1.2.3 License: MIT ## About diff --git a/ospec/ospec.js b/ospec/ospec.js index 56111b66..96a09ebe 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -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) diff --git a/ospec/package.json b/ospec/package.json index 1127ad7f..fdda49db 100644 --- a/ospec/package.json +++ b/ospec/package.json @@ -1,6 +1,6 @@ { "name": "ospec", - "version": "1.2.2", + "version": "1.2.3", "description": "Noiseless testing framework", "main": "ospec.js", "directories": { diff --git a/promise/tests/test-promise.js b/promise/tests/test-promise.js index aa3a1bd9..a91b0bcb 100644 --- a/promise/tests/test-promise.js +++ b/promise/tests/test-promise.js @@ -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) { diff --git a/request/tests/test-jsonp.js b/request/tests/test-jsonp.js index 6dd0a619..7042274c 100644 --- a/request/tests/test-jsonp.js +++ b/request/tests/test-jsonp.js @@ -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) { diff --git a/test-utils/tests/test-parseURL.js b/test-utils/tests/test-parseURL.js index 10bb7e81..b722cd8d 100644 --- a/test-utils/tests/test-parseURL.js +++ b/test-utils/tests/test-parseURL.js @@ -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") diff --git a/test-utils/tests/test-pushStateMock.js b/test-utils/tests/test-pushStateMock.js index 86298b30..3cb51716 100644 --- a/test-utils/tests/test-pushStateMock.js +++ b/test-utils/tests/test-pushStateMock.js @@ -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()