@@ -7,6 +7,8 @@ const utils = require('../lib/utils')
77const stripAnsiRegex =
88/ [ \u001b \u009b ] [ [ ( ) # ; ? ] * (?: [ 0 - 9 ] { 1 , 4 } (?: ; [ 0 - 9 ] { 0 , 4 } ) * ) ? [ 0 - 9 A - O R Z c f - n q r y = > < ] / g
99
10+ const originalConsoleLog = console . log
11+
1012test ( 'test utility functions' , ( t ) => {
1113 t . test ( 'test rightPad function - with padding' , ( tt ) => {
1214 const padded = utils . rightPad ( 'string' , 10 )
@@ -72,5 +74,51 @@ test('test utility functions', (t) => {
7274 tt . end ( )
7375 } )
7476
77+ t . test ( 'test describeRule function' , ( tt ) => {
78+ function logger ( ) {
79+ const args = [ ...arguments ]
80+ tt . equal ( args [ 1 ] . replace ( stripAnsiRegex , '' ) ,
81+ ' rule-id' , 'has a title with padding' )
82+ tt . equal ( args [ 2 ] . replace ( stripAnsiRegex , '' ) ,
83+ 'a description' , 'has a description' )
84+ }
85+
86+ // overrite the console.log
87+ console . log = logger
88+ utils . describeRule ( { id : 'rule-id' , meta : { description : 'a description' } } )
89+ // put it back
90+ console . log = originalConsoleLog
91+ tt . end ( )
92+ } )
93+
94+ t . test ( 'test describeRule function - no meta data description' , ( tt ) => {
95+ function logger ( ) {
96+ tt . fails ( 'should not reach here' )
97+ }
98+
99+ // overrite the console.log
100+ console . log = logger
101+ utils . describeRule ( { id : 'rule-id' , meta : { } } )
102+ tt . pass ( 'no return value' )
103+
104+ // put it back
105+ console . log = originalConsoleLog
106+ tt . end ( )
107+ } )
108+
109+ t . test ( 'test describeSubsystem function - no subsystems' , ( tt ) => {
110+ function logger ( ) {
111+ tt . fails ( 'should not reach here' )
112+ }
113+
114+ // overrite the console.log
115+ console . log = logger
116+ utils . describeSubsystem ( )
117+ tt . pass ( 'no return value' )
118+ // put it back
119+ console . log = originalConsoleLog
120+ tt . end ( )
121+ } )
122+
75123 t . end ( )
76124} )
0 commit comments