Skip to content

Commit

Permalink
chore: fix testing when stdout does not support color-codes. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell authored and bcoe committed Apr 10, 2019
1 parent c9dab69 commit e1ad447
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/cliui.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ describe('cliui', function () {
})

it('ignores ansi escape codes when measuring padding', function () {
// Forcefully enable color-codes for this test
const { enabled, level } = chalk
chalk.enabled = true
chalk.level = 1

var ui = cliui({
width: 25
})
Expand All @@ -448,6 +453,32 @@ describe('cliui', function () {
' '
]

ui.toString().split('\n').map(function (l) {
return stripAnsi(l)
}).should.eql(expected)
chalk.enabled = enabled
chalk.level = level
})

it('correctly handles lack of ansi escape codes when measuring padding', function () {
var ui = cliui({
width: 25
})

// using figlet font 'Shadow' rendering of text 'true' here
ui.div(
' | \n __| __| | | _ \\ \n | | | | __/ \n \\__| _| \\__,_| \\___| \n '
)

// The difference
var expected = [
' |',
' __| __| | | _ \\',
' | | | | __/',
' \\__| _| \\__,_| \\___|',
''
]

ui.toString().split('\n').map(function (l) {
return stripAnsi(l)
}).should.eql(expected)
Expand Down

0 comments on commit e1ad447

Please sign in to comment.