Skip to content

Commit b3d0302

Browse files
committed
fix: cleanup project and add more tests
1 parent e5c60ab commit b3d0302

File tree

9 files changed

+61
-89
lines changed

9 files changed

+61
-89
lines changed

@commitlint/prompt/fixtures/cli.js

-8
This file was deleted.

@commitlint/prompt/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@
3838
"devDependencies": {
3939
"@commitlint/utils": "^11.0.0",
4040
"@types/inquirer": "^6.5.0",
41-
"@types/concat-stream": "^1.6.0",
4241
"commitizen": "4.2.2",
43-
"concat-stream": "^2.0.0",
4442
"inquirer": "^6.5.2"
4543
},
4644
"dependencies": {

@commitlint/prompt/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import inquirer from 'inquirer';
22
import input from './input';
3-
import InputCustomPrompt from './inquirer/InputCustomPrompt';
43

54
type Commit = (input: string) => void;
65

@@ -14,7 +13,6 @@ export async function prompter(
1413
cz: typeof inquirer,
1514
commit: Commit
1615
): Promise<void> {
17-
cz.prompt.registerPrompt('input-custom', InputCustomPrompt);
1816
const message = await input(cz.prompt);
1917
commit(message);
2018
}

@commitlint/prompt/src/input.test.ts

-69
This file was deleted.

@commitlint/prompt/src/input.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import settings from './settings';
77
import {InputSetting, Result} from './library/types';
88

99
import {getHasName, getMaxLength, getRules} from './library/utils';
10+
import InputCustomPrompt from './inquirer/InputCustomPrompt';
1011

1112
/**
1213
* Get user input by interactive prompt based on
@@ -26,6 +27,7 @@ export default async function input(prompter: PromptModule): Promise<string> {
2627

2728
try {
2829
const questions: DistinctQuestion<Result>[] = [];
30+
prompter.registerPrompt('input-custom', InputCustomPrompt);
2931

3032
for (const input of parts) {
3133
const inputSettings: InputSetting = settings[input];

@commitlint/prompt/src/inquirer/InputCustomPrompt.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import inquirer from 'inquirer';
55
import InputPrompt from 'inquirer/lib/prompts/input';
66
import observe from 'inquirer/lib/utils/events';
77
import type {Subscription} from 'rxjs/internal/Subscription';
8+
import './inquirer.d.ts';
89

910
import Answers = inquirer.Answers;
1011
import InputCustomOptions = inquirer.InputCustomOptions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {Result} from './types';
2+
import format from './format';
3+
4+
test('should return empty string', () => {
5+
const result: Result = {};
6+
expect(format(result)).toBe(' ');
7+
});
8+
9+
test('should omit scope', () => {
10+
const result: Result = {
11+
type: 'fix',
12+
subject: 'test',
13+
};
14+
expect(format(result)).toBe('fix: test');
15+
});
16+
17+
test('should include scope', () => {
18+
const result: Result = {
19+
type: 'fix',
20+
scope: 'prompt',
21+
subject: 'test',
22+
};
23+
expect(format(result)).toBe('fix(prompt): test');
24+
});
25+
26+
test('should include body', () => {
27+
const result: Result = {
28+
type: 'fix',
29+
scope: 'prompt',
30+
subject: 'test',
31+
body: 'some body',
32+
};
33+
expect(format(result)).toBe('fix(prompt): test\nsome body');
34+
});
35+
36+
test('should include footer', () => {
37+
const result: Result = {
38+
type: 'fix',
39+
scope: 'prompt',
40+
subject: 'test',
41+
footer: 'some footer',
42+
};
43+
expect(format(result)).toBe('fix(prompt): test\nsome footer');
44+
});
45+
46+
test('should include body and footer', () => {
47+
const result: Result = {
48+
type: 'fix',
49+
scope: 'prompt',
50+
subject: 'test',
51+
body: 'some body',
52+
footer: 'some footer',
53+
};
54+
expect(format(result)).toBe('fix(prompt): test\nsome body\nsome footer');
55+
});

@commitlint/prompt/src/library/format.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export default function format(input: Result, debug = false): string {
2727
// Return formatted string
2828
const {type, scope, subject, body, footer} = results;
2929
return [
30-
`${type}${scope ? `(${scope})` : ''}${type || scope ? ':' : ''} ${subject}`,
30+
`${type || ''}${scope ? `(${scope})` : ''}${type || scope ? ':' : ''} ${
31+
subject || ''
32+
}`,
3133
body,
3234
footer,
3335
]

yarn.lock

-7
Original file line numberDiff line numberDiff line change
@@ -2225,13 +2225,6 @@
22252225
resolved "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
22262226
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
22272227

2228-
"@types/concat-stream@^1.6.0":
2229-
version "1.6.0"
2230-
resolved "https://registry.npmjs.org/@types/concat-stream/-/concat-stream-1.6.0.tgz#394dbe0bb5fee46b38d896735e8b68ef2390d00d"
2231-
integrity sha1-OU2+C7X+5Gs42JZzXoto7yOQ0A0=
2232-
dependencies:
2233-
"@types/node" "*"
2234-
22352228
"@types/events@*":
22362229
version "3.0.0"
22372230
resolved "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"

0 commit comments

Comments
 (0)