Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
fix dangling variable parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
goya committed Dec 31, 2018
1 parent 6a6b9b8 commit 132c48c
Show file tree
Hide file tree
Showing 28 changed files with 144 additions and 128 deletions.
2 changes: 1 addition & 1 deletion lib/util/args.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pgb-cli",
"version": "1.1.2",
"version": "1.1.3",
"description": "nodeJS CLI to PhoneGap Build",
"keywords": [
"PhoneGap",
Expand Down
2 changes: 1 addition & 1 deletion src/util/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = (opts) => {
if (variable) {
let value = (args.length) ? args.join('=') : rawArgs[++i]
if (opts.variables[key]) {
variables[key] = (variables[key] || []).concat(value.split(','))
variables[key] = (variables[key] || []).concat((value || '').split(','))
} else {
variables[key] = value
}
Expand Down
6 changes: 3 additions & 3 deletions test/commands/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('app', () => {
.then(command)
.then(() => {
expect(validators.args).toHaveBeenLastCalledWith(1)
expect(validators.signed_in).toBeCalled()
expect(validators.signed_in).toHaveBeenCalled()
expect(validators.id).toHaveBeenLastCalledWith('12')
})
})
Expand All @@ -31,7 +31,7 @@ describe('app', () => {
return Promise.resolve()
.then(command)
.then((app) => {
expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } })
expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } })
})
})

Expand All @@ -49,6 +49,6 @@ describe('app', () => {
test('should support completion', () =>
Promise.resolve()
.then(command.completion)
.then(() => expect(complete.app).toBeCalled())
.then(() => expect(complete.app).toHaveBeenCalled())
)
})
22 changes: 11 additions & 11 deletions test/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('build', () => {
return Promise.resolve()
.then(command)
.then(() => {
expect(validators.signed_in).toBeCalled()
expect(validators.signed_in).toHaveBeenCalled()
expect(validators.args).toHaveBeenLastCalledWith(1)
expect(validators.platform).toHaveBeenCalledTimes(2)
expect(validators.id).toHaveBeenLastCalledWith('12')
Expand All @@ -33,9 +33,9 @@ describe('build', () => {
return Promise.resolve()
.then(command)
.then((cmd) => {
expect(pgb.api.buildApp).toBeCalledWith('12', [''])
expect(wait).toBeCalledWith({ id: 12 })
expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } })
expect(pgb.api.buildApp).toHaveBeenCalledWith('12', [''])
expect(wait).toHaveBeenCalledWith({ id: 12 })
expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } })
})
})

Expand All @@ -44,9 +44,9 @@ describe('build', () => {
return Promise.resolve()
.then(command)
.then((cmd) => {
expect(pgb.api.buildApp).toBeCalledWith('12', ['ios'])
expect(wait).toBeCalledWith({ id: 12 })
expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } })
expect(pgb.api.buildApp).toHaveBeenCalledWith('12', ['ios'])
expect(wait).toHaveBeenCalledWith({ id: 12 })
expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } })
})
})

Expand All @@ -55,9 +55,9 @@ describe('build', () => {
return Promise.resolve()
.then(command)
.then((cmd) => {
expect(pgb.api.buildApp).toBeCalledWith('12', ['ios', 'winphone', 'android'])
expect(wait).toBeCalledWith({ id: 12 })
expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } })
expect(pgb.api.buildApp).toHaveBeenCalledWith('12', ['ios', 'winphone', 'android'])
expect(wait).toHaveBeenCalledWith({ id: 12 })
expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12, 'wait': true } })
})
})

Expand All @@ -75,6 +75,6 @@ describe('build', () => {
test('should support completion', () =>
Promise.resolve()
.then(command.completion)
.then(() => expect(complete.appAndPlatform).toBeCalled())
.then(() => expect(complete.appAndPlatform).toHaveBeenCalled())
)
})
2 changes: 1 addition & 1 deletion test/commands/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('build', () => {
.then(command)
.then(() => {
expect(console.log).not.toHaveBeenCalledWith('')
expect(pgb.debug).toBeCalledWith(new Error('an error'))
expect(pgb.debug).toHaveBeenCalledWith(new Error('an error'))
})
})

