UNPKG

1.18 kBtext/coffeescriptView Raw
1fibrous = require('./fibrous')
2
3class jasmine.AsyncBlock extends jasmine.Block
4 execute: (onComplete) ->
5 completed = false
6 complete = (err) =>
7 if completed
8 console.error "A completed async spec \"#{@spec.getFullName()}\" has completed again with", err?.stack or err
9 else
10 completed = true
11 clearTimeout(timeout)
12 @spec.fail(err) if err?
13 process.nextTick onComplete # next tick it to prevent the next block from running in the previous block's fiber
14
15 timeout = setTimeout =>
16 complete(new Error("spec timed out after #{jasmine.DEFAULT_TIMEOUT_INTERVAL} msec"))
17 , jasmine.DEFAULT_TIMEOUT_INTERVAL
18
19 @func.call @spec, complete
20
21for jasmineFunction in [ "it", "beforeEach", "afterEach"]
22 do (jasmineFunction) ->
23 original = jasmine.Env.prototype[jasmineFunction]
24 jasmine.Env.prototype[jasmineFunction] = (args...) ->
25 func = args.pop()
26
27 return original.call @, args..., ->
28 #Causes non async specs to run inside a fiber
29 asyncFunc = (func.length is 1) and func or fibrous(func)
30 asyncBlock = new jasmine.AsyncBlock(@env, asyncFunc, @)
31 @addToQueue(asyncBlock)