UNPKG

2.24 kBtext/coffeescriptView Raw
1fbpspec = require 'fbp-spec/src/index' if not fbpspec
2widgets = fbpspec.ui.widgets
3
4# DOM helpers
5id = (name) ->
6 document.getElementById name
7
8parseQuery = (querystring) ->
9 querystring = querystring.substring(querystring.indexOf('?')+1).split('&')
10 params = {}
11 for i in [querystring.length-1..0] by -1
12 pair = querystring[i].split '='
13 k = decodeURIComponent pair[0]
14 v = decodeURIComponent pair[1]
15 if params[k]
16 params[k] = [ params[k] ] if not Array.isArray params[k]
17 params[k].push v
18 else
19 params[k] = v
20 return params
21
22getOptions = (query) ->
23 query = window.location.toString() if not query
24 options =
25 secret: null
26 protocol: 'websocket'
27 port: null
28 host: 'localhost'
29 scheme: null
30 test: []
31 # TODO: also allow to specify host/port instead of address?
32 params = parseQuery query
33 for k, v of params
34 options[k] = v
35
36 if options.protocol == 'websocket'
37 options.port = 3569 if not options.port
38 options.scheme = 'ws' if not options.scheme
39 options.address = "#{options.scheme}://#{options.host}:#{options.port}"
40
41 options.port = 80 if not options.port
42
43 options.test = [ options.test ] if not Array.isArray options.test
44
45 return options
46
47# Main
48main = () ->
49 console.log 'main'
50
51 onTestsChanged = (suites) ->
52 React.render (widgets.TestsListing {suites: suites}), id('listing')
53 React.render (widgets.TestStatus {suites: suites}), id('status')
54 console.log 'rendered'
55
56 # Runtime should be started in advance. Normally done by Grunt
57 options = getOptions()
58 console.log 'o', options
59
60 runTests = () ->
61 runner = new fbpspec.runner.Runner options
62 runner.client.setParentElement id('runtime') if runner.client.setParentElement # iframe support
63
64 fbpspec.testsuite.getSuites options.test, (err, suites) ->
65 console.log 'loaded', err
66 onTestsChanged suites # initial render
67
68 runner.connect (err) ->
69 console.log 'connected', err
70 fbpspec.runner.runAll runner, suites, onTestsChanged, (err) ->
71 console.log 'test run done'
72 runner.disconnect (err) ->
73 console.log 'disconnected'
74
75 id('runButton').onclick = runTests
76 setTimeout runTests, 100
77 console.log 'main done'
78
79main()