1
+ 'use strict'
2
+
1
3
/* global describe, it */
2
4
3
5
require ( 'chai' ) . should ( )
4
6
5
7
// Force chalk to enable color, if it's disabled the test fails.
6
8
process . env [ 'FORCE_COLOR' ] = 1
7
9
8
- var chalk = require ( 'chalk' )
9
- var cliui = require ( '../' )
10
- var stripAnsi = require ( 'strip-ansi' )
10
+ const chalk = require ( 'chalk' )
11
+ const cliui = require ( '../' )
12
+ const stripAnsi = require ( 'strip-ansi' )
11
13
12
- describe ( 'cliui' , function ( ) {
13
- describe ( 'resetOutput' , function ( ) {
14
- it ( 'should set lines to empty' , function ( ) {
15
- var ui = cliui ( )
14
+ describe ( 'cliui' , ( ) => {
15
+ describe ( 'resetOutput' , ( ) => {
16
+ it ( 'should set lines to empty' , ( ) => {
17
+ const ui = cliui ( )
16
18
ui . div ( 'i am a value that would be in a line' )
17
19
ui . resetOutput ( )
18
20
ui . toString ( ) . length . should . be . equal ( 0 )
19
21
} )
20
22
} )
21
23
22
- describe ( 'div' , function ( ) {
23
- it ( "wraps text at 'width' if a single column is given" , function ( ) {
24
- var ui = cliui ( {
24
+ describe ( 'div' , ( ) => {
25
+ it ( "wraps text at 'width' if a single column is given" , ( ) => {
26
+ const ui = cliui ( {
25
27
width : 10
26
28
} )
27
29
28
30
ui . div ( 'i am a string that should be wrapped' )
29
31
30
- ui . toString ( ) . split ( '\n' ) . forEach ( function ( row ) {
32
+ ui . toString ( ) . split ( '\n' ) . forEach ( row => {
31
33
row . length . should . be . lte ( 10 )
32
34
} )
33
35
} )
34
36
35
- it ( 'evenly divides text across columns if multiple columns are given' , function ( ) {
36
- var ui = cliui ( {
37
+ it ( 'evenly divides text across columns if multiple columns are given' , ( ) => {
38
+ const ui = cliui ( {
37
39
width : 40
38
40
} )
39
41
@@ -45,12 +47,12 @@ describe('cliui', function () {
45
47
46
48
// total width of all columns is <=
47
49
// the width cliui is initialized with.
48
- ui . toString ( ) . split ( '\n' ) . forEach ( function ( row ) {
50
+ ui . toString ( ) . split ( '\n' ) . forEach ( row => {
49
51
row . length . should . be . lte ( 40 )
50
52
} )
51
53
52
54
// it should wrap each column appropriately.
53
- var expected = [
55
+ const expected = [
54
56
'i am a string i am a i am a third' ,
55
57
'that should be second string that' ,
56
58
'wrapped string that should be' ,
@@ -61,80 +63,80 @@ describe('cliui', function () {
61
63
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
62
64
} )
63
65
64
- it ( 'allows for a blank row to be appended' , function ( ) {
65
- var ui = cliui ( {
66
+ it ( 'allows for a blank row to be appended' , ( ) => {
67
+ const ui = cliui ( {
66
68
width : 40
67
69
} )
68
70
69
71
ui . div ( )
70
72
71
73
// it should wrap each column appropriately.
72
- var expected = [ '' ]
74
+ const expected = [ '' ]
73
75
74
76
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
75
77
} )
76
78
} )
77
79
78
- describe ( '_columnWidths' , function ( ) {
79
- it ( 'uses same width for each column by default' , function ( ) {
80
- var ui = cliui ( {
80
+ describe ( '_columnWidths' , ( ) => {
81
+ it ( 'uses same width for each column by default' , ( ) => {
82
+ const ui = cliui ( {
81
83
width : 40
82
84
} )
83
- var widths = ui . _columnWidths ( [ { } , { } , { } ] )
85
+ const widths = ui . _columnWidths ( [ { } , { } , { } ] )
84
86
85
87
widths [ 0 ] . should . equal ( 13 )
86
88
widths [ 1 ] . should . equal ( 13 )
87
89
widths [ 2 ] . should . equal ( 13 )
88
90
} )
89
91
90
- it ( 'divides width over remaining columns if first column has width specified' , function ( ) {
91
- var ui = cliui ( {
92
+ it ( 'divides width over remaining columns if first column has width specified' , ( ) => {
93
+ const ui = cliui ( {
92
94
width : 40
93
95
} )
94
- var widths = ui . _columnWidths ( [ { width : 20 } , { } , { } ] )
96
+ const widths = ui . _columnWidths ( [ { width : 20 } , { } , { } ] )
95
97
96
98
widths [ 0 ] . should . equal ( 20 )
97
99
widths [ 1 ] . should . equal ( 10 )
98
100
widths [ 2 ] . should . equal ( 10 )
99
101
} )
100
102
101
- it ( 'divides width over remaining columns if middle column has width specified' , function ( ) {
102
- var ui = cliui ( {
103
+ it ( 'divides width over remaining columns if middle column has width specified' , ( ) => {
104
+ const ui = cliui ( {
103
105
width : 40
104
106
} )
105
- var widths = ui . _columnWidths ( [ { } , { width : 10 } , { } ] )
107
+ const widths = ui . _columnWidths ( [ { } , { width : 10 } , { } ] )
106
108
107
109
widths [ 0 ] . should . equal ( 15 )
108
110
widths [ 1 ] . should . equal ( 10 )
109
111
widths [ 2 ] . should . equal ( 15 )
110
112
} )
111
113
112
- it ( 'keeps track of remaining width if multiple columns have width specified' , function ( ) {
113
- var ui = cliui ( {
114
+ it ( 'keeps track of remaining width if multiple columns have width specified' , ( ) => {
115
+ const ui = cliui ( {
114
116
width : 40
115
117
} )
116
- var widths = ui . _columnWidths ( [ { width : 20 } , { width : 12 } , { } ] )
118
+ const widths = ui . _columnWidths ( [ { width : 20 } , { width : 12 } , { } ] )
117
119
118
120
widths [ 0 ] . should . equal ( 20 )
119
121
widths [ 1 ] . should . equal ( 12 )
120
122
widths [ 2 ] . should . equal ( 8 )
121
123
} )
122
124
123
- it ( 'uses a sane default if impossible widths are specified' , function ( ) {
124
- var ui = cliui ( {
125
+ it ( 'uses a sane default if impossible widths are specified' , ( ) => {
126
+ const ui = cliui ( {
125
127
width : 40
126
128
} )
127
- var widths = ui . _columnWidths ( [ { width : 30 } , { width : 30 } , { padding : [ 0 , 2 , 0 , 1 ] } ] )
129
+ const widths = ui . _columnWidths ( [ { width : 30 } , { width : 30 } , { padding : [ 0 , 2 , 0 , 1 ] } ] )
128
130
129
131
widths [ 0 ] . should . equal ( 30 )
130
132
widths [ 1 ] . should . equal ( 30 )
131
133
widths [ 2 ] . should . equal ( 4 )
132
134
} )
133
135
} )
134
136
135
- describe ( 'alignment' , function ( ) {
136
- it ( 'allows a column to be right aligned' , function ( ) {
137
- var ui = cliui ( {
137
+ describe ( 'alignment' , ( ) => {
138
+ it ( 'allows a column to be right aligned' , ( ) => {
139
+ const ui = cliui ( {
138
140
width : 40
139
141
} )
140
142
@@ -145,7 +147,7 @@ describe('cliui', function () {
145
147
)
146
148
147
149
// it should right-align the second column.
148
- var expected = [
150
+ const expected = [
149
151
'i am a stringi am a secondi am a third' ,
150
152
' stringstring that' ,
151
153
' should be' ,
@@ -155,8 +157,8 @@ describe('cliui', function () {
155
157
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
156
158
} )
157
159
158
- it ( 'allows a column to be center aligned' , function ( ) {
159
- var ui = cliui ( {
160
+ it ( 'allows a column to be center aligned' , ( ) => {
161
+ const ui = cliui ( {
160
162
width : 60
161
163
} )
162
164
@@ -167,7 +169,7 @@ describe('cliui', function () {
167
169
)
168
170
169
171
// it should right-align the second column.
170
- var expected = [
172
+ const expected = [
171
173
'i am a string i am a second i am a third string' ,
172
174
' string that should be' ,
173
175
' wrapped'
@@ -177,9 +179,9 @@ describe('cliui', function () {
177
179
} )
178
180
} )
179
181
180
- describe ( 'padding' , function ( ) {
181
- it ( 'handles left/right padding' , function ( ) {
182
- var ui = cliui ( {
182
+ describe ( 'padding' , ( ) => {
183
+ it ( 'handles left/right padding' , ( ) => {
184
+ const ui = cliui ( {
183
185
width : 40
184
186
} )
185
187
@@ -190,7 +192,7 @@ describe('cliui', function () {
190
192
)
191
193
192
194
// it should add left/right padding to columns.
193
- var expected = [
195
+ const expected = [
194
196
' i have i have i have no' ,
195
197
' padding padding on padding' ,
196
198
' on my my right' ,
@@ -200,8 +202,8 @@ describe('cliui', function () {
200
202
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
201
203
} )
202
204
203
- it ( 'handles top/bottom padding' , function ( ) {
204
- var ui = cliui ( {
205
+ it ( 'handles top/bottom padding' , ( ) => {
206
+ const ui = cliui ( {
205
207
width : 40
206
208
} )
207
209
@@ -213,7 +215,7 @@ describe('cliui', function () {
213
215
214
216
// it should add top/bottom padding to second
215
217
// and third columns.
216
- var expected = [
218
+ const expected = [
217
219
'i am a string i am a third' ,
218
220
' string that' ,
219
221
' i am a secondshould be' ,
@@ -224,26 +226,24 @@ describe('cliui', function () {
224
226
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
225
227
} )
226
228
227
- it ( 'preserves leading whitespace as padding' , function ( ) {
228
- var ui = cliui ( )
229
+ it ( 'preserves leading whitespace as padding' , ( ) => {
230
+ const ui = cliui ( )
229
231
230
232
ui . div ( ' LEADING WHITESPACE' )
231
233
ui . div ( '\u001b[34m with ansi\u001b[39m' )
232
234
233
- var expected = [
235
+ const expected = [
234
236
' LEADING WHITESPACE' ,
235
237
' with ansi'
236
238
]
237
239
238
- ui . toString ( ) . split ( '\n' ) . map ( function ( l ) {
239
- return stripAnsi ( l )
240
- } ) . should . eql ( expected )
240
+ ui . toString ( ) . split ( '\n' ) . map ( l => stripAnsi ( l ) ) . should . eql ( expected )
241
241
} )
242
242
} )
243
243
244
- describe ( 'border' , function ( ) {
245
- it ( 'allows a border to be placed around a div' , function ( ) {
246
- var ui = cliui ( {
244
+ describe ( 'border' , ( ) => {
245
+ it ( 'allows a border to be placed around a div' , ( ) => {
246
+ const ui = cliui ( {
247
247
width : 40
248
248
} )
249
249
@@ -252,7 +252,7 @@ describe('cliui', function () {
252
252
{ text : 'i am a second string' , padding : [ 1 , 0 , 0 , 0 ] , border : true }
253
253
)
254
254
255
- var expected = [
255
+ const expected = [
256
256
'.------------------.' ,
257
257
'| i am a first |.------------------.' ,
258
258
'| string || i am a second |' ,
@@ -264,9 +264,9 @@ describe('cliui', function () {
264
264
} )
265
265
} )
266
266
267
- describe ( 'wrap' , function ( ) {
268
- it ( 'allows wordwrap to be disabled' , function ( ) {
269
- var ui = cliui ( {
267
+ describe ( 'wrap' , ( ) => {
268
+ it ( 'allows wordwrap to be disabled' , ( ) => {
269
+ const ui = cliui ( {
270
270
wrap : false
271
271
} )
272
272
@@ -280,9 +280,9 @@ describe('cliui', function () {
280
280
} )
281
281
} )
282
282
283
- describe ( 'span' , function ( ) {
284
- it ( 'appends the next row to the end of the prior row if it fits' , function ( ) {
285
- var ui = cliui ( {
283
+ describe ( 'span' , ( ) => {
284
+ it ( 'appends the next row to the end of the prior row if it fits' , ( ) => {
285
+ const ui = cliui ( {
286
286
width : 40
287
287
} )
288
288
@@ -294,16 +294,16 @@ describe('cliui', function () {
294
294
{ text : ' [required] [default: 99]' , align : 'right' }
295
295
)
296
296
297
- var expected = [
297
+ const expected = [
298
298
'i am a string that will be' ,
299
299
'wrapped [required] [default: 99]'
300
300
]
301
301
302
302
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
303
303
} )
304
304
305
- it ( 'does not append the string if it does not fit on the prior row' , function ( ) {
306
- var ui = cliui ( {
305
+ it ( 'does not append the string if it does not fit on the prior row' , ( ) => {
306
+ const ui = cliui ( {
307
307
width : 40
308
308
} )
309
309
@@ -315,7 +315,7 @@ describe('cliui', function () {
315
315
{ text : 'i am a second row' , align : 'left' }
316
316
)
317
317
318
- var expected = [
318
+ const expected = [
319
319
'i am a string that will be' ,
320
320
'wrapped' ,
321
321
'i am a second row'
@@ -324,8 +324,8 @@ describe('cliui', function () {
324
324
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
325
325
} )
326
326
327
- it ( 'always appends text to prior span if wrap is disabled' , function ( ) {
328
- var ui = cliui ( {
327
+ it ( 'always appends text to prior span if wrap is disabled' , ( ) => {
328
+ const ui = cliui ( {
329
329
wrap : false ,
330
330
width : 40
331
331
} )
@@ -340,16 +340,16 @@ describe('cliui', function () {
340
340
341
341
ui . div ( 'a third line' )
342
342
343
- var expected = [
343
+ const expected = [
344
344
'i am a string that will be wrapped i am a second row' ,
345
345
'a third line'
346
346
]
347
347
348
348
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
349
349
} )
350
350
351
- it ( 'appends to prior line appropriately when strings contain ansi escape codes' , function ( ) {
352
- var ui = cliui ( {
351
+ it ( 'appends to prior line appropriately when strings contain ansi escape codes' , ( ) => {
352
+ const ui = cliui ( {
353
353
width : 40
354
354
} )
355
355
@@ -361,44 +361,42 @@ describe('cliui', function () {
361
361
{ text : chalk . blue ( ' [required] [default: 99]' ) , align : 'right' }
362
362
)
363
363
364
- var expected = [
364
+ const expected = [
365
365
'i am a string that will be' ,
366
366
'wrapped [required] [default: 99]'
367
367
]
368
368
369
- ui . toString ( ) . split ( '\n' ) . map ( function ( l ) {
370
- return stripAnsi ( l )
371
- } ) . should . eql ( expected )
369
+ ui . toString ( ) . split ( '\n' ) . map ( l => stripAnsi ( l ) ) . should . eql ( expected )
372
370
} )
373
371
} )
374
372
375
- describe ( 'layoutDSL' , function ( ) {
376
- it ( 'turns tab into multiple columns' , function ( ) {
377
- var ui = cliui ( {
373
+ describe ( 'layoutDSL' , ( ) => {
374
+ it ( 'turns tab into multiple columns' , ( ) => {
375
+ const ui = cliui ( {
378
376
width : 60
379
377
} )
380
378
381
379
ui . div (
382
380
' <regex> \tmy awesome regex\n <my second thing> \tanother row\t a third column'
383
381
)
384
382
385
- var expected = [
383
+ const expected = [
386
384
' <regex> my awesome regex' ,
387
385
' <my second thing> another row a third column'
388
386
]
389
387
390
388
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
391
389
} )
392
390
393
- it ( 'turns newline into multiple rows' , function ( ) {
394
- var ui = cliui ( {
391
+ it ( 'turns newline into multiple rows' , ( ) => {
392
+ const ui = cliui ( {
395
393
width : 40
396
394
} )
397
395
398
396
ui . div (
399
397
'Usage: $0\n <regex>\t my awesome regex\n <glob>\t my awesome glob\t [required]'
400
398
)
401
- var expected = [
399
+ const expected = [
402
400
'Usage: $0' ,
403
401
' <regex> my awesome regex' ,
404
402
' <glob> my awesome [required]' ,
@@ -408,34 +406,32 @@ describe('cliui', function () {
408
406
ui . toString ( ) . split ( '\n' ) . should . eql ( expected )
409
407
} )
410
408
411
- it ( 'aligns rows appropriately when they contain ansi escape codes' , function ( ) {
412
- var ui = cliui ( {
409
+ it ( 'aligns rows appropriately when they contain ansi escape codes' , ( ) => {
410
+ const ui = cliui ( {
413
411
width : 40
414
412
} )
415
413
416
414
ui . div (
417
415
' <regex>\t ' + chalk . red ( 'my awesome regex' ) + '\t [regex]\n ' + chalk . blue ( '<glob>' ) + '\t my awesome glob\t [required]'
418
416
)
419
417
420
- var expected = [
418
+ const expected = [
421
419
' <regex> my awesome [regex]' ,
422
420
' regex' ,
423
421
' <glob> my awesome [required]' ,
424
422
' glob'
425
423
]
426
424
427
- ui . toString ( ) . split ( '\n' ) . map ( function ( l ) {
428
- return stripAnsi ( l )
429
- } ) . should . eql ( expected )
425
+ ui . toString ( ) . split ( '\n' ) . map ( l => stripAnsi ( l ) ) . should . eql ( expected )
430
426
} )
431
427
432
- it ( 'ignores ansi escape codes when measuring padding' , function ( ) {
428
+ it ( 'ignores ansi escape codes when measuring padding' , ( ) => {
433
429
// Forcefully enable color-codes for this test
434
430
const { enabled, level } = chalk
435
431
chalk . enabled = true
436
432
chalk . level = 1
437
433
438
- var ui = cliui ( {
434
+ const ui = cliui ( {
439
435
width : 25
440
436
} )
441
437
@@ -445,23 +441,21 @@ describe('cliui', function () {
445
441
)
446
442
447
443
// relevant part is first line - leading whitespace should be preserved as left padding
448
- var expected = [
444
+ const expected = [
449
445
' |' ,
450
446
' __| __| | | _ \\' ,
451
447
' | | | | __/' ,
452
448
' \\__| _| \\__,_| \\___|' ,
453
449
' '
454
450
]
455
451
456
- ui . toString ( ) . split ( '\n' ) . map ( function ( l ) {
457
- return stripAnsi ( l )
458
- } ) . should . eql ( expected )
452
+ ui . toString ( ) . split ( '\n' ) . map ( l => stripAnsi ( l ) ) . should . eql ( expected )
459
453
chalk . enabled = enabled
460
454
chalk . level = level
461
455
} )
462
456
463
- it ( 'correctly handles lack of ansi escape codes when measuring padding' , function ( ) {
464
- var ui = cliui ( {
457
+ it ( 'correctly handles lack of ansi escape codes when measuring padding' , ( ) => {
458
+ const ui = cliui ( {
465
459
width : 25
466
460
} )
467
461
@@ -471,21 +465,19 @@ describe('cliui', function () {
471
465
)
472
466
473
467
// The difference
474
- var expected = [
468
+ const expected = [
475
469
' |' ,
476
470
' __| __| | | _ \\' ,
477
471
' | | | | __/' ,
478
472
' \\__| _| \\__,_| \\___|' ,
479
473
''
480
474
]
481
475
482
- ui . toString ( ) . split ( '\n' ) . map ( function ( l ) {
483
- return stripAnsi ( l )
484
- } ) . should . eql ( expected )
476
+ ui . toString ( ) . split ( '\n' ) . map ( l => stripAnsi ( l ) ) . should . eql ( expected )
485
477
} )
486
478
487
- it ( 'does not apply DSL if wrap is false' , function ( ) {
488
- var ui = cliui ( {
479
+ it ( 'does not apply DSL if wrap is false' , ( ) => {
480
+ const ui = cliui ( {
489
481
width : 40 ,
490
482
wrap : false
491
483
} )
0 commit comments