UNPKG

2.47 kBtext/coffeescriptView Raw
1
2## Run fbp-spec testcases using Mocha as a runner/frontend
3## Intended to allow reuse of Mocha reporters, or
4## to quickly add a couple of fbp-spec cases to a predominantly Mocha-based testsuite
5## See also ./mochacompat.coffee
6
7runnerModule = require('./runner')
8Runner = runnerModule.Runner
9testsuite = require './testsuite'
10expectation = require './expectation'
11subprocess = require './subprocess'
12
13
14debug = require('debug')('fbp-spec:mocha')
15
16runSuite = (runner, suite) ->
17
18 suiteDescribe = if suite.skip then describe.skip else describe
19 suiteDescribe "#{suite.name}", ->
20 beforeEach (done) ->
21 @timeout suite.timeout if suite.timeout?
22 runner.setupSuite suite, done
23 afterEach (done) ->
24 runner.teardownSuite suite, done
25
26 suite.cases.forEach (testcase) ->
27 caseDescribe = if testcase.skip then describe.skip else describe
28 caseDescribe testcase.name, ->
29 it testcase.assertion, (done) ->
30 @timeout suite.timeout if suite.timeout?
31 @timeout testcase.timeout if testcase.timeout?
32
33 runnerModule.runTestAndCheck runner, testcase, (err, result) ->
34 return done err if err
35 return done result.error
36
37## run()
38# Must be be ran using Mocha,
39# it is responsible for setting up the "describe", and "it" functions
40exports.run = (rt, tests, options) ->
41 # default pretty high to give time for runtime to start
42 options.starttimeout = 5000 if not options.starttimeout?
43 options.fixturetimeout = 2000 if not options.fixturetimeout?
44
45 runnerOptions =
46 connectTimeout: options.starttimeout
47 commandTimeout: options.commandtimeout
48 runner = new Runner rt, runnerOptions
49 try
50 suites = testsuite.getSuitesSync tests
51 catch e
52 console.log 'Unable to get suites:', e
53 throw e
54 process = null
55
56 start = (callback) ->
57 return callback null if not rt.command
58 subprocessOptions = {}
59 process = subprocess.start rt.command, subprocessOptions, callback
60 stop = (callback) ->
61 process.kill() if process
62 return callback null
63
64 before (done) ->
65 @timeout options.starttimeout+500
66 start (err) ->
67 debug 'started', err
68 expectation.noError err
69 runner.connect done
70 return null
71 after (done) ->
72 stop (err) ->
73 debug 'stopped', err
74 expectation.noError err
75 runner.disconnect done
76 return null
77
78 for suite in suites
79 suite.timeout = options.fixturetimeout if not suite.timeout?
80 runSuite runner, suite
81