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 |
|
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 'extensionName'"
|
38 | args: []
|
39 | expected: [
|
40 | source: 'stdout'
|
41 | message: "Missing required argument: 'extensionName'\n"
|
42 | ,
|
43 | source: 'stdout'
|
44 | message: 'Usage: axiom <extensionName> <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 argument: 'serviceName'\n"
|
52 | ,
|
53 | source: 'stdout'
|
54 | message: 'Usage: axiom <extensionName> <serviceName> [<--arg> <value> ...]\n\n\n'
|
55 | ]
|
56 | ,
|
57 | description: 'should start the server'
|
58 | args: ['hello', 'world']
|
59 | expected: [
|
60 | {source: 'stdout', message: 'Hello, world!\n'}
|
61 | {source: 'stdout', message: 'Success!\n'}
|
62 | ]
|
63 | description: 'should pass args'
|
64 | args: ['hello', 'args', '--hello.foo=1']
|
65 | expected: [
|
66 | {source: 'stdout', message: '{ foo: 1 }\n'}
|
67 | {source: 'stdout', message: 'Success!\n'}
|
68 | ]
|
69 | ]
|
70 |
|
71 | logTests = [
|
72 | description: "should accept '--log=info'"
|
73 | args: ['hello', 'world', '--log=info']
|
74 | expected: [
|
75 | {source: 'stdout', message: 'Hello, world!\n'}
|
76 | {source: 'stdout', message: 'Success!\n'}
|
77 | ]
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | ]
|
106 |
|
107 | describe 'cli', ->
|
108 | @timeout 2000
|
109 |
|
110 |
|
111 | for test in tests
|
112 | do (test) ->
|
113 |
|
114 | {description, args, expected} = test
|
115 |
|
116 | it description, (done) ->
|
117 |
|
118 | {cli, output} = cliRun args
|
119 |
|
120 | cli.on 'close', ->
|
121 |
|
122 | output.should.eql expected
|
123 |
|
124 | done()
|
125 |
|
126 |
|
127 | for test in logTests
|
128 | do (test) ->
|
129 |
|
130 | {description, args, expected} = test
|
131 |
|
132 | it description, (done) ->
|
133 |
|
134 | {cli, output} = cliRun args
|
135 |
|
136 | cli.on 'close', ->
|
137 |
|
138 |
|
139 | removeTimestamps(output).should.eql expected
|
140 |
|
141 | done()
|