Skip to content

refactor(format): expose format result with extra tests #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion @commitlint/format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function formatInput(result = {}, options = {}) {
return `\n${decoration} input: ${decoratedInput}\n`;
}

function formatResult(result = {}, options = {}) {
export function formatResult(result = {}, options = {}) {
const {
signs = DEFAULT_SIGNS,
colors = DEFAULT_COLORS,
Expand Down
45 changes: 44 additions & 1 deletion @commitlint/format/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava';
import chalk from 'chalk';
import {includes} from 'lodash';
import format from '.';
import format, {formatResult} from '.';

const ok = chalk.bold(
`${chalk.green(
Expand Down Expand Up @@ -144,3 +144,46 @@ test('uses signs as configured', t => {
t.true(includes(actualError, 'ERR'));
t.true(includes(actualWarning, 'WRN'));
});

test('format result provides summary without arguments', t => {
const actual = formatResult();
const actualText = actual.join('\n');

t.true(includes(actualText, '0 problems, 0 warnings'));
});

test('format result transforms error to text', t => {
const actual = formatResult({
errors: [
{
level: 2,
name: 'error-name',
message: 'There was an error'
}
]
});

const actualText = actual.join('\n');

t.true(includes(actualText, 'error-name'));
t.true(includes(actualText, 'There was an error'));
t.true(includes(actualText, '1 problems, 0 warnings'));
});

test('format result transforms warning to text', t => {
const actual = formatResult({
warnings: [
{
level: 1,
name: 'warning-name',
message: 'There was a warning'
}
]
});

const actualText = actual.join('\n');

t.true(includes(actualText, 'warning-name'));
t.true(includes(actualText, 'There was a warning'));
t.true(includes(actualText, '0 problems, 1 warnings'));
});