From 14695c9cda4cf9a53284c730078b15d33ad6c8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Fri, 1 Jun 2018 19:12:58 +0200 Subject: [PATCH] [ospec] Allow more than one o.only() test --- ospec/ospec.js | 7 ++++--- ospec/tests/test-ospec.js | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index f27021bf..2706f6ac 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -4,7 +4,7 @@ if (typeof module !== "undefined") module["exports"] = m() else window.o = m() })(function init(name) { - var spec = {}, subjects = [], results, only = null, ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty + var spec = {}, subjects = [], results, only = [], ctx = spec, start, stack = 0, nextTickish, hasProcess = typeof process === "object", hasOwn = ({}).hasOwnProperty var ospecFileName = getStackName(ensureStackTrace(new Error), /[\/\\](.*?):\d+:\d+/), timeoutStackName var globalTimeout = noTimeoutRightNow var currentTestError = null @@ -43,7 +43,8 @@ else window.o = m() highlight("/!\\ WARNING /!\\ o.only() mode") + "\n" + o.cleanStackTrace(ensureStackTrace(new Error)) + "\n", cStyle("red"), "" ) - o(subject, only = predicate) + only.push(predicate) + o(subject, predicate) } o.spy = function(fn) { var spy = function() { @@ -101,7 +102,7 @@ else window.o = m() pre = [].concat(pre, spec["\x01beforeEach"] || []) post = [].concat(spec["\x01afterEach"] || [], post) series([].concat(spec["\x01before"] || [], Object.keys(spec).reduce(function(tasks, key) { - if (key.charCodeAt(0) !== 1 && (only === null || spec[key].fn === only || !(spec[key] instanceof Task))) { + if (key.charCodeAt(0) !== 1 && (only.length === 0 || only.indexOf(spec[key].fn) !== -1 || !(spec[key] instanceof Task))) { tasks.push(new Task(function(done) { o.timeout(Infinity) subjects.push(key) diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index 537890a3..43f4e0bc 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -50,11 +50,16 @@ o("o.only", function(done) { oo.only(".only()", function() { oo(2).equals(2) }, true) + oo.only("another .only()", function(done) { + done("that fails") + }, true) }) oo.run(function(results){ - o(results.length).equals(1) + o(results.length).equals(2) o(results[0].pass).equals(true) + o(results[1].pass).equals(false) + done() }) })