From 53597871b8b393706574fdaac54135d8fd4424d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yves=20G=C3=A9rardy?= Date: Fri, 1 Jun 2018 09:32:55 +0200 Subject: [PATCH] [ospec] don't allocate task for tests that will be skipped in o.only mode, fix stack overflow --- ospec/ospec.js | 15 ++++----------- ospec/tests/test-ospec.js | 8 +++++++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ospec/ospec.js b/ospec/ospec.js index ea542f82..99ca8b4a 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -101,20 +101,13 @@ 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) { - tasks.push(new Task(function(done, timeout) { - timeout(Infinity) - if (only !== null && spec[key].fn !== only && spec[key] instanceof Task) return done() - + if (key.charCodeAt(0) !== 1 && (only === null || spec[key].fn === only || !(spec[key] instanceof Task))) { + tasks.push(new Task(function(done) { + o.timeout(Infinity) subjects.push(key) - var pop = new Task(function pop() { - subjects.pop() - done() - }, null) - + var pop = new Task(function pop() {subjects.pop(), done()}, null) if (spec[key] instanceof Task) series([].concat(pre, spec[key], post, pop), defaultDelay) else test(spec[key], pre, post, pop, defaultDelay) - }, null)) } return tasks diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index d652ad90..90c26ae0 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -37,8 +37,14 @@ if (typeof process !== "undefined") { o("o.only", function(done) { var oo = o.new() + oo.spec("won't run", function() { + oo("nope, skipped", function() { + o(true).equals(false) + }) + }) + oo.spec("ospec", function() { - oo("skipped", function() { + oo("skipped as well", function() { oo(true).equals(false) }) oo.only(".only()", function() {