-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkleur-test.js
More file actions
49 lines (37 loc) · 1.36 KB
/
kleur-test.js
File metadata and controls
49 lines (37 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const assert = require('node:assert/strict');
const kleur = require('kleur');
// Enable colors explicitly for testing
kleur.enabled = true;
// Basic colors
const red = kleur.red('error');
assert.equal(typeof red, 'string');
assert.ok(red.includes('error'));
const green = kleur.green('success');
assert.equal(typeof green, 'string');
assert.ok(green.includes('success'));
const blue = kleur.blue('info');
assert.equal(typeof blue, 'string');
assert.ok(blue.includes('info'));
// Bold and underline
const bold = kleur.bold('important');
assert.equal(typeof bold, 'string');
assert.ok(bold.includes('important'));
const underline = kleur.underline('link');
assert.equal(typeof underline, 'string');
assert.ok(underline.includes('link'));
// Chaining styles
const chained = kleur.bold().red('alert');
assert.equal(typeof chained, 'string');
assert.ok(chained.includes('alert'));
// Enabled flag controls whether ANSI codes are applied
// Disable colors and verify plain text output (no ANSI escape sequences)
kleur.enabled = false;
const plain = kleur.red('no-color');
assert.equal(plain, 'no-color');
// Re-enable colors and verify ANSI codes are present
kleur.enabled = true;
const colored = kleur.red('with-color');
assert.ok(colored.includes('with-color'));
assert.notEqual(colored, 'with-color', 'should include ANSI codes when enabled');
console.log('kleur-test:ok');