Skip to content

Commit a64c50b

Browse files
committed
Fix doctor help text formatting in test.
1 parent 3b42a2a commit a64c50b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

test/doctor.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
33
import chai from 'chai'
4-
import chalk from 'chalk'
54
import chaiAsPromised from 'chai-as-promised'
65
import spawn from 'spawn-please'
76
import rimraf from 'rimraf'
@@ -15,6 +14,12 @@ process.env.NCU_TESTS = 'true'
1514
const bin = path.join(__dirname, '../build/src/bin/cli.js')
1615
const doctorTests = path.join(__dirname, 'doctor')
1716

17+
/** Strips ANSI formatting from a string. */
18+
// https://stackoverflow.com/a/29497680/480608
19+
const stripColors = (s: string) =>
20+
// eslint-disable-next-line no-control-regex
21+
s.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
22+
1823
/** Run the ncu CLI. */
1924
const ncu = (args: string[], options?: Record<string, unknown>) => spawn('node', [bin, ...args], options)
2025

@@ -140,10 +145,7 @@ describe('doctor', function () {
140145
it('print instructions when -u is not specified', async () => {
141146
const cwd = path.join(doctorTests, 'nopackagefile')
142147
const output = await ncu(['--doctor'], { cwd })
143-
// output does not include chalk formatting
144-
// chalk.reset does not seem to work, so just format the expected bold text in the output before comparing
145-
const outputFormatted = output.replace('Add "-u" to execute', chalk.bold('Add "-u" to execute'))
146-
return outputFormatted.should.equal(`Usage: ncu --doctor\n\n${cliOptionsMap.doctor.help}\n`)
148+
return stripColors(output).should.equal(`Usage: ncu --doctor\n\n${stripColors(cliOptionsMap.doctor.help!)}\n`)
147149
})
148150

149151
it('throw an error if there is no package file', async () => {

0 commit comments

Comments
 (0)