Skip to content

Commit 3854d07

Browse files
lholmquistTrott
authored andcommitted
test: add tests for header util functions (#76)
* This adds a test for the header utility function.
1 parent 64a7a65 commit 3854d07

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/utils-test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
const { test } = require('tap')
44
const utils = require('../lib/utils')
55

6+
// We aren't testing the chalk library, so strip off the colors/styles it adds
7+
const stripAnsiRegex =
8+
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
9+
610
test('test utility functions', (t) => {
711
t.test('test rightPad function - with padding', (tt) => {
812
const padded = utils.rightPad('string', 10)
@@ -36,5 +40,37 @@ test('test utility functions', (t) => {
3640
tt.end()
3741
})
3842

43+
t.test('test headers function - skip', (tt) => {
44+
const header = utils.header('abc123', 'skip')
45+
tt.equal(header.replace(stripAnsiRegex, ''),
46+
'✔ abc123 # SKIPPED',
47+
'should be equal')
48+
tt.end()
49+
})
50+
51+
t.test('test headers function - pass', (tt) => {
52+
const header = utils.header('abc123', 'pass')
53+
tt.equal(header.replace(stripAnsiRegex, ''),
54+
'✔ abc123',
55+
'should be equal')
56+
tt.end()
57+
})
58+
59+
t.test('test headers function - pass', (tt) => {
60+
const header = utils.header('abc123', 'pass')
61+
tt.equal(header.replace(stripAnsiRegex, ''),
62+
'✔ abc123',
63+
'should be equal')
64+
tt.end()
65+
})
66+
67+
t.test('test headers function - fail', (tt) => {
68+
const header = utils.header('abc123', 'fail')
69+
tt.equal(header.replace(stripAnsiRegex, ''),
70+
'✖ abc123',
71+
'should be equal')
72+
tt.end()
73+
})
74+
3975
t.end()
4076
})

0 commit comments

Comments
 (0)