conventional-commits-parser
Advanced tools
Comparing version 0.0.9 to 0.0.11
78
cli.js
@@ -29,2 +29,3 @@ #!/usr/bin/env node | ||
' conventional-commits-parser log.txt', | ||
' cat log.txt | conventional-commits-parser', | ||
' conventional-commits-parser log2.txt \'===\' >> output.txt', | ||
@@ -36,3 +37,3 @@ '', | ||
'-c, --close-keywords Comma separated keywords that used to close issues', | ||
'-b, --break-keywords Comma separated keywords for breaking changes' | ||
'-n, --note-keywords Comma separated keywords for important notes' | ||
].join('\n') | ||
@@ -44,3 +45,3 @@ }, { | ||
c: 'closeKeywords', | ||
b: 'breakKeywords' | ||
n: 'noteKeywords' | ||
} | ||
@@ -58,2 +59,4 @@ }); | ||
var length = filePaths.length; | ||
var options = cli.flags; | ||
options.warn = console.log.bind(console); | ||
@@ -70,3 +73,3 @@ function processFile(fileIndex) { | ||
.pipe(split(separator)) | ||
.pipe(conventionalCommitsParser(cli.flags)) | ||
.pipe(conventionalCommitsParser(options)) | ||
.pipe(JSONStream.stringify()) | ||
@@ -81,34 +84,45 @@ .on('end', function() { | ||
if (length > 0) { | ||
processFile(0); | ||
} else { | ||
var commit = ''; | ||
var stream = through(); | ||
var rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
terminal: true | ||
}); | ||
cli.flags.warn = console.log.bind(console); | ||
if (process.stdin.isTTY) { | ||
if (length > 0) { | ||
processFile(0); | ||
} else { | ||
var commit = ''; | ||
var stream = through(); | ||
var rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
terminal: true | ||
}); | ||
stream.pipe(conventionalCommitsParser(cli.flags)) | ||
.pipe(JSONStream.stringify('', '', '')) | ||
.pipe(through(function(chunk, enc, cb) { | ||
if (chunk.toString() === '""') { | ||
cb(null, 'Commit cannot be parsed\n\n'); | ||
} else { | ||
cb(null, 'Result: ' + chunk + '\n\n'); | ||
stream.pipe(conventionalCommitsParser(options)) | ||
.pipe(JSONStream.stringify('', '', '')) | ||
.pipe(through(function(chunk, enc, cb) { | ||
if (chunk.toString() === '""') { | ||
cb(null, 'Commit cannot be parsed\n\n'); | ||
} else { | ||
cb(null, 'Result: ' + chunk + '\n\n'); | ||
} | ||
})) | ||
.pipe(process.stdout); | ||
rl.on('line', function(line) { | ||
commit += line + '\n'; | ||
if (commit.indexOf(separator) === -1) { | ||
return; | ||
} | ||
})) | ||
stream.write(commit); | ||
commit = ''; | ||
}); | ||
} | ||
} else { | ||
options.warn = true; | ||
process.stdin | ||
.pipe(conventionalCommitsParser(options)) | ||
.on('error', function(err) { | ||
console.error(err.toString()); | ||
process.exit(1); | ||
}) | ||
.pipe(JSONStream.stringify()) | ||
.pipe(process.stdout); | ||
rl.on('line', function(line) { | ||
commit += line + '\n'; | ||
if (commit.indexOf(separator) === -1) { | ||
return; | ||
} | ||
stream.write(commit); | ||
commit = ''; | ||
}); | ||
} |
23
index.js
@@ -17,4 +17,4 @@ 'use strict'; | ||
if (typeof options.breakKeywords === 'string') { | ||
options.breakKeywords = options.breakKeywords.split(','); | ||
if (typeof options.noteKeywords === 'string') { | ||
options.noteKeywords = options.noteKeywords.split(','); | ||
} | ||
@@ -25,2 +25,3 @@ } | ||
maxSubjectLength: 80, | ||
warn: function() {}, | ||
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/, | ||
@@ -38,14 +39,20 @@ closeKeywords: [ | ||
], | ||
breakKeywords: [ | ||
noteKeywords: [ | ||
'BREAKING CHANGE' | ||
] | ||
}, options || {}); | ||
}, options); | ||
return through.obj(function(data, enc, cb) { | ||
var commit = parser(data.toString(), options); | ||
var commit; | ||
if (commit) { | ||
try { | ||
commit = parser(data.toString(), options); | ||
cb(null, commit); | ||
} else { | ||
cb(null, ''); | ||
} catch (err) { | ||
if (options.warn === true) { | ||
cb(err); | ||
} else { | ||
options.warn(err.toString()); | ||
cb(null, ''); | ||
} | ||
} | ||
@@ -52,0 +59,0 @@ }); |
@@ -6,12 +6,8 @@ 'use strict'; | ||
function parser(raw, options) { | ||
var warn; | ||
if (!_.isEmpty(options)) { | ||
warn = options.warn || function() {}; | ||
} else { | ||
return null; | ||
if (!raw || !raw.trim()) { | ||
throw new Error('Cannot parse raw commit: "' + raw + '"'); | ||
} | ||
if (!raw || !raw.trim()) { | ||
warn('Cannot parse raw commit: "' + raw + '"'); | ||
return null; | ||
if (_.isEmpty(options)) { | ||
throw new Error('options must not be empty: "' + raw + '"'); | ||
} | ||
@@ -27,3 +23,3 @@ | ||
msg.footer = ''; | ||
msg.breaks = {}; | ||
msg.notes = {}; | ||
msg.closes = []; | ||
@@ -40,4 +36,3 @@ | ||
if (!msg.header) { | ||
warn('Cannot parse commit header: "' + raw + '"'); | ||
return null; | ||
throw new Error('Cannot parse commit header: "' + raw + '"'); | ||
} | ||
@@ -47,9 +42,11 @@ | ||
if (!match || !match[1]) { | ||
warn('Cannot parse commit type: "' + raw + '"'); | ||
return null; | ||
throw new Error('Cannot parse commit type: "' + raw + '"'); | ||
} else if (!match[3]) { | ||
warn('Cannot parse commit subject: "' + raw + '"'); | ||
return null; | ||
throw new Error('Cannot parse commit subject: "' + raw + '"'); | ||
} | ||
if (!options.maxSubjectLength) { | ||
options.maxSubjectLength = match[3].length; | ||
} | ||
if (match[3].length > options.maxSubjectLength) { | ||
@@ -68,11 +65,11 @@ match[3] = match[3].substr(0, options.maxSubjectLength); | ||
var reBreaks = regex.getBreaksRegex(options.breakKeywords); | ||
var reNotes = regex.getNotesRegex(options.noteKeywords); | ||
var reCloses = regex.getClosesRegex(options.closeKeywords); | ||
// this is a breaking change | ||
match = line.match(reBreaks); | ||
// this is a important note | ||
match = line.match(reNotes); | ||
if (match) { | ||
isBody = false; | ||
msg.footer += line + '\n'; | ||
msg.breaks[match[1]] = match[2]; | ||
msg.notes[match[1]] = match[2]; | ||
} | ||
@@ -79,0 +76,0 @@ |
'use strict'; | ||
var forEach = require('lodash').forEach; | ||
function getBreaksRegex(breakKeywords) { | ||
function getNotesRegex(noteKeywords) { | ||
var re = '('; | ||
var maxIndex = breakKeywords.length - 1; | ||
forEach(breakKeywords, function(val, index) { | ||
var maxIndex = noteKeywords.length - 1; | ||
forEach(noteKeywords, function(val, index) { | ||
if (val) { | ||
@@ -35,4 +35,4 @@ re += val.trim(); | ||
module.exports = { | ||
getBreaksRegex: getBreaksRegex, | ||
getNotesRegex: getNotesRegex, | ||
getClosesRegex: getClosesRegex | ||
}; |
{ | ||
"name": "conventional-commits-parser", | ||
"version": "0.0.9", | ||
"version": "0.0.11", | ||
"description": "Parse raw conventional commits", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/stevemao/conventional-commits-parser", |
@@ -32,6 +32,6 @@ # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coverall-image]][coverall-url] | ||
The footer should contain any information about **Breaking Changes** (optional) and is also the place to reference GitHub issues that this commit **Closes** (optional). | ||
The footer should contain any information about **Important Notes** (optional) and is also the place to reference GitHub issues that this commit **Closes** (optional). | ||
``` | ||
<breaking change> | ||
<important note> | ||
<BLANK LINE> | ||
@@ -82,3 +82,3 @@ <closes> | ||
footer: 'Closes #1', | ||
breaks: {}, | ||
notes: {}, | ||
closes: [ 1 ], | ||
@@ -92,3 +92,3 @@ type: 'feat', | ||
footer: 'BREAKING CHANGE: some breaking change', | ||
breaks: { 'BREAKING CHANGE': 'some breaking change' }, | ||
notes: { 'BREAKING CHANGE': 'some breaking change' }, | ||
closes: [], | ||
@@ -143,13 +143,13 @@ type: 'feat', | ||
##### breakKeywords | ||
##### noteKeywords | ||
Type: `array` or `string` Default: `['BREAKING CHANGE']` | ||
Keywords for breaking changes. If it's a `string` it will be converted to an `array` separated by a comma. | ||
Keywords for important notes. If it's a `string` it will be converted to an `array` separated by a comma. | ||
##### warn | ||
Type: `function` | ||
Type: `function` or `boolean` Default: `function() {}` | ||
What warn function to use. For example, `console.warn.bind(console)` or `grunt.log.writeln`. By default, it's a noop. | ||
What warn function to use. For example, `console.warn.bind(console)` or `grunt.log.writeln`. By default, it's a noop. If it is `true`, it will error if commit cannot be parsed (strict). | ||
@@ -165,6 +165,2 @@ | ||
```sh | ||
$ conventional-commits-parser --help | ||
``` | ||
If you run `conventional-commits-parser` without any arguments | ||
@@ -183,3 +179,3 @@ | ||
result: {"hash":null,"header":"fix(title): a title is fixed","body":"","footer":"","breaks":{},"closes":[],"type":"fix","scope":"title","subject":"a title is fixed"} | ||
result: {"hash":null,"header":"fix(title): a title is fixed","body":"","footer":"","notes":{},"closes":[],"type":"fix","scope":"title","subject":"a title is fixed"} | ||
``` | ||
@@ -208,2 +204,4 @@ | ||
$ conventional-commits-parser log.txt | ||
# or | ||
$ cat log.txt | conventional-commits-parser | ||
``` | ||
@@ -215,3 +213,3 @@ | ||
[ | ||
{"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"feat(ngMessages): provide support for dynamic message resolution","body":"Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error.","footer":"BREAKING CHANGE: The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.\nCloses #10036\nCloses #9338","breaks":{"BREAKING CHANGE":"The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive."},"closes":[10036,9338],"type":"feat","scope":"ngMessages","subject":"provide support for dynamic message resolution"} | ||
{"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"feat(ngMessages): provide support for dynamic message resolution","body":"Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error.","footer":"BREAKING CHANGE: The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.\nCloses #10036\nCloses #9338","notes":{"BREAKING CHANGE":"The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive."},"closes":[10036,9338],"type":"feat","scope":"ngMessages","subject":"provide support for dynamic message resolution"} | ||
] | ||
@@ -244,5 +242,5 @@ ``` | ||
[ | ||
{"hash":"2d0eda10e43f6b079b531c507282fad082ea0762","header":"docs(ngMessageExp): split ngMessage docs up to show its alias more clearly","body":"","footer":"","breaks":{},"closes":[],"type":"docs","scope":"ngMessageExp","subject":"split ngMessage docs up to show its alias more clearly"} | ||
{"hash":"2d0eda10e43f6b079b531c507282fad082ea0762","header":"docs(ngMessageExp): split ngMessage docs up to show its alias more clearly","body":"","footer":"","notes":{},"closes":[],"type":"docs","scope":"ngMessageExp","subject":"split ngMessage docs up to show its alias more clearly"} | ||
, | ||
{"hash":"4374f892c6fa4af6ba1f2ed47c5f888fdb5fadc5","header":"fix($animate): applyStyles from options on leave","body":"","footer":"Closes #10068","breaks":{},"closes":[10068],"type":"fix","scope":"$animate","subject":"applyStyles from options on leave"} | ||
{"hash":"4374f892c6fa4af6ba1f2ed47c5f888fdb5fadc5","header":"fix($animate): applyStyles from options on leave","body":"","footer":"Closes #10068","notes":{},"closes":[10068],"type":"fix","scope":"$animate","subject":"applyStyles from options on leave"} | ||
] | ||
@@ -249,0 +247,0 @@ ``` |
'use strict'; | ||
var concat = require('concat-stream'); | ||
var expect = require('chai').expect; | ||
var fs = require('fs'); | ||
var readFileSync = require('fs').readFileSync; | ||
@@ -15,3 +16,5 @@ var spawn = require('child_process').spawn; | ||
it('should parse commits in a file', function(done) { | ||
var cp = spawn(cliPath, ['test/fixtures/log.txt']); | ||
var cp = spawn(cliPath, ['test/fixtures/log.txt'], { | ||
stdio: [process.stdin, null, null] | ||
}); | ||
cp.stdout | ||
@@ -25,3 +28,5 @@ .pipe(concat(function(chunk) { | ||
it('should work with a separator', function(done) { | ||
var cp = spawn(cliPath, ['test/fixtures/log2.txt', '===']); | ||
var cp = spawn(cliPath, ['test/fixtures/log2.txt', '==='], { | ||
stdio: [process.stdin, null, null] | ||
}); | ||
cp.stdout | ||
@@ -35,3 +40,5 @@ .pipe(concat(function(chunk) { | ||
it('should work with two files', function(done) { | ||
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log2.txt', '===']); | ||
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log2.txt', '==='], { | ||
stdio: [process.stdin, null, null] | ||
}); | ||
cp.stdout | ||
@@ -47,3 +54,5 @@ .pipe(concat(function(chunk) { | ||
var i = 0; | ||
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log4.txt', 'test/fixtures/log2.txt', 'test/fixtures/log5.txt', '===']); | ||
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log4.txt', 'test/fixtures/log2.txt', 'test/fixtures/log5.txt', '==='], { | ||
stdio: [process.stdin, null, null] | ||
}); | ||
cp.stderr | ||
@@ -64,3 +73,5 @@ .pipe(through(function(chunk, enc, cb) { | ||
it('should work with options', function(done) { | ||
var cp = spawn(cliPath, ['test/fixtures/log3.txt', '--max-subject-length', '5', '-p', '^(\\w*)(?:\\(([:\\w\\$\\.\\-\\* ]*)\\))?\\: (.*)$', '--close-keywords', 'close, fix', '-b', 'BREAKING NEWS']); | ||
var cp = spawn(cliPath, ['test/fixtures/log3.txt', '--max-subject-length', '5', '-p', '^(\\w*)(?:\\(([:\\w\\$\\.\\-\\* ]*)\\))?\\: (.*)$', '--close-keywords', 'close, fix', '-n', 'BREAKING NEWS'], { | ||
stdio: [process.stdin, null, null] | ||
}); | ||
cp.stdout | ||
@@ -72,2 +83,24 @@ .pipe(concat(function(chunk) { | ||
}); | ||
it('should work if it is not a tty', function(done) { | ||
var cp = spawn(cliPath, [], { | ||
stdio: [fs.openSync('test/fixtures/log.txt', 'r'), null, null] | ||
}); | ||
cp.stdout | ||
.pipe(concat(function(chunk) { | ||
expect(chunk.toString()).to.equal(output1); | ||
done(); | ||
})); | ||
}); | ||
it('should error if it is not a tty and commit cannot be parsed', function(done) { | ||
var cp = spawn(cliPath, [], { | ||
stdio: [fs.openSync('test/fixtures/bad_commit.txt', 'r'), null, null] | ||
}); | ||
cp.stderr | ||
.pipe(concat(function(chunk) { | ||
expect(chunk.toString()).to.equal('Error: Cannot parse commit type: "bla bla\n"\n'); | ||
done(); | ||
})); | ||
}); | ||
}); |
[ | ||
{"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"feat(ngMessages): provide support for dynamic message resolution","body":"Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error.","footer":"BREAKING CHANGE: The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.\nCloses #10036\nCloses #9338","breaks":{"BREAKING CHANGE":"The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive."},"closes":[10036,9338],"type":"feat","scope":"ngMessages","subject":"provide support for dynamic message resolution"} | ||
{"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"feat(ngMessages): provide support for dynamic message resolution","body":"Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error.","footer":"BREAKING CHANGE: The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive.\nCloses #10036\nCloses #9338","notes":{"BREAKING CHANGE":"The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive."},"closes":[10036,9338],"type":"feat","scope":"ngMessages","subject":"provide support for dynamic message resolution"} | ||
] |
[ | ||
{"hash":"2d0eda10e43f6b079b531c507282fad082ea0762","header":"docs(ngMessageExp): split ngMessage docs up to show its alias more clearly","body":"","footer":"","breaks":{},"closes":[],"type":"docs","scope":"ngMessageExp","subject":"split ngMessage docs up to show its alias more clearly"} | ||
{"hash":"2d0eda10e43f6b079b531c507282fad082ea0762","header":"docs(ngMessageExp): split ngMessage docs up to show its alias more clearly","body":"","footer":"","notes":{},"closes":[],"type":"docs","scope":"ngMessageExp","subject":"split ngMessage docs up to show its alias more clearly"} | ||
, | ||
{"hash":"4374f892c6fa4af6ba1f2ed47c5f888fdb5fadc5","header":"fix($animate): applyStyles from options on leave","body":"","footer":"Closes #10068","breaks":{},"closes":[10068],"type":"fix","scope":"$animate","subject":"applyStyles from options on leave"} | ||
{"hash":"4374f892c6fa4af6ba1f2ed47c5f888fdb5fadc5","header":"fix($animate): applyStyles from options on leave","body":"","footer":"Closes #10068","notes":{},"closes":[10068],"type":"fix","scope":"$animate","subject":"applyStyles from options on leave"} | ||
] |
[ | ||
{"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"fix(category:subcategory): My subject","body":"This is my commit body.\nFixed #13233","footer":"BREAKING NEWS: A lot of changes!\nClose #10036, Closes #10000\nfix #9338","breaks":{"BREAKING NEWS":"A lot of changes!"},"closes":[10036,9338],"type":"fix","scope":"category:subcategory","subject":"My su"} | ||
{"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"fix(category:subcategory): My subject","body":"This is my commit body.\nFixed #13233","footer":"BREAKING NEWS: A lot of changes!\nClose #10036, Closes #10000\nfix #9338","notes":{"BREAKING NEWS":"A lot of changes!"},"closes":[10036,9338],"type":"fix","scope":"category:subcategory","subject":"My su"} | ||
] |
@@ -86,2 +86,38 @@ 'use strict'; | ||
it('should warn if malformed commits found', function(done) { | ||
var stream = through(); | ||
var commit = 'bla bla bla\n\n'; | ||
stream.write(commit); | ||
stream.end(); | ||
stream | ||
.pipe(conventionalCommitsParser({ | ||
warn: function(warning) { | ||
expect(warning).to.equal('Error: Cannot parse commit type: "bla bla bla\n\n"'); | ||
done(); | ||
} | ||
})) | ||
.pipe(through.obj(function(chunk, enc, cb) { | ||
cb(); | ||
})); | ||
}); | ||
it('should error if malformed commits found and `options.warn === true`', function(done) { | ||
var stream = through(); | ||
var commit = 'bla bla bla\n\n'; | ||
stream.write(commit); | ||
stream.end(); | ||
stream | ||
.pipe(conventionalCommitsParser({ | ||
warn: true | ||
})) | ||
.on('error', function(err) { | ||
expect(err.toString()).to.equal('Error: Cannot parse commit type: "bla bla bla\n\n"'); | ||
done(); | ||
}); | ||
}); | ||
var commits = [ | ||
@@ -96,3 +132,3 @@ '13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'bla bla bla\n\n' + | ||
'BREAKING CHANGES: some breaking changes\n', | ||
'BREAKING CHANGES: some breaking changes\n' | ||
]; | ||
@@ -113,3 +149,3 @@ | ||
closeKeywords: ['fix'], | ||
breakKeywords: ['BREAKING CHANGES'] | ||
noteKeywords: ['BREAKING CHANGES'] | ||
})) | ||
@@ -126,3 +162,3 @@ .pipe(through.obj(function(chunk, enc, cb) { | ||
expect(chunk.subject).to.equal('Another custom separator'); | ||
expect(chunk.breaks['BREAKING CHANGES']).to.equal('some breaking changes'); | ||
expect(chunk.notes['BREAKING CHANGES']).to.equal('some breaking changes'); | ||
done(); | ||
@@ -147,3 +183,3 @@ } | ||
closeKeywords: 'fix', | ||
breakKeywords: 'BREAKING CHANGES' | ||
noteKeywords: 'BREAKING CHANGES' | ||
})) | ||
@@ -160,3 +196,3 @@ .pipe(through.obj(function(chunk, enc, cb) { | ||
expect(chunk.subject).to.equal('Another custom separator'); | ||
expect(chunk.breaks['BREAKING CHANGES']).to.equal('some breaking changes'); | ||
expect(chunk.notes['BREAKING CHANGES']).to.equal('some breaking changes'); | ||
done(); | ||
@@ -163,0 +199,0 @@ } |
@@ -22,3 +22,3 @@ 'use strict'; | ||
], | ||
breakKeywords: [ | ||
noteKeywords: [ | ||
'BREAKING AMEND' | ||
@@ -46,26 +46,14 @@ ] | ||
it('should return null if nothing to parse', function() { | ||
expect(parser()).to.equal(null); | ||
expect(parser('\n')).to.equal(null); | ||
expect(parser(' ')).to.equal(null); | ||
it('should throw if nothing to parse', function() { | ||
expect(function() { | ||
parser(); | ||
}).to.throw('Cannot parse raw commit: "undefined"'); | ||
expect(function() { | ||
parser('\n'); | ||
}).to.throw('Cannot parse raw commit: "\n"'); | ||
expect(function() { | ||
parser(' '); | ||
}).to.throw('Cannot parse raw commit: " "'); | ||
}); | ||
it('should warn if nothing to parse', function() { | ||
parser('', { | ||
warn: function(warning) { | ||
expect(warning).to.equal('Cannot parse raw commit: ""'); | ||
} | ||
}); | ||
parser('\n', { | ||
warn: function(warning) { | ||
expect(warning).to.equal('Cannot parse raw commit: "\n"'); | ||
} | ||
}); | ||
parser(' ', { | ||
warn: function(warning) { | ||
expect(warning).to.equal('Cannot parse raw commit: " "'); | ||
} | ||
}); | ||
}); | ||
it('should parse hash', function() { | ||
@@ -76,30 +64,30 @@ expect(msg.hash).to.equal('9b1aff905b638aa274a5fc8f88662df446d374bd'); | ||
describe('header', function() { | ||
it('should return null if header cannot be parsed', function() { | ||
expect(parser('bla bla', options)).to.equal(null); | ||
it('should throw if header cannot be parsed', function() { | ||
expect(function() { | ||
parser('bla bla', options); | ||
}).to.throw('Cannot parse commit type: "bla bla"'); | ||
}); | ||
it('should warn if type cannot be parsed', function() { | ||
parser('bla bla', { | ||
warn: function(warning) { | ||
expect(warning).to.equal('Cannot parse commit type: "bla bla"'); | ||
} | ||
}); | ||
it('should throw if `options` is empty', function() { | ||
expect(function() { | ||
parser('bla bla'); | ||
}).to.throw('options must not be empty: "bla bla"'); | ||
}); | ||
it('should warn if subject cannot be parsed', function() { | ||
options.warn = function(warning) { | ||
expect(warning).to.equal('Cannot parse commit subject: "fix: "'); | ||
}; | ||
parser('fix: ', options); | ||
it('should throw if subject cannot be found', function() { | ||
expect(function() { | ||
parser('fix: ', options); | ||
}).to.throw('Cannot parse commit subject: "fix: "'); | ||
}); | ||
it('should return null if there is no header', function() { | ||
expect(parser('056f5827de86cace1f282c8e3f1cccc952fcad2e', options)).to.equal(null); | ||
it('should throw if there is no header', function() { | ||
expect(function() { | ||
parser('056f5827de86cace1f282c8e3f1cccc952fcad2e', options); | ||
}).to.throw('Cannot parse commit header: "056f5827de86cace1f282c8e3f1cccc952fcad2e"'); | ||
}); | ||
it('should warn if header cannot be parsed', function() { | ||
options.warn = function(warning) { | ||
expect(warning).to.equal('Cannot parse commit header: "056f5827de86cace1f282c8e3f1cccc952fcad2e"'); | ||
}; | ||
parser('056f5827de86cace1f282c8e3f1cccc952fcad2e', options); | ||
it('should throw if header cannot be found', function() { | ||
expect(function() { | ||
parser('056f5827de86cace1f282c8e3f1cccc952fcad2e', options); | ||
}).to.throw('Cannot parse commit header: "056f5827de86cace1f282c8e3f1cccc952fcad2e"'); | ||
}); | ||
@@ -148,3 +136,3 @@ | ||
var msg = parser('feat(ng:list): Allow custom separator', { | ||
headerPattern: /^(\w*)(?:\(([:\w\$\.\-\* ]*)\))?\: (.*)$/, | ||
headerPattern: /^(\w*)(?:\(([:\w\$\.\-\* ]*)\))?\: (.*)$/ | ||
}); | ||
@@ -174,3 +162,3 @@ expect(msg.scope).to.equal('ng:list'); | ||
it('should parse breaking change', function() { | ||
expect(msg.breaks['BREAKING AMEND']).to.deep.equal('some breaking change'); | ||
expect(msg.notes['BREAKING AMEND']).to.deep.equal('some breaking change'); | ||
}); | ||
@@ -177,0 +165,0 @@ |
@@ -6,5 +6,5 @@ 'use strict'; | ||
describe('regex', function() { | ||
describe('getBreaksRegex', function() { | ||
describe('getNotesRegex', function() { | ||
it('should generate correct regex', function() { | ||
var re = regex.getBreaksRegex(['Breaking News', 'Breaking Change']); | ||
var re = regex.getNotesRegex(['Breaking News', 'Breaking Change']); | ||
expect(re).to.eql(/(Breaking News|Breaking Change):\s([\s\S]*)/); | ||
@@ -14,3 +14,3 @@ }); | ||
it('should ignore whitespace', function() { | ||
var re = regex.getBreaksRegex([' Breaking News', 'Breaking Change ', '', ' Breaking SOLUTION ']); | ||
var re = regex.getNotesRegex([' Breaking News', 'Breaking Change ', '', ' Breaking SOLUTION ']); | ||
expect(re).to.eql(/(Breaking News|Breaking Change|Breaking SOLUTION):\s([\s\S]*)/); | ||
@@ -17,0 +17,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36486
23
708
258
3