1
1
import fs from 'fs'
2
2
import path from 'path'
3
3
import chai from 'chai'
4
- import chalk from 'chalk'
5
4
import chaiAsPromised from 'chai-as-promised'
6
5
import spawn from 'spawn-please'
7
6
import rimraf from 'rimraf'
@@ -15,6 +14,12 @@ process.env.NCU_TESTS = 'true'
15
14
const bin = path . join ( __dirname , '../build/src/bin/cli.js' )
16
15
const doctorTests = path . join ( __dirname , 'doctor' )
17
16
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 - 9 A - O R Z c f - n q r y = > < ] / g, '' )
22
+
18
23
/** Run the ncu CLI. */
19
24
const ncu = ( args : string [ ] , options ?: Record < string , unknown > ) => spawn ( 'node' , [ bin , ...args ] , options )
20
25
@@ -140,10 +145,7 @@ describe('doctor', function () {
140
145
it ( 'print instructions when -u is not specified' , async ( ) => {
141
146
const cwd = path . join ( doctorTests , 'nopackagefile' )
142
147
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` )
147
149
} )
148
150
149
151
it ( 'throw an error if there is no package file' , async ( ) => {
0 commit comments