-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathConsoleReporter.coffee
executable file
·95 lines (71 loc) · 2.9 KB
/
ConsoleReporter.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
{ObjectLogger} = require("meteor/practicalmeteor:loglevel")
{MochaRunner, ClientServerBaseReporter} = require("meteor/practicalmeteor:mocha")
log = new ObjectLogger('ConsoleReporter', 'info')
class ConsoleReporter extends ClientServerBaseReporter
@VERSION: "0.2.2"
constructor: (@clientRunner, @serverRunner, @options)->
try
log.enter('constructor')
super(@clientRunner, @serverRunner, @options)
MochaRunner.on "end all", => @finishAndPrintTestsSummary()
finally
log.return()
###
Overwriting from ClientServerBaseReporter
###
registerRunnerEvents: (where)->
try
log.enter("registerRunnerEvents")
# Call super.registerRunnerEvents to register events from ClientServerBaseReporter first
super(where)
@["#{where}Runner"].on "start", => @printReporterHeader(where)
@["#{where}Runner"].on 'test end', (test)=> @printTest(test, where)
# Log for errors with hooks
@["#{where}Runner"].on "fail", (hook)=> @printTest(hook, where) if hook.type is 'hook'
finally
log.return()
printReporterHeader: (where)=>
try
log.enter("printReporterHeader", where)
return if @options.runOrder isnt 'serial'
# i.e client = Client
where = where[0].toUpperCase() + where.substr(1)
console.log("\n--------------------------------------------------")
console.log("------------------ #{where} tests ------------------")
console.log("--------------------------------------------------\n")
finally
log.return()
printTest: (test, where)->
try
log.enter("prinTest", test)
state = test.state or (if test.pending then "pending")
# Since the test are running in parallel we don't need
# to specify where they are client or server tests.
if @options.runOrder is 'serial'
where = ""
else
# Get first chart 's' or 'c' for client/server
where = where[0].toUpperCase() + ": "
console.log("#{where}#{test.fullTitle()} : #{state}")
if test.state is "failed"
console.log(" " + (test.err.stack || test.err))
console.log("")
finally
log.return()
finishAndPrintTestsSummary: ()=>
try
log.enter("finishAndPrintTestsSummary")
return if not @clientStats?.total? or not @serverStats?.total?
console.log("\n--------------------------------------------------")
console.log("---------------------RESULTS----------------------")
console.log("PASSED:", @stats.passes)
console.log("FAILED:", @stats.failures)
console.log("SKIPPED:", @stats.pending)
console.log("TOTAL:", @stats.total)
console.log("--------------------------------------------------")
console.log("--------------------------------------------------\n")
finally
log.return()
module.exports.ConsoleReporter = ConsoleReporter
module.exports.runTests = () ->
MochaRunner.setReporter(ConsoleReporter)