[ospec] don't allocate task for tests that will be skipped in o.only mode, fix stack overflow

This commit is contained in:
Pierre-Yves Gérardy 2018-06-01 09:32:55 +02:00 committed by Pierre-Yves Gérardy
parent 277f35fb3a
commit 53597871b8
2 changed files with 11 additions and 12 deletions

View file

@ -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

View file

@ -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() {