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

Commit 005185d

Browse files
committed
fix for #9
1 parent 72a337c commit 005185d

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

lib/commands/ls.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pgb-cli",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "nodeJS CLI to PhoneGap Build",
55
"keywords": [
66
"PhoneGap",

src/commands/ls.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const has = require('./helpers/validators')
55
const toTitleCase = (str) => str.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase())
66

77
const print = (data) => {
8-
let diff = Math.max(process.stdout.columns - 80, 0)
9-
let title_length = 15 + diff
8+
let title_length = (15 + Math.max(process.stdout.columns - 80, 0)) || 80
109
let str = ''
1110
let bare = []
1211

test/commands/ls.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
const command = require('../../src/commands/ls')
22
const validators = require('../../src/commands/helpers/validators')
33

4-
describe('qyarn jest', () => {
4+
describe('ls', () => {
55
let apps
66

77
beforeEach(() => {
88
require('../_helpers/pgb')({ commands: [ 'ls' ] })
99
apps = { apps: [
10-
{ id: 1, status: { ios: 'error', android: 'skip', winphone: 'pending' }, last_build: '4 march 1994', foo: 'bar', zig: null },
10+
{ id: 1, title: '123456789012345678901234567890', status: { ios: 'error', android: 'skip', winphone: 'pending' }, last_build: '4 march 1994', foo: 'bar', zig: null },
1111
{ id: 12, status: { ios: 'error', android: 'unknown', winphone: 'complete' }, foo: {a: 12} }
1212
] }
1313
pgb.api.getApps = jest.fn(() => Promise.resolve(apps))
14+
process.stdout.columns = 10
1415
})
1516

1617
afterAll(() => {
1718
delete global.pgb
19+
process.stdout.columns = 10
1820
})
1921

2022
test('should validate', () => {
@@ -26,6 +28,31 @@ describe('qyarn jest', () => {
2628
})
2729

2830
test('should print apps details', () => {
31+
return Promise.resolve()
32+
.then(command)
33+
.then(() => {
34+
let call = pgb.print.mock.calls[0]
35+
expect(call[0].pretty).toMatch(/App Id[^]*1[^]*123456789012\.\.\.[^]*FAILED[^]*SKIPPED[^]*BUILDING[^]*1994-03-04[^]*12[^]*FAILED[^]*BUILDING[^]*SUCCESS/)
36+
expect(call[0].json).toEqual(apps)
37+
expect(call[0].bare).toEqual('1\n12')
38+
expect(pgb.api.getApps).toHaveBeenCalled()
39+
})
40+
})
41+
42+
test('should print apps details even when not stdout.tty', () => {
43+
process.stdout.columns = undefined
44+
return Promise.resolve()
45+
.then(command)
46+
.then(() => {
47+
let call = pgb.print.mock.calls[0]
48+
expect(call[0].pretty).toMatch(/App Id[^]*1[^]*123456789012345678901234567890[^]*FAILED[^]*SKIPPED[^]*BUILDING[^]*1994-03-04[^]*12[^]*FAILED[^]*BUILDING[^]*SUCCESS/)
49+
expect(call[0].json).toEqual(apps)
50+
expect(call[0].bare).toEqual('1\n12')
51+
expect(pgb.api.getApps).toHaveBeenCalled()
52+
})
53+
})
54+
55+
test('should truncate properly if no tty', () => {
2956
return Promise.resolve()
3057
.then(command)
3158
.then(() => {

0 commit comments

Comments
 (0)