Skip to content

Commit ac0737b

Browse files
lholmquistTrott
authored andcommitted
Add tests for the describeRule and describeSubsystem utility functions (#77)
* test: add describeRule test * test: add describeSystem test
1 parent 3854d07 commit ac0737b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/utils-test.js

+48
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const utils = require('../lib/utils')
77
const stripAnsiRegex =
88
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
99

10+
const originalConsoleLog = console.log
11+
1012
test('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

Comments
 (0)