neft
Version:
Universal Platform
115 lines (91 loc) • 2.7 kB
text/coffeescript
'use strict'
{utils} = Neft
stack = require './stack'
logger = require './logger'
class Scope
constructor: ->
= null
= ''
= []
= []
= []
Object.seal @
run: do ->
forEachCallback = (child, i, arr, callback) ->
stack.currentScope = @
child.run callback
(callback) ->
Object.freeze @
logger.onScopeStart @
utils.async.forEach , forEachCallback, ->
logger.onScopeEnd @
callback()
, @
return
class Test
constructor: ->
= false
= null
= {}
= null
= true
= ''
= utils.NOP
= null
= utils.bindFunctionContext , @
Object.seal @
onEnd: (err) ->
if
return
= true
if err
stack.fail err
stack.testsAmount += 1
logger.onTestEnd @
# call after functions
for afterFunc in stack.currentScope.afterFunctions
stack.callFunction afterFunc,
return
run: (callback) ->
stack.currentTest = @
= callback
logger.onTestStart @
# call before functions
for beforeFunc in stack.currentScope.beforeFunctions
stack.callFunction beforeFunc,
# call test function
if .length is 0
stack.callFunction ,
else
stack.callFunction , , []
return
getFullMessage: ->
str =
scope = @
while scope = scope.parent
if message = scope.message
str = "#{message} #{str}"
str
class Listener
constructor: ->
= null
= null
= null
= 1000
= Date.now()
Object.seal @
test: ->
if not utils.isEqual(, , 1)
unless stack.callFunction()
stack.currentTest.onEnd()
return true
if > 0 and Date.now() - >
stack.fail new Error 'unit.whenChange waits too long'
stack.currentTest.onEnd()
return true
false
exports.Scope = Scope
exports.Test = Test
exports.Listener = Listener