@@ -7,6 +7,8 @@ const utils = require('../lib/utils')
7
7
const stripAnsiRegex =
8
8
/ [ \u001b \u009b ] [ [ ( ) # ; ? ] * (?: [ 0 - 9 ] { 1 , 4 } (?: ; [ 0 - 9 ] { 0 , 4 } ) * ) ? [ 0 - 9 A - O R Z c f - n q r y = > < ] / g
9
9
10
+ const originalConsoleLog = console . log
11
+
10
12
test ( 'test utility functions' , ( t ) => {
11
13
t . test ( 'test rightPad function - with padding' , ( tt ) => {
12
14
const padded = utils . rightPad ( 'string' , 10 )
@@ -72,5 +74,51 @@ test('test utility functions', (t) => {
72
74
tt . end ( )
73
75
} )
74
76
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
+
75
123
t . end ( )
76
124
} )
0 commit comments