/
eapostnova
/
2026-1--study--mathmod
Обзор
Документация
Войти
/
eapostnova
/
2026-1--study--mathmod
Код
Запросы
0
Задачи
Пакеты
0
Релизы
6
Аналитика
Безопасность
develop
node_modules/cz-customizable/__tests__/build-commit.test.js
192 строки
6 KB
Елизавета Постнова
feat(lab): lab04
24 мар 2026, 02:59
Верифицирован
24 мар 2026, 02:59
7783508
Код
Авторство
О чём код?
const buildCommit = require('../lib/build-commit'); describe('buildCommit()', () => { const answers = { type: 'feat', scope: 'app', subject: 'this is a new feature', }; it('subject with default subject separator', () => { const options = {}; expect(buildCommit(answers, options)).toEqual('feat(app): this is a new feature'); }); it('subject with custom subject separator option', () => { const options = { subjectSeparator: ' - ', }; expect(buildCommit(answers, options)).toEqual('feat(app) - this is a new feature'); }); it('subject 1 empty character separator', () => { const options = { subjectSeparator: ' ', }; expect(buildCommit(answers, options)).toEqual('feat(app) this is a new feature'); }); describe('without scope', () => { it('subject without scope', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', }; const options = {}; expect(buildCommit(answersNoScope, options)).toEqual('feat: this is a new feature'); }); it('subject without scope', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', }; const options = { subjectSeparator: ' - ', }; expect(buildCommit(answersNoScope, options)).toEqual('feat - this is a new feature'); }); }); describe('ticket number', () => { it('subject with ticket number', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', ticketNumber: '123', }; const options = {}; expect(buildCommit(answersNoScope, options)).toEqual('feat: 123 this is a new feature'); }); it('subject with ticket number prefix but no scope', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', ticketNumber: '123', }; const options = { ticketNumberPrefix: 'PREFIX-', }; expect(buildCommit(answersNoScope, options)).toEqual('feat: PREFIX-123 this is a new feature'); }); it('subject with scope, ticket number and prefix', () => { const answersNoScope = { type: 'feat', scope: 'app', subject: 'this is a new feature', ticketNumber: '123', }; const options = { ticketNumberPrefix: 'PREFIX-', }; expect(buildCommit(answersNoScope, options)).toEqual('feat(app): PREFIX-123 this is a new feature'); }); it('subject with no ticket number or scope but with fallback', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', }; const options = { fallbackTicketNumber: '000', }; expect(buildCommit(answersNoScope, options)).toEqual('feat: 000 this is a new feature'); }); it('subject with prefix and fallback ticket number', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', }; const options = { ticketNumberPrefix: 'PREFIX-', fallbackTicketNumber: '000', }; expect(buildCommit(answersNoScope, options)).toEqual('feat: PREFIX-000 this is a new feature'); }); it('subject with ticket number and fallback', () => { const answersNoScope = { type: 'feat', subject: 'should not use fallback', ticketNumber: '123', }; const options = { fallbackTicketNumber: '000', }; expect(buildCommit(answersNoScope, options)).toEqual('feat: 123 should not use fallback'); }); it('subject with ticket number prepend', () => { const answersNoScope = { type: 'feat', subject: 'should prepend ticket number to head', ticketNumber: '123', }; const options = { prependTicketToHead: true, }; expect(buildCommit(answersNoScope, options)).toEqual('123 feat: should prepend ticket number to head'); }); }); describe('type prefix and type suffix', () => { it('subject with both', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', }; const options = { typePrefix: '[', typeSuffix: ']', subjectSeparator: ' ', }; expect(buildCommit(answersNoScope, options)).toEqual('[feat] this is a new feature'); }); }); describe('pipe replaced with new line', () => { // I know it looks weird on tests but this proves to have the correct breakline inserted. const expecteMessage = `feat: this is a new feature\n body with new line now body line2 ISSUES CLOSED: footer with new line line 2`; it('should add breakline for body and footer', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', body: 'body with new line now|body line2', footer: 'footer with new line|line 2', }; const options = {}; expect(buildCommit(answersNoScope, options)).toEqual(expecteMessage); }); it('should override breakline character with option breaklineChar', () => { const answersNoScope = { type: 'feat', subject: 'this is a new feature', body: 'body with new line now@@@body line2', footer: 'footer with new line@@@line 2', }; const options = { breaklineChar: '@@@', }; expect(buildCommit(answersNoScope, options)).toEqual(expecteMessage); }); }); it('should escape harmful characters', () => { const altAnswers = { ...answers, subject: 'th"is i\'s a n`ew $ f<ea>ture &' }; // eslint-disable-next-line prettier/prettier, no-useless-escape expect(buildCommit(altAnswers, {})).toEqual('feat(app): th\\\"is i\'s a n\\`ew \\\\$ f\\<ea\\>ture \\&'); }); });