MCPcopy
hub / github.com/MithrilJS/mithril.js / next

Function next

ospec/ospec.js:121–197  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

119 next()
120
121 function next() {
122 if (cursor === tasks.length) return
123
124 var task = tasks[cursor++]
125 var fn = task.fn
126 currentTestError = task.err
127 var timeout = 0, delay = defaultDelay, s = new Date
128 var current = cursor
129 var arg
130
131 globalTimeout = setDelay
132
133 var isDone = false
134 // public API, may only be called once from use code (or after returned Promise resolution)
135 function done(err) {
136 if (!isDone) isDone = true
137 else throw new Error("`" + arg + "()` should only be called once")
138 if (timeout === undefined) console.warn("# elapsed: " + Math.round(new Date - s) + "ms, expected under " + delay + "ms\n" + o.cleanStackTrace(task.err))
139 finalizeAsync(err)
140 }
141 // for internal use only
142 function finalizeAsync(err) {
143 if (err == null) {
144 if (task.err != null) succeed(new Assert)
145 } else {
146 if (err instanceof Error) fail(new Assert, err.message, err)
147 else fail(new Assert, String(err), null)
148 }
149 if (timeout !== undefined) timeout = clearTimeout(timeout)
150 if (current === cursor) next()
151 }
152 function startTimer() {
153 timeout = setTimeout(function() {
154 timeout = undefined
155 finalizeAsync("async test timed out after " + delay + "ms")
156 }, Math.min(delay, 2147483647))
157 }
158 function setDelay (t) {
159 if (typeof t !== "number") throw new Error("timeout() and o.timeout() expect a number as argument")
160 delay = t
161 }
162 if (fn.length > 0) {
163 var body = fn.toString()
164 arg = (body.match(/^(.+?)(?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*=>/) || body.match(/\((?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*(.+?)(?:\s|\/\*[\s\S]*?\*\/|\/\/.*?\n)*[,\)]/) || []).pop()
165 if (body.indexOf(arg) === body.lastIndexOf(arg)) {
166 var e = new Error
167 e.stack = "`" + arg + "()` should be called at least once\n" + o.cleanStackTrace(task.err)
168 throw e
169 }
170 try {
171 fn(done, setDelay)
172 }
173 catch (e) {
174 if (task.err != null) finalizeAsync(e)
175 // The errors of internal tasks (which don't have an Err) are ospec bugs and must be rethrown.
176 else throw e
177 }
178 if (timeout === 0) {

Callers 5

handleFunction · 0.85
handleFunction · 0.85
seriesFunction · 0.85
finalizeAsyncFunction · 0.85
ospec.jsFile · 0.85

Calls 3

finalizeAsyncFunction · 0.85
startTimerFunction · 0.85
doneFunction · 0.85

Tested by

no test coverage detected