Skip to content

Commit b5487f0

Browse files
committed
fix: allow multiple command to be passed #163 + strengthen tests
1 parent 449e629 commit b5487f0

2 files changed

Lines changed: 32 additions & 28 deletions

File tree

deploy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ var path = require('path');
1212
* @callback cb
1313
*/
1414
function spawn(hostJSON, args, cb) {
15-
var shellSyntaxCommand = "echo '" + hostJSON + "' | \"" + __dirname.replace(/\\/g, '/') + "/deploy\" " + args.join(' ');
15+
var shellSyntaxCommand = "echo '" + hostJSON + "' | \"" + __dirname.replace(/\\/g, '/') + "/deploy\" "
16+
17+
if (args.length > 0)
18+
shellSyntaxCommand += '"' + args.join('" "') + '"';
19+
1620
var proc = childProcess.spawn('sh', ['-c', shellSyntaxCommand], { stdio: 'inherit' });
1721
var error;
1822

test/deploy.mocha.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ describe('deploy', function() {
3939
})
4040

4141
it('is a function', function() {
42-
deploy.deployForEnv.should.be.a.Function
42+
deploy.deployForEnv.should.be.a.Function()
4343
})
4444

45-
it('returns false', function() {
45+
it('returns false()', function() {
4646
var ret = deploy.deployForEnv(conf, 'staging', [], function() {})
47-
ret.should.be.false
47+
ret.should.be.false()
4848
})
4949

5050
describe('deploy_conf validation', function() {
5151
it('validate user', function(done) {
5252
conf.staging.user = '';
5353
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
54-
err.should.be.an.Object
54+
err.should.be.an.Object()
5555
err.code.should.equal(200)
5656
err.message.should.match('String is too short (0 chars), minimum 1')
5757
done()
@@ -61,7 +61,7 @@ describe('deploy', function() {
6161
it('requires host', function(done) {
6262
delete conf.staging.host
6363
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
64-
err.should.be.an.Object
64+
err.should.be.an.Object()
6565
err.code.should.equal(302)
6666
err.message.should.match('Missing required property: host')
6767
done()
@@ -71,7 +71,7 @@ describe('deploy', function() {
7171
it('requires repo', function(done) {
7272
delete conf.staging.repo
7373
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
74-
err.should.be.an.Object
74+
err.should.be.an.Object()
7575
err.code.should.equal(302)
7676
err.message.should.match('Missing required property: repo')
7777
done()
@@ -81,7 +81,7 @@ describe('deploy', function() {
8181
it('requires path', function(done) {
8282
delete conf.staging.path
8383
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
84-
err.should.be.an.Object
84+
err.should.be.an.Object()
8585
err.code.should.equal(302)
8686
err.message.should.match('Missing required property: path')
8787
done()
@@ -91,7 +91,7 @@ describe('deploy', function() {
9191
it('requires ref', function(done) {
9292
delete conf.staging.ref
9393
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
94-
err.should.be.an.Object
94+
err.should.be.an.Object()
9595
err.code.should.equal(302)
9696
err.message.should.match('Missing required property: ref')
9797
done()
@@ -119,7 +119,7 @@ describe('deploy', function() {
119119
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
120120
spawnCalls.length.should.equal(1)
121121
spawnCalls[0][0].should.equal('sh')
122-
spawnCalls[0][1].should.be.an.Array
122+
spawnCalls[0][1].should.be.an.Array()
123123
spawnCalls[0][1][0].should.equal('-c')
124124
done()
125125
})
@@ -131,16 +131,16 @@ describe('deploy', function() {
131131
})
132132
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
133133
spawnCalls.length.should.equal(1)
134-
spawnCalls[0][1][1].should.be.a.String
134+
spawnCalls[0][1][1].should.be.a.String()
135135

136136
var pipeFrom = spawnCalls[0][1][1].split(/\s*\|\s*/)[0]
137-
pipeFrom.should.be.ok
137+
pipeFrom.should.be.ok()
138138

139139
var echoJSON = pipeFrom.match(/^echo '(.+?)'/)[1]
140-
echoJSON.should.be.ok
140+
echoJSON.should.be.ok()
141141

142142
var echoData = JSON.parse(echoJSON)
143-
echoData.should.be.an.Object
143+
echoData.should.be.an.Object()
144144
echoData.ref.should.eql(conf.staging.ref)
145145
echoData.user.should.eql(conf.staging.user)
146146
echoData.repo.should.eql(conf.staging.repo)
@@ -151,7 +151,7 @@ describe('deploy', function() {
151151
conf.staging.env = { a: 1, b: 2 }
152152
deploy.deployForEnv(conf, 'staging', [], function() {
153153
spawnCalls.length.should.equal(2)
154-
spawnCalls[1][1][1].should.be.a.String
154+
spawnCalls[1][1][1].should.be.a.String()
155155
echoData = JSON.parse( spawnCalls[1][1][1].match(/^echo '(.+?)'/)[1] )
156156
echoData['post-deploy'].should.eql(
157157
'export A=1 B=2 && ' + conf.staging['post-deploy']
@@ -160,7 +160,7 @@ describe('deploy', function() {
160160
conf.staging['post-deploy'] = ''
161161
deploy.deployForEnv(conf, 'staging', [], function() {
162162
spawnCalls.length.should.equal(3)
163-
spawnCalls[2][1][1].should.be.a.String
163+
spawnCalls[2][1][1].should.be.a.String()
164164
echoData = JSON.parse( spawnCalls[2][1][1].match(/^echo '(.+?)'/)[1] )
165165
echoData['post-deploy'].should.eql('export A=1 B=2')
166166
done()
@@ -175,9 +175,9 @@ describe('deploy', function() {
175175
})
176176
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
177177
spawnCalls.length.should.equal(1)
178-
spawnCalls[0][1][1].should.be.a.String
178+
spawnCalls[0][1][1].should.be.a.String()
179179
var pipeTo = spawnCalls[0][1][1].split(/\s*\|\s*/)[1]
180-
pipeTo.should.be.ok
180+
pipeTo.should.be.ok()
181181
pipeTo.should.match(/\/deploy"\s*$/)
182182
done()
183183
})
@@ -192,7 +192,7 @@ describe('deploy', function() {
192192
proc.emit('close', 1)
193193
})
194194
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
195-
err.should.be.a.String
195+
err.should.be.an.Object()
196196
err.stack.should.eql(error.stack)
197197
done()
198198
})
@@ -205,7 +205,7 @@ describe('deploy', function() {
205205
proc.emit('close', 1)
206206
})
207207
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
208-
err.should.be.an.Object
208+
err.should.be.an.Object()
209209
err.should.eql(error)
210210
done()
211211
})
@@ -239,13 +239,13 @@ describe('deploy', function() {
239239

240240
spawnNotifier.on('spawned', function(proc) {
241241
var pipeFrom = spawnCalls[spawnCount][1][1].split(/\s*\|\s*/)[0]
242-
pipeFrom.should.be.ok
242+
pipeFrom.should.be.ok()
243243

244244
var echoJSON = pipeFrom.match(/^echo '(.+?)'/)[1]
245-
echoJSON.should.be.ok
245+
echoJSON.should.be.ok()
246246

247247
var echoData = JSON.parse(echoJSON)
248-
echoData.should.be.an.Object
248+
echoData.should.be.an.Object()
249249

250250
echoData.ref.should.eql(conf.staging.ref)
251251
echoData.repo.should.eql(conf.staging.repo)
@@ -271,13 +271,13 @@ describe('deploy', function() {
271271

272272
spawnNotifier.on('spawned', function(proc) {
273273
var pipeFrom = spawnCalls[spawnCount][1][1].split(/\s*\|\s*/)[0]
274-
pipeFrom.should.be.ok
274+
pipeFrom.should.be.ok()
275275

276276
var echoJSON = pipeFrom.match(/^echo '(.+?)'/)[1]
277-
echoJSON.should.be.ok
277+
echoJSON.should.be.ok()
278278

279279
var echoData = JSON.parse(echoJSON)
280-
echoData.should.be.an.Object
280+
echoData.should.be.an.Object()
281281

282282
echoData.ref.should.eql(conf.staging.ref)
283283
echoData.repo.should.eql(conf.staging.repo)
@@ -306,7 +306,7 @@ describe('deploy', function() {
306306
})
307307

308308
deploy.deployForEnv(conf, 'staging', argsIn, function(err, argsOut) {
309-
argsOut.should.be.an.Array
309+
argsOut.should.be.an.Array()
310310
argsOut.length.should.eql(4)
311311
argsOut[0].should.eql(argsIn)
312312
argsOut[1].should.eql(argsIn)
@@ -324,7 +324,7 @@ describe('deploy', function() {
324324
proc.emit('close', 1)
325325
})
326326
deploy.deployForEnv(conf, 'staging', [], function(err, args) {
327-
err.should.be.an.Object
327+
err.should.be.an.Object()
328328
err.should.eql(error)
329329
spawnCalls.length.should.eql(1)
330330
done()

0 commit comments

Comments
 (0)