1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | runnerModule = require('./runner')
|
8 | Runner = runnerModule.Runner
|
9 | testsuite = require './testsuite'
|
10 | expectation = require './expectation'
|
11 | subprocess = require './subprocess'
|
12 |
|
13 |
|
14 | debug = require('debug')('fbp-spec:mocha')
|
15 |
|
16 | runSuite = (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 |
|
38 |
|
39 |
|
40 | exports.run = (rt, tests, options) ->
|
41 |
|
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 |
|