This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathmocha-runner
More file actions
executable file
·69 lines (43 loc) · 1.52 KB
/
mocha-runner
File metadata and controls
executable file
·69 lines (43 loc) · 1.52 KB
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
#!/usr/bin/env coffee
# this file instantiates mocha runner and runs test.coffee files in a directory
{ join } = require('path')
fs = require('fs')
Mocha = require('mocha')
addTestFilesToMocha = (mocha, path) ->
# if the given path is not a directory add the file and return
unless fs.statSync(path).isDirectory()
mocha.addFile path
return
fs.readdirSync(path).filter (file) ->
fullFilePath = join path, file
# Recursive call in case file is a directory
if fs.statSync(fullFilePath).isDirectory()
addTestFilesToMocha mocha, fullFilePath
# Only keep the test.coffee files
return file.substr(-11) is 'test.coffee'
.forEach (file) ->
# Use the method "addFile" to add the test file to mocha
mocha.addFile join(path, file)
runMocha = (mocha) ->
mocha.run (failures) ->
console.log "mochaRunner failures = (#{failures})"
process.exit failures
addEventListenersToRunner = (runner) ->
runner.on 'fail', (test) ->
console.log "failed on #{test.title} err:#{test.err}"
# instantiates mocha runner, adds test files and event listeners to runner
start = ->
unless path = process.argv[2]
console.error 'test path is not specified'
process.exit 1
# instantiating mocha instance
mocha = new Mocha
slow : 200
timeout : 30000
reporter : 'koding'
# adding test files which will be executed
addTestFilesToMocha mocha, path
# running mocha, returns a runner instance
runner = runMocha mocha
addEventListenersToRunner runner
start()