Skip to content

Commit

Permalink
feat(cli): ✨ add skip when none hint to breaking change prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Nov 9, 2021
1 parent 30c8c7a commit 614f502
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 35 deletions.
8 changes: 4 additions & 4 deletions .config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = {
coveragePathIgnorePatterns: ['node_modules', 'index.ts'],
coverageThreshold: {
global: {
branches: 97.3,
functions: 96.55,
lines: 97.28,
statements: 97.67,
branches: 97.32,
functions: 96.64,
lines: 97.59,
statements: 97.92,
},
},
preset: 'ts-jest',
Expand Down
13 changes: 13 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,16 @@ export interface GitzyState {
answers: Answers
config: GitzyConfig
}

interface PromptLang {
hint?: string
message: string
}

export interface PromptsLang {
body: PromptLang
breaking: PromptLang
scope: PromptLang
subject: PromptLang
type: PromptLang
}
27 changes: 27 additions & 0 deletions src/prompts/__snapshots__/lang.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lang promptsLang should create prompts lang 1`] = `
Object {
"body": Object {
"hint": "...supports multi line, press enter to go to next line",
"message": "Add a longer description
",
},
"breaking": Object {
"hint": "...skip when none",
"message": "Add any breaking changes
BREAKING CHANGE:",
},
"scope": Object {
"hint": "...type or use arrow keys",
"message": "Choose the scope",
},
"subject": Object {
"message": "Add a short description",
},
"type": Object {
"hint": "...type or use arrow keys",
"message": "Choose the type",
},
}
`;
6 changes: 3 additions & 3 deletions src/prompts/body.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CreatedPrompt } from '../interfaces'
import { promptMessages } from './lang'
import { promptsLang } from './lang'

export const body: CreatedPrompt = () => {
return {
format: (value): string => value.trim(),
hint: '...supports multi line, press enter to go to next line',
message: promptMessages.body,
hint: promptsLang.body.hint,
message: promptsLang.body.message,
multiline: true,
name: 'body',
type: 'text',
Expand Down
28 changes: 28 additions & 0 deletions src/prompts/breaking.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { breaking } from './breaking'
import { defaultConfig } from '../defaults'
import { EnquirerPrompt } from '../interfaces'

describe('breaking', () => {
it('should create body prompt', () => {
const breakingPrompt = breaking({
config: defaultConfig,
answers: {
body: '',
breaking: '',
issues: '',
scope: '',
subject: '',
type: '',
},
flags: {},
}) as Required<EnquirerPrompt>

expect(breakingPrompt).toStrictEqual({
hint: '...skip when none',
message: `Add any breaking changes
BREAKING CHANGE:`,
name: 'breaking',
type: 'text',
})
})
})
5 changes: 3 additions & 2 deletions src/prompts/breaking.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CreatedPrompt } from '../interfaces'
import { promptMessages } from './lang'
import { promptsLang } from './lang'

export const breaking: CreatedPrompt = () => {
return {
message: promptMessages.breaking,
hint: promptsLang.breaking.hint,
message: promptsLang.breaking.message,
name: 'breaking',
type: 'text',
}
Expand Down
9 changes: 9 additions & 0 deletions src/prompts/lang.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { promptsLang } from './lang'

describe('lang', () => {
describe('promptsLang', () => {
it('should create prompts lang', () => {
expect(promptsLang).toMatchSnapshot()
})
})
})
32 changes: 22 additions & 10 deletions src/prompts/lang.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
import { bold, red, reset } from 'ansi-colors'
import { bold, dim, red, reset } from 'ansi-colors'

import { IssuesPrefixes } from '../interfaces'
import { IssuesPrefixes, PromptsLang } from '../interfaces'

const breaking = red('BREAKING CHANGE:')

const closes = (issuesPrefix: IssuesPrefixes): string => {
return reset(`${issuesPrefix}:`)
export const promptsLang: PromptsLang = {
body: {
hint: '...supports multi line, press enter to go to next line',
message: 'Add a longer description\n',
},
breaking: {
hint: dim('...skip when none'),
message: `${bold('Add any breaking changes')}\n ${breaking}`,
},
scope: {
hint: dim('...type or use arrow keys'),
message: 'Choose the scope',
},
subject: { message: 'Add a short description' },
type: {
hint: dim('...type or use arrow keys'),
message: 'Choose the type',
},
}

export const promptMessages: Record<string, string> = {
body: 'Add a longer description\n',
breaking: `${bold('Add any breaking changes')}\n ${breaking}`,
scope: 'Choose the scope',
subject: 'Add a short description',
type: 'Choose the type',
const closes = (issuesPrefix: IssuesPrefixes): string => {
return reset(`${issuesPrefix}:`)
}

export const issuesMessage = (issuesPrefix: IssuesPrefixes): string => {
Expand Down
9 changes: 3 additions & 6 deletions src/prompts/scope.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { dim } from 'ansi-colors'

import { CreatedPrompt, EnquirerChoice } from '../interfaces'
import { fuzzySearch } from '../utils'
import { promptMessages } from './lang'
import { promptsLang } from './lang'

export const scope: CreatedPrompt = ({ config: { scopes } }) => {
const choices = scopes.map((s) => ({ indent: ' ', title: s, value: s }))
Expand All @@ -11,14 +9,13 @@ export const scope: CreatedPrompt = ({ config: { scopes } }) => {
return scopes.length > 0
? {
choices,
hint: dim('...type or use arrow keys'),
hint: promptsLang.scope.hint,
limit: 10,
message: promptMessages.scope,
message: promptsLang.scope.message,
name: 'scope',
suggest: (input: string): Promise<EnquirerChoice[]> => {
return fuzzySearch<EnquirerChoice>(choices, input, 'title')
},

type: 'autocomplete',
}
: null
Expand Down
4 changes: 2 additions & 2 deletions src/prompts/subject.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { green, red, yellow, bold } from 'ansi-colors'

import { CreatedPrompt, EnquirerState, Answers } from '../interfaces'
import { errorMessage, promptMessages } from './lang'
import { errorMessage, promptsLang } from './lang'

export const leadingLabel = (answers?: Answers): string => {
const scope =
Expand All @@ -15,7 +15,7 @@ export const subject: CreatedPrompt = ({
}) => {
const minTitleLengthError = errorMessage.minTitleLength(headerMinLength)
const maxTitleLengthError = errorMessage.maxTitleLength(headerMaxLength)
const message = promptMessages.subject
const message = promptsLang.subject.message
const emojiLength = disableEmoji ? 0 : 3

return {
Expand Down
8 changes: 3 additions & 5 deletions src/prompts/type.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { dim } from 'ansi-colors'

import {
CreatedPrompt,
EnquirerChoice,
Flags,
GitzyConfig,
} from '../interfaces'
import { fuzzySearch } from '../utils'
import { promptMessages } from './lang'
import { promptsLang } from './lang'

export const choice = (
{ details, disableEmoji }: GitzyConfig,
Expand All @@ -31,9 +29,9 @@ export const type: CreatedPrompt = ({ config, flags }) => {

return {
choices,
hint: dim('...type or use arrow keys'),
hint: promptsLang.type.hint,
limit: 10,
message: promptMessages.type,
message: promptsLang.type.message,
name: 'type',
suggest: (input: string): Promise<EnquirerChoice[]> => {
return fuzzySearch<EnquirerChoice>(choices, input, 'title')
Expand Down
27 changes: 24 additions & 3 deletions src/utils/store/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ describe('utils', () => {
})

describe('mkdir', () => {
const DIR_NAME = 'dirname'

it('should do nothing when directory exists', () => {
const mkdirSyncSpy = jest
.spyOn(fs, 'mkdirSync')
Expand All @@ -94,10 +96,29 @@ describe('utils', () => {

jest.spyOn(utils, 'directoryExists').mockReturnValueOnce(true)

utils.mkdir('dirname')
utils.mkdir(DIR_NAME)
expect(mkdirSyncSpy).not.toHaveBeenCalled()
expect(handleErrorSpy).not.toHaveBeenCalled()
})
it('should do throw when mkdirSync fails', () => {
const mkdirSyncSpy = jest
.spyOn(fs, 'mkdirSync')
.mockImplementationOnce(() => {
throw new Error('')
})
const handleErrorSpy = jest
.spyOn(utils, 'handleError')
.mockImplementationOnce(jest.fn())

jest.spyOn(utils, 'directoryExists').mockReturnValueOnce(false)

utils.mkdir(DIR_NAME)

expect(mkdirSyncSpy).toHaveBeenNthCalledWith(1, DIR_NAME, {
recursive: true,
})
expect(handleErrorSpy).toHaveBeenNthCalledWith(1, DIR_NAME, new Error(''))
})
it('should call mkdirSync when directory does not exist', () => {
const mkdirSyncSpy = jest
.spyOn(fs, 'mkdirSync')
Expand All @@ -106,9 +127,9 @@ describe('utils', () => {

jest.spyOn(utils, 'directoryExists').mockReturnValueOnce(false)

utils.mkdir('dirname')
utils.mkdir(DIR_NAME)

expect(mkdirSyncSpy).toHaveBeenNthCalledWith(1, 'dirname', {
expect(mkdirSyncSpy).toHaveBeenNthCalledWith(1, DIR_NAME, {
recursive: true,
})
expect(handleErrorSpy).not.toHaveBeenCalled()
Expand Down

0 comments on commit 614f502

Please sign in to comment.