Expand Down
24 changes: 12 additions & 12 deletions test/commands/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('download', () => {
.then(command)
.then(() => {
expect(validators.args).toHaveBeenLastCalledWith(2)
expect(validators.signed_in).toBeCalled()
expect(validators.signed_in).toHaveBeenCalled()
expect(validators.platform).toHaveBeenLastCalledWith('ios', true)
})
})
Expand All @@ -30,7 +30,7 @@ describe('download', () => {
return Promise.resolve()
.then(command)
.then(() => {
expect(pgb.api.downloadApp).toBeCalledWith('12', 'ios', '.')
expect(pgb.api.downloadApp).toHaveBeenCalledWith('12', 'ios', '.')
})
})

Expand All @@ -39,7 +39,7 @@ describe('download', () => {
return Promise.resolve()
.then(command)
.then(() => {
expect(pgb.api.downloadApp).toBeCalledWith('12', 'ios', '/foo')
expect(pgb.api.downloadApp).toHaveBeenCalledWith('12', 'ios', '/foo')
})
})

Expand All @@ -53,14 +53,14 @@ describe('download', () => {
return Promise.resolve()
.then(command)
.then(() => {
expect(pgb.print).not.toBeCalled()
expect(pgb.print).not.toHaveBeenCalled()
let call = pgb.api.downloadApp.mock.calls[0]
expect(call[0]).toBe('12')
expect(call[1]).toBe('ios')
expect(call[2]).toBeInstanceOf(require('stream').Writable)
expect(call[2]).toMatchObject({ _isStdio: true })
expect(Progress).not.toBeCalledWith('downloading ', 100, 60)
expect(pgb.print).not.toBeCalled()
expect(Progress).not.toHaveBeenCalledWith('downloading ', 100, 60)
expect(pgb.print).not.toHaveBeenCalled()
})
})

Expand All @@ -74,10 +74,10 @@ describe('download', () => {
return Promise.resolve()
.then(command)
.then(() => {
expect(Progress.mock.instances[0].update).toBeCalledWith(100, '100 B / 100 B')
expect(Progress.mock.instances[0].stop).toBeCalledWith()
expect(pgb.api.downloadApp).toBeCalledWith('12', 'ios', '.')
expect(Progress).toBeCalledWith('downloading ', 100, 40)
expect(Progress.mock.instances[0].update).toHaveBeenCalledWith(100, '100 B / 100 B')
expect(Progress.mock.instances[0].stop).toHaveBeenCalledWith()
expect(pgb.api.downloadApp).toHaveBeenCalledWith('12', 'ios', '.')
expect(Progress).toHaveBeenCalledWith('downloading ', 100, 40)
})
})

Expand All @@ -90,7 +90,7 @@ describe('download', () => {
.then(command)
.then(done.fail)
.catch(() => {
expect(Progress).not.toBeCalledWith()
expect(Progress).not.toHaveBeenCalledWith()
done()
})
})
Expand All @@ -107,6 +107,6 @@ describe('download', () => {
test('should support completion', () =>
Promise.resolve()
.then(command.completion)
.then(() => expect(complete.appAndPlatform).toBeCalled())
.then(() => expect(complete.appAndPlatform).toHaveBeenCalled())
)
})
22 changes: 11 additions & 11 deletions test/commands/helpers/bind-progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,47 @@ describe('bind-progress', () => {

test('should debug files on zip/files event', () => {
process.emit('zip/files', { foo: 'bar' })
expect(pgb.debug).toBeCalledWith({ foo: 'bar' })
expect(pgb.debug).toHaveBeenCalledWith({ foo: 'bar' })
})

test('should stop progress on end events', () => {
process.emit('api/write', { size: 2000000, pos: 25 })
process.emit('zip/write', { size: 2000000, pos: 25 })
process.emit('api/connect')
process.emit('zip/end')
expect(Progress.mock.instances[0].stop).toBeCalledWith()
expect(Progress.mock.instances[1].stop).toBeCalledWith()
expect(Progress.mock.instances[0].stop).toHaveBeenCalledWith()
expect(Progress.mock.instances[1].stop).toHaveBeenCalledWith()
})

test('should instantiate and/or update progress on api/write', () => {
process.emit('api/write', { size: 2000000, pos: 25 })
process.emit('api/write', { size: 2000000, pos: 25 })
expect(Progress).toBeCalledWith('uploading ', 2000000, 40)
expect(Progress.mock.instances[0].update).toBeCalledWith(25, '25 B / 1.9 MB')
expect(Progress).toHaveBeenCalledWith('uploading ', 2000000, 40)
expect(Progress.mock.instances[0].update).toHaveBeenCalledWith(25, '25 B / 1.9 MB')
})

test('should not instantiate and/or update progress on api/write if too small', () => {
process.emit('api/write', { size: 100, pos: 25 })
expect(Progress).not.toBeCalledWith()
expect(Progress).not.toHaveBeenCalledWith()
})

test('should instantiate and/or update progress on api/write if too small but has zipper', () => {
process.emit('zip/write', { size: 2000000, pos: 25 })
expect(Progress.mock.instances[0].update).toBeCalledWith(25, '25 B / 1.9 MB')
expect(Progress.mock.instances[0].update).toHaveBeenCalledWith(25, '25 B / 1.9 MB')
process.emit('api/write', { size: 100, pos: 22 })
expect(Progress.mock.instances[1].update).toBeCalledWith(22, '22 B / 100 B')
expect(Progress.mock.instances[1].update).toHaveBeenCalledWith(22, '22 B / 100 B')
})

test('should not instantiate and/or update progress on api/write if noprogress', () => {
pgb.opts.noprogress = true
process.emit('api/write', { size: 2000000, pos: 25 })
expect(Progress).not.toBeCalledWith()
expect(Progress).not.toHaveBeenCalledWith()
})

test('should instantiate and/or update progress on zip/write', () => {
process.emit('zip/write', { size: 200000, pos: 25 })
process.emit('zip/write', { size: 200000, pos: 25 })
expect(Progress).toBeCalledWith('archiving ', 200000, 40)
expect(Progress).toHaveBeenCalledWith('archiving ', 200000, 40)
})

test('should not bind events if noprogress', () => {
Expand All @@ -84,6 +84,6 @@ describe('bind-progress', () => {
bindProgress = BindProgress()
process.emit('zip/write', { size: 2000000, pos: 25 })
expect(process.eventNames()).not.toContain(['zip/files', 'zip/end', 'api/connect', 'zip/write', 'api/write'])
expect(Progress).not.toBeCalled()
expect(Progress).not.toHaveBeenCalled()
})
})
6 changes: 3 additions & 3 deletions test/commands/helpers/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('complete', () => {
.then(complete.app)
.then((result) => {
expect(result).toEqual([12, 13])
expect(pgb.api.getApps).toBeCalledWith()
expect(pgb.api.getApps).toHaveBeenCalledWith()
})
})

Expand All @@ -36,7 +36,7 @@ describe('complete', () => {
.then(complete.appAndPlatform)
.then((result) => {
expect(result).toEqual([12, 13])
expect(pgb.api.getApps).toBeCalledWith()
expect(pgb.api.getApps).toHaveBeenCalledWith()
})
})

Expand Down Expand Up @@ -67,7 +67,7 @@ describe('complete', () => {
.then(complete.key)
.then((result) => {
expect(result).toEqual([12, 13])
expect(pgb.api.getKeys).toBeCalledWith('ios')
expect(pgb.api.getKeys).toHaveBeenCalledWith('ios')
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/commands/helpers/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('validators', () => {
jest.mock('../../../src/commands/usage')
expect(pgb.opts.short_usage).toBeFalsy()
expect(() => validators.args(1)).toThrow('')
expect(pgb.error).lastCalledWith('command requires 1 argument(s)')
expect(pgb.error).toHaveBeenLastCalledWith('command requires 1 argument(s)')
expect(pgb.opts.short_usage).toBeTruthy()
pgb.opts = { commands: ['cmd', 'arg1'] }
expect(() => validators.args(1)).not.toThrow()
Expand Down
20 changes: 10 additions & 10 deletions test/commands/helpers/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe('progress', () => {
return wait({ id: 12, package: 'com.example', status: {}, error: {}, completed: true })
.then((app) => {
expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: {}, completed: true })
expect(pgb.api.getApp).not.toBeCalled()
expect(pgb.api.getStatus).not.toBeCalled()
expect(pgb.api.getApp).not.toHaveBeenCalled()
expect(pgb.api.getStatus).not.toHaveBeenCalled()
})
})

Expand All @@ -33,8 +33,8 @@ describe('progress', () => {
return wait({ id: 12, package: 'com.example', status: {}, error: {}, completed: true })
.then((app) => {
expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: {}, completed: true })
expect(pgb.api.getApp).not.toBeCalled()
expect(pgb.api.getStatus).not.toBeCalled()
expect(pgb.api.getApp).not.toHaveBeenCalled()
expect(pgb.api.getStatus).not.toHaveBeenCalled()
})
})

Expand All @@ -44,8 +44,8 @@ describe('progress', () => {
.then(done.fail)
.catch((err) => {
expect(err).toEqual(new Error())
expect(pgb.api.getApp).not.toBeCalled()
expect(pgb.api.getStatus).not.toBeCalled()
expect(pgb.api.getApp).not.toHaveBeenCalled()
expect(pgb.api.getStatus).not.toHaveBeenCalled()
done()
})
})
Expand All @@ -55,8 +55,8 @@ describe('progress', () => {
return wait({ id: 12, package: 'com.example', status: {}, error: { }, completed: true })
.then((app) => {
expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: { }, completed: true })
expect(pgb.api.getApp).not.toBeCalled()
expect(pgb.api.getStatus).not.toBeCalled()
expect(pgb.api.getApp).not.toHaveBeenCalled()
expect(pgb.api.getStatus).not.toHaveBeenCalled()
expect(stdout.flush().stderr).toHaveLength(1)
})
})
Expand All @@ -66,8 +66,8 @@ describe('progress', () => {
return wait({ id: 12, package: 'com.example', status: {}, error: { android: 'bad' }, completed: true })
.then((app) => {
expect(app).toEqual({ id: 12, package: 'com.example', status: {}, error: { android: 'bad' }, completed: true })
expect(pgb.api.getApp).not.toBeCalled()
expect(pgb.api.getStatus).not.toBeCalled()
expect(pgb.api.getApp).not.toHaveBeenCalled()
expect(pgb.api.getStatus).not.toHaveBeenCalled()
expect(stdout.flush().stderr).toHaveLength(1)
})
})
Expand Down
8 changes: 4 additions & 4 deletions test/commands/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('key', () => {
.then(command)
.then(() => {
expect(validators.args).toHaveBeenLastCalledWith(2)
expect(validators.signed_in).toBeCalled()
expect(validators.signed_in).toHaveBeenCalled()
expect(validators.key_platform).toHaveBeenLastCalledWith('ios', true)
expect(validators.id).toHaveBeenLastCalledWith('12')
})
Expand All @@ -28,8 +28,8 @@ describe('key', () => {
return Promise.resolve()
.then(command)
.then(() => {
expect(pgb.print).toBeCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } })
expect(pgb.api.getKey).toBeCalledWith('ios', '12')
expect(pgb.print).toHaveBeenCalledWith({ 'bare': 12, 'json': { 'id': 12 }, 'pretty': { 'id': 12 } })
expect(pgb.api.getKey).toHaveBeenCalledWith('ios', '12')
})
})

Expand All @@ -47,6 +47,6 @@ describe('key', () => {
test('should support completion', () =>
Promise.resolve()
.then(command.completion)
.then(() => expect(complete.key).toBeCalledWith(true))
.then(() => expect(complete.key).toHaveBeenCalledWith(true))
)
})
4 changes: 2 additions & 2 deletions test/commands/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('keys', () => {
return Promise.resolve()
.then(command)
.then(() => {
expect(validators.signed_in).toBeCalled()
expect(validators.signed_in).toHaveBeenCalled()
expect(validators.key_platform).toHaveBeenLastCalledWith(undefined, false)
})
})
Expand Down Expand Up @@ -83,6 +83,6 @@ describe('keys', () => {
test('should support completion', () =>
Promise.resolve()
.then(command.completion)
.then(() => expect(complete.platform).toBeCalledWith(true))
.then(() => expect(complete.platform).toHaveBeenCalledWith(true))
)
})
Loading

0 comments on commit 132c48c

Please sign in to comment.