Skip to content

Commit aed7936

Browse files
committed
refactor(format): expose format result with extra tests
1 parent a03d92a commit aed7936

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

@commitlint/format/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function formatInput(result = {}, options = {}) {
3838
return `\n${decoration} input: ${decoratedInput}\n`;
3939
}
4040

41-
function formatResult(result = {}, options = {}) {
41+
export function formatResult(result = {}, options = {}) {
4242
const {
4343
signs = DEFAULT_SIGNS,
4444
colors = DEFAULT_COLORS,

@commitlint/format/src/index.test.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import chalk from 'chalk';
33
import {includes} from 'lodash';
4-
import format from '.';
4+
import format, {formatResult} from '.';
55

66
const ok = chalk.bold(
77
`${chalk.green(
@@ -144,3 +144,46 @@ test('uses signs as configured', t => {
144144
t.true(includes(actualError, 'ERR'));
145145
t.true(includes(actualWarning, 'WRN'));
146146
});
147+
148+
test('format result provides summary without arguments', t => {
149+
const actual = formatResult();
150+
const actualText = actual.join('\n');
151+
152+
t.true(includes(actualText, '0 problems, 0 warnings'));
153+
});
154+
155+
test('format result transforms error to text', t => {
156+
const actual = formatResult({
157+
errors: [
158+
{
159+
level: 2,
160+
name: 'error-name',
161+
message: 'There was an error'
162+
}
163+
]
164+
});
165+
166+
const actualText = actual.join('\n');
167+
168+
t.true(includes(actualText, 'error-name'));
169+
t.true(includes(actualText, 'There was an error'));
170+
t.true(includes(actualText, '1 problems, 0 warnings'));
171+
});
172+
173+
test('format result transforms warning to text', t => {
174+
const actual = formatResult({
175+
warnings: [
176+
{
177+
level: 1,
178+
name: 'warning-name',
179+
message: 'There was a warning'
180+
}
181+
]
182+
});
183+
184+
const actualText = actual.join('\n');
185+
186+
t.true(includes(actualText, 'warning-name'));
187+
t.true(includes(actualText, 'There was a warning'));
188+
t.true(includes(actualText, '0 problems, 1 warnings'));
189+
});

0 commit comments

Comments
 (0)