Skip to content

Commit e1ad447

Browse files
coreyfarrellbcoe
authored andcommittedApr 10, 2019
chore: fix testing when stdout does not support color-codes. (#62)
1 parent c9dab69 commit e1ad447

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
 

‎test/cliui.js

+31
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ describe('cliui', function () {
430430
})
431431

432432
it('ignores ansi escape codes when measuring padding', function () {
433+
// Forcefully enable color-codes for this test
434+
const { enabled, level } = chalk
435+
chalk.enabled = true
436+
chalk.level = 1
437+
433438
var ui = cliui({
434439
width: 25
435440
})
@@ -448,6 +453,32 @@ describe('cliui', function () {
448453
' '
449454
]
450455

456+
ui.toString().split('\n').map(function (l) {
457+
return stripAnsi(l)
458+
}).should.eql(expected)
459+
chalk.enabled = enabled
460+
chalk.level = level
461+
})
462+
463+
it('correctly handles lack of ansi escape codes when measuring padding', function () {
464+
var ui = cliui({
465+
width: 25
466+
})
467+
468+
// using figlet font 'Shadow' rendering of text 'true' here
469+
ui.div(
470+
' | \n __| __| | | _ \\ \n | | | | __/ \n \\__| _| \\__,_| \\___| \n '
471+
)
472+
473+
// The difference
474+
var expected = [
475+
' |',
476+
' __| __| | | _ \\',
477+
' | | | | __/',
478+
' \\__| _| \\__,_| \\___|',
479+
''
480+
]
481+
451482
ui.toString().split('\n').map(function (l) {
452483
return stripAnsi(l)
453484
}).should.eql(expected)

0 commit comments

Comments
 (0)
Please sign in to comment.