1 | path = require 'path'
|
2 | should = require 'should'
|
3 | logger = require 'torch'
|
4 | {spawn, exec} = require 'child_process'
|
5 |
|
6 | rel = (name) -> path.join __dirname, name
|
7 |
|
8 | command = rel '../bin/axiom'
|
9 |
|
10 | sampleProject = rel '../sample/project2'
|
11 |
|
12 | cliRun = (args) ->
|
13 | cli = spawn command, args, {cwd: sampleProject}
|
14 | output = []
|
15 | ['stdout', 'stderr'].forEach (source) ->
|
16 | cli[source].setEncoding 'utf8'
|
17 | cli[source].on 'data', logger.yellow
|
18 | cli[source].on 'data', (message) -> output.push({source, message})
|
19 |
|
20 | return {cli, output}
|
21 |
|
22 | removeTimestamps = (output) ->
|
23 |
|
24 | output.map ({source, message}) ->
|
25 |
|
26 |
|
27 | if /\[.*\].*/.test(message)
|
28 |
|
29 | cutoff = (msg) -> msg.replace /^.*\] /, ''
|
30 |
|
31 |
|
32 | message = cutoff(message)
|
33 |
|
34 | return {source, message}
|
35 |
|
36 | tests = [
|
37 | description: "should fail with a help message if missing 'moduleName'"
|
38 | args: []
|
39 | expected: [
|
40 | source: 'stdout'
|
41 | message: "Missing required positional argument: 'moduleName'\n"
|
42 | ,
|
43 | source: 'stdout'
|
44 | message: 'Usage: axiom <moduleName> <serviceName> [<--arg> <value> ...]\n\n\n'
|
45 | ]
|
46 | ,
|
47 | description: "should fail with a help message if missing 'serviceName'"
|
48 | args: ['hello']
|
49 | expected: [
|
50 | source: 'stdout'
|
51 | message: "Missing required positional argument: 'serviceName'\n"
|
52 | ,
|
53 | source: 'stdout'
|
54 | message: 'Usage: axiom <moduleName> <serviceName> [<--arg> <value> ...]\n\n\n'
|
55 | ]
|
56 | ,
|
57 | description: 'should start the server'
|
58 | args: ['hello', 'world']
|
59 | expected: [{source: 'stdout', message: 'Hello, world!\n'}]
|
60 | ]
|
61 |
|
62 | logTests = [
|
63 | description: "should accept '--log=info'"
|
64 | args: ['hello', 'world', '--log=info']
|
65 | expected: [
|
66 | source: 'stdout'
|
67 | message: 'Hello, world!\n'
|
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 |
|
95 |
|
96 | ]
|
97 |
|
98 | describe 'cli', ->
|
99 | @timeout 2000
|
100 |
|
101 |
|
102 | for test in tests
|
103 | do (test) ->
|
104 |
|
105 | {description, args, expected} = test
|
106 |
|
107 | it description, (done) ->
|
108 |
|
109 | {cli, output} = cliRun args
|
110 |
|
111 | cli.on 'close', ->
|
112 |
|
113 | output.should.eql expected
|
114 |
|
115 | done()
|
116 |
|
117 |
|
118 | for test in logTests
|
119 | do (test) ->
|
120 |
|
121 | {description, args, expected} = test
|
122 |
|
123 | it description, (done) ->
|
124 |
|
125 | {cli, output} = cliRun args
|
126 |
|
127 | cli.on 'close', ->
|
128 |
|
129 |
|
130 | removeTimestamps(output).should.eql expected
|
131 |
|
132 | done()
|