forked from practicalmeteor/meteor-munit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Munit.coffee
executable file
·120 lines (101 loc) · 3.44 KB
/
Munit.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class Munit
@lastError: null
@wrap: (func)->
chai.expect(func).to.be.a('function')
return ->
Munit.lastError = null
try
func()
catch ex
Munit.lastError = ex
throw ex
@run:(testSuite)->
chai.expect(testSuite).to.be.an('object')
suiteName = testSuite.name || testSuite.constructor.name
suiteSetup = _getSuiteFunction(testSuite,'suiteSetup')
suiteTearDown = _getSuiteFunction(testSuite,'suiteTearDown')
testSetup = _getSuiteFunction(testSuite,"setup")
testTearDown = _getSuiteFunction(testSuite,"tearDown")
arrSuiteTests = _getSuiteTests(testSuite)
if arrSuiteTests.length is 0
return
firstTest = arrSuiteTests.shift() # get first element of an array
lastTest = arrSuiteTests.pop()# get last element of an array
addFirstTest = ->
lvTestAsyncMulti "#{suiteName} - #{firstTest.name}",firstTest.timeout,[
suiteSetup
testSetup
firstTest.func
testTearDown
]
addLastTest = ->
lvTestAsyncMulti "#{suiteName} - #{lastTest.name}",lastTest.timeout,[
testSetup
lastTest.func
testTearDown
suiteTearDown
]
if firstTest and not lastTest
lvTestAsyncMulti "#{suiteName} - #{firstTest.name}",firstTest.timeout,[
suiteSetup
testSetup
firstTest.func
testTearDown
suiteTearDown
]
else if firstTest and lastTest and arrSuiteTests.length is 0
addFirstTest()
addLastTest()
else
addFirstTest()
for test in arrSuiteTests
lvTestAsyncMulti "#{suiteName} - #{test.name}",test.timeout,[
testSetup
test.func
testTearDown
]
addLastTest()
_getSuiteFunction = (testSuite,nameFunc)->
func = testSuite[nameFunc]
return func ?= -> # create an empty function if no exists
_getSuiteTests = (testSuite)->
arrTests = []
suiteTests = testSuite['tests']
if suiteTests
# Convert an object declaration into the standard array format.
if not _.isArray(suiteTests) and _.isObject(suiteTests)
suiteTests = []
for key, test of testSuite['tests']
test = { func:test } if _.isFunction(test)
test.name ?= key
suiteTests.push(test)
testSuite['tests'] = suiteTests
chai.expect(suiteTests).to.be.an('array')
for test in suiteTests
chai.expect(test).to.have.property('name')
chai.expect(test).to.have.property('func')
if not test.skip
test.timeout = test.timeout || 30000
if test.type is "client"
if Meteor.isClient
arrTests.push test
else if test.type is "server"
if Meteor.isServer
arrTests.push test
else
arrTests.push test
for key,func of testSuite
if key isnt "tests" and key.indexOf("test") is 0
expect(func).to.be.a('function')
arrTests.push name:key,func:func,timeout:5000
else if key.indexOf("clientTest") is 0
if Meteor.isClient
expect(func).to.be.a('function')
suiteTestName = key.replace("client","")
arrTests.push name:suiteTestName,func:func,timeout:5000
else if key.indexOf("serverTest") is 0
if Meteor.isServer
expect(func).to.be.a('function')
suiteTestName = key.replace("server","")
arrTests.push name:suiteTestName,func:func,timeout:5000
return arrTests