[ospec] Improve the done() call checker

This commit is contained in:
Pierre-Yves Gérardy 2018-05-27 22:30:01 +02:00 committed by Pierre-Yves Gérardy
parent 33180370ea
commit 8ebf036b8c
3 changed files with 86 additions and 2 deletions

View file

@ -166,8 +166,12 @@ else window.o = m()
}
if (fn.length > 0) {
var body = fn.toString()
arg = (body.match(/\(([\w$]+)/) || body.match(/([\w$]+)\s*=>/) || []).pop()
if (body.indexOf(arg) === body.lastIndexOf(arg)) throw new Error("`" + arg + "()` should be called at least once")
arg = (body.match(/^(.+?)(?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*=>/) || body.match(/\((?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*(.+?)(?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*[,\)]/) || []).pop()
if (body.indexOf(arg) === body.lastIndexOf(arg)) {
var e = new Error
e.stack = "`" + arg + "()` should be called at least once\n" + o.cleanStackTrace(task.err)
throw e
}
try {
fn(done, setDelay)
}