Skip to content

Commit 4f57721

Browse files
authored
v1.5.0 - theme support (#9)
* refactor: little refactor, preparing for theme implementation * feat(themes): initial themes implementation * improved theming, added tests and docs * docs: updated themes.md added badge examples * fix: little code styling * docs: added theme options to badge signature * refactor: renamed inverse to swap * tests: added color tests * docs: moved images into images folder * refactor: improved creation of theme helper methods * docs: improved themes docs * feat(themes): added option to register new themes, and refactored a bit * docs: updated theme docs * tests: added more tests, and coverage badges * docs: added table of contents * docs: removed color list, as it's already in cli-color docs * docs: added theme overrides explanation * chore(release): 1.5.0
1 parent 67941fb commit 4f57721

28 files changed

+2425
-104
lines changed

.tests/badge.test.js

+70-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ test('Should work with null label and message bg', () => {
4040
expect(createEmptyBadge).not.toThrow();
4141
})
4242

43+
test('Should work with incorrect xterm color', () => {
44+
const createEmptyBadge = () => badge('test', 'label', { labelBg: -1, messageBg: 260 });
45+
expect(createEmptyBadge).not.toThrow();
46+
})
47+
4348
test('Should work with null label and message color', () => {
4449
const createEmptyBadge = () => badge('test', 'label', { labelColor: null, messageColor: null });
4550
expect(createEmptyBadge).not.toThrow();
@@ -86,7 +91,69 @@ test('Should work with forceLink', () => {
8691
expect(createEmptyBadge).not.toThrow();
8792
})
8893

89-
test('Should return correctly formatted badge', () => {
90-
const testBadge = badge('test', 'label', { labelBg: 32 });
91-
expect(testBadge).toEqual(' test  label  ');
94+
test('Should work with theme', () => {
95+
const createEmptyBadge = () => badge('test', 'label', { theme: 'green' });
96+
expect(createEmptyBadge).not.toThrow();
97+
})
98+
99+
test('Should work with theme', () => {
100+
const createEmptyBadge = () => badge('test', 'label', { theme: 'green', invertTheme: true });
101+
expect(createEmptyBadge).not.toThrow();
102+
})
103+
104+
test('badge.theme should work', () => {
105+
const createEmptyBadge = () => badge.theme('red')('test', 'label');
106+
expect(createEmptyBadge).not.toThrow();
107+
})
108+
109+
test('badge.theme should work', () => {
110+
const createEmptyBadge = () => badge.theme('red').swapped('test', 'label');
111+
expect(createEmptyBadge).not.toThrow();
112+
})
113+
114+
test('override label should work', () => {
115+
badge.addTheme('replaceLbl', { label: 'hello' });
116+
expect(
117+
badge('lbl', 'msg', { theme: 'replaceLbl' })
118+
).toEqual("\u001b[100m\u001b[37m hello \u001b[39m\u001b[49m\u001b[44m\u001b[37m msg \u001b[39m\u001b[49m ");
119+
})
120+
121+
122+
test('override message should work', () => {
123+
badge.addTheme('replaceLbl', { message: 'hello' });
124+
expect(
125+
badge('lbl', 'msg', { theme: 'replaceLbl' })
126+
).toEqual("\u001b[100m\u001b[37m lbl \u001b[39m\u001b[49m\u001b[44m\u001b[37m hello \u001b[39m\u001b[49m ");
127+
})
128+
129+
// Xterm tests
130+
131+
test('Label bg xterm [32]', () => {
132+
const createEmptyBadge = () => badge('test', 'label', { labelBg: 32 });
133+
expect(createEmptyBadge).not.toThrow();
134+
})
135+
136+
test('Message bg xterm [32]', () => {
137+
const createEmptyBadge = () => badge('test', 'label', { messageBg: 32 });
138+
expect(createEmptyBadge).not.toThrow();
139+
})
140+
141+
test('Label color xterm [32]', () => {
142+
const createEmptyBadge = () => badge('test', 'label', { labelColor: 32 });
143+
expect(createEmptyBadge).not.toThrow();
144+
})
145+
146+
test('Message color xterm [32]', () => {
147+
const createEmptyBadge = () => badge('test', 'label', { messageColor: 32 });
148+
expect(createEmptyBadge).not.toThrow();
149+
})
150+
151+
test('Label bg xterm [null]', () => {
152+
const createEmptyBadge = () => badge('test', 'label', { labelBg: null });
153+
expect(createEmptyBadge).not.toThrow();
154+
})
155+
156+
test('Label bg xterm [-1]', () => {
157+
const createEmptyBadge = () => badge('test', 'label', { labelBg: -1 });
158+
expect(createEmptyBadge).not.toThrow();
92159
})

.tests/bg-labels.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
const { badge } = require('../index');
3+
const badgesTestData = require('./util/all-badges.js');
4+
5+
function testLabelBg(color, expected) {
6+
return () => {
7+
const testBadge = badge('lbl', 'msg', { labelBg: color });
8+
expect(testBadge).toEqual(expected);
9+
};
10+
}
11+
12+
const bgLabelsData = badgesTestData.bgLabels;
13+
14+
for (let lblData of bgLabelsData) {
15+
test('Bg label [green]', testLabelBg(lblData.color, lblData.badge));
16+
}

.tests/bg-messages.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { badge } = require('../index');
2+
const badgesTestData = require('./util/all-badges.js');
3+
4+
function testMessageBg(color, expected) {
5+
return () => {
6+
const testBadge = badge('lbl', 'msg', { messageBg: color });
7+
expect(testBadge).toEqual(expected);
8+
};
9+
}
10+
11+
const bgMessagesData = badgesTestData.bgMessages;
12+
13+
for (let msgData of bgMessagesData) {
14+
test('Bg message [green]', testMessageBg(msgData.color, msgData.badge));
15+
}

.tests/color-labels.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
const { badge } = require('../index');
3+
const badgesTestData = require('./util/all-badges.js');
4+
5+
function testLabelColor(color, expected) {
6+
return () => {
7+
const testBadge = badge('lbl', 'msg', { labelColor: color });
8+
expect(testBadge).toEqual(expected);
9+
};
10+
}
11+
12+
const colorLabelsData = badgesTestData.colorLabels;
13+
14+
for (let lblData of colorLabelsData) {
15+
test('Color label [green]', testLabelColor(lblData.color, lblData.badge));
16+
}

.tests/color-messages.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
const { badge } = require('../index');
3+
const badgesTestData = require('./util/all-badges.js');
4+
5+
function testMessageColor(color, expected) {
6+
return () => {
7+
const testBadge = badge('lbl', 'msg', { messageColor: color });
8+
expect(testBadge).toEqual(expected);
9+
};
10+
}
11+
12+
const colorMessagesData = badgesTestData.colorMessages;
13+
14+
for (let msgData of colorMessagesData) {
15+
test('Color message [green]', testMessageColor(msgData.color, msgData.badge));
16+
}

0 commit comments

Comments
 (0